Skip to content
Snippets Groups Projects
Commit 72d475db authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

merge ServiceProvider and Data::ServiceProvider classes

parent cb737a5c
No related branches found
No related tags found
No related merge requests found
......@@ -20,8 +20,9 @@ use IdPAccountManager::Data::AuthenticationToken;
use IdPAccountManager::Data::AuthenticationToken::Manager;
use IdPAccountManager::Data::TestAccount;
use IdPAccountManager::Data::TestAccount::Manager;
use IdPAccountManager::Data::ServiceProvider;
use IdPAccountManager::Data::ServiceProvider::Manager;
use IdPAccountManager::SAMLMetadata;
use IdPAccountManager::ServiceProvider;
use IdPAccountManager::Logger;
my %options;
......@@ -158,7 +159,7 @@ if ($action eq 'add_test_account') {
## Check if entry already exists in DB first
my $service_provider =
IdPAccountManager::ServiceProvider->new(
IdPAccountManager::Data::ServiceProvider->new(
entityid => $options{'sp_entityid'});
if ($service_provider->load(speculative => 1)) {
printf "Entry for %s already in DB; update it with new data\n",
......@@ -169,7 +170,7 @@ if ($action eq 'add_test_account') {
if ($options{'displayname'});
} else {
$service_provider = IdPAccountManager::ServiceProvider->new(
$service_provider = IdPAccountManager::Data::ServiceProvider->new(
entityid => $options{'sp_entityid'},
contacts => $options{'contacts'},
displayname => $options{'displayname'}
......@@ -187,14 +188,14 @@ if ($action eq 'add_test_account') {
my %args;
my $all = IdPAccountManager::ServiceProvider::list_service_providers(%args);
my $providers = IdPAccountManager::Data::ServiceProvider::Manager->get_serviceproviders(%args);
if ($#{$all} < 0) {
if (@$providers) {
printf "No service provider in DB\n";
}
foreach my $service_provider (@$all) {
$service_provider->print();
foreach my $provider (@$providers) {
$provider->print();
}
} elsif ($action eq 'list_authentication_tokens') {
......
......@@ -20,7 +20,6 @@ use Template::Constants qw( :debug );
use Conf;
use IdPAccountManager::SAMLMetadata;
use IdPAccountManager::ServiceProvider;
use IdPAccountManager::WebRequest;
......
......@@ -20,5 +20,53 @@ __PACKAGE__->meta->setup(
unique_key => [ 'entityid' ],
);
sub new {
my ($pkg, %args) = @_;
my $self = $pkg->SUPER::new(%args);
$self->{dev_sp_contact} = $args{dev_sp_contact};
return $self;
}
## Print the content of a test account
sub print {
my ($self, $fd) = @_;
$fd = \*STDOUT unless $fd;
printf $fd
"ServiceProvider ID=%s; entityid=%s; displayname=%s; contacts=%s\n",
$self->id(), $self->entityid(), $self->displayname(), $self->contacts();
}
## list contacts for this SP, including those listed in conf.dev_sp_contact
sub list_contacts_as_array {
my ($self) = @_;
my %contact_list;
foreach my $contact_email (split /,/, $self->contacts()) {
$contact_list{$contact_email}++;
}
foreach my $contact_email (split /,/, $self->{dev_sp_contact}) {
$contact_list{$contact_email}++;
}
return keys %contact_list;
}
## Check if email address is a known contact (or conf.dev_sp_contact)
sub is_contact {
my ($self, $email) = @_;
foreach my $known_contact ($self->list_contacts_as_array()) {
return 1 if (lc($email) eq lc($known_contact));
}
return 0;
}
1;
package IdPAccountManager::ServiceProvider;
## Copyright (c) GEANT
## This software was developed by RENATER. The research leading to these results has received funding
## from the European Community¹s Seventh Framework Programme (FP7/2007-2013) under grant agreement nº 238875 (GÉANT).
use strict;
use warnings;
use base 'IdPAccountManager::Data::ServiceProvider';
use IdPAccountManager::Data::ServiceProvider;
use IdPAccountManager::Data::ServiceProvider::Manager;
use IdPAccountManager::Tools;
use Carp;
INIT {
## Set error mode to non fatal
IdPAccountManager::Data::ServiceProvider::Manager->error_mode('return');
}
sub new {
my ($pkg, %args) = @_;
my $self = SUPER::new->(%args);
$self->{dev_sp_contact} = $args{dev_sp_contact};
return $self;
}
## Print the content of a test account
sub print {
my ($self, $fd) = @_;
$fd = \*STDOUT unless $fd;
printf $fd
"ServiceProvider ID=%s; entityid=%s; displayname=%s; contacts=%s\n",
$self->id, $self->entityid, $self->displayname, $self->contacts;
}
## list contacts for this SP, including those listed in conf.dev_sp_contact
sub list_contacts_as_array {
my ($self) = @_;
my %contact_list;
foreach my $contact_email (split /,/, $self->contacts()) {
$contact_list{$contact_email}++;
}
foreach my $contact_email (split /,/, $self->{dev_sp_contact}) {
$contact_list{$contact_email}++;
}
return keys %contact_list;
}
## Check if email address is a known contact (or conf.dev_sp_contact)
sub is_contact {
my ($self, $email) = @_;
foreach my $known_contact ($self->list_contacts_as_array()) {
return 1 if (lc($email) eq lc($known_contact));
}
return 0;
}
## list all test accounts
## Class method
sub list_service_providers {
my (%args) = @_;
my $persistent_accounts =
IdPAccountManager::Data::ServiceProvider::Manager->get_serviceproviders(
%args);
my $service_providers;
foreach my $persistent_sp (@{$persistent_accounts}) {
my $service_provider =
IdPAccountManager::ServiceProvider->new(
entityid => $persistent_sp->entityid());
$service_provider->load();
push @$service_providers, $service_provider;
}
return $service_providers;
}
1;
__END__
=head1 NAME
IdPAccountManager::ServiceProvider - Manage Service Providers for which test accounts have been requested for the Test Identity Provider
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 SUBROUTINES/METHODS
=head1 AUTHOR
Olivier Salaün (olivier.salaun@renater.fr)
=head1 LICENSE
Copyright (c) GEANT
This software was developed by RENATER. The research leading to these results has received funding
from the European Community¹s Seventh Framework Programme (FP7/2007-2013) under grant agreement nº 238875 (GÉANT).
......@@ -7,6 +7,7 @@ use English qw(-no_match_vars);
use IdPAccountManager::Logger;
use IdPAccountManager::Data::TestAccount;
use IdPAccountManager::Data::AuthenticationToken;
use IdPAccountManager::Data::ServiceProvider;
use Conf;
## New web request
......@@ -296,7 +297,7 @@ sub req_select_sp {
}
## Create a serviceprovider object to store major parameters for this SP in DB
my $service_provider = IdPAccountManager::ServiceProvider->new(
my $service_provider = IdPAccountManager::Data::ServiceProvider->new(
entityid => $self->{'param_in'}{'sp_entityid'},
dev_sp_contact => $Conf::global{'dev_sp_contact'}
);
......@@ -336,7 +337,7 @@ sub req_select_sp {
} else {
$service_provider = IdPAccountManager::ServiceProvider->new(
$service_provider = IdPAccountManager::Data::ServiceProvider->new(
entityid => $self->{'param_in'}{'sp_entityid'},
contacts => join(',', @contacts),
displayname => $display_name,
......@@ -391,7 +392,7 @@ sub req_generate_token {
}
## Create a serviceprovider object to load parameters for this SP from DB
my $service_provider = IdPAccountManager::ServiceProvider->new(
my $service_provider = IdPAccountManager::Data::ServiceProvider->new(
entityid => $self->{'param_in'}{'sp_entityid'},
dev_sp_contact => $Conf::global{'dev_sp_contact'}
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment