From 72d475db4c91287829f3db67f50102c043af9313 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Thu, 2 Nov 2017 14:59:40 +0100 Subject: [PATCH] merge ServiceProvider and Data::ServiceProvider classes --- bin/account-manager-client.pl | 15 +-- bin/account-manager-web.pl | 1 - lib/IdPAccountManager/Data/ServiceProvider.pm | 48 ++++++++ lib/IdPAccountManager/ServiceProvider.pm | 113 ------------------ lib/IdPAccountManager/WebRequest.pm | 7 +- 5 files changed, 60 insertions(+), 124 deletions(-) delete mode 100644 lib/IdPAccountManager/ServiceProvider.pm diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl index 49491db..346069f 100755 --- a/bin/account-manager-client.pl +++ b/bin/account-manager-client.pl @@ -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') { diff --git a/bin/account-manager-web.pl b/bin/account-manager-web.pl index 09f0ef0..3729cf9 100755 --- a/bin/account-manager-web.pl +++ b/bin/account-manager-web.pl @@ -20,7 +20,6 @@ use Template::Constants qw( :debug ); use Conf; use IdPAccountManager::SAMLMetadata; -use IdPAccountManager::ServiceProvider; use IdPAccountManager::WebRequest; diff --git a/lib/IdPAccountManager/Data/ServiceProvider.pm b/lib/IdPAccountManager/Data/ServiceProvider.pm index 209ac30..6eee98a 100644 --- a/lib/IdPAccountManager/Data/ServiceProvider.pm +++ b/lib/IdPAccountManager/Data/ServiceProvider.pm @@ -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; diff --git a/lib/IdPAccountManager/ServiceProvider.pm b/lib/IdPAccountManager/ServiceProvider.pm deleted file mode 100644 index 78cdf68..0000000 --- a/lib/IdPAccountManager/ServiceProvider.pm +++ /dev/null @@ -1,113 +0,0 @@ -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). diff --git a/lib/IdPAccountManager/WebRequest.pm b/lib/IdPAccountManager/WebRequest.pm index 42553e9..97ebc20 100755 --- a/lib/IdPAccountManager/WebRequest.pm +++ b/lib/IdPAccountManager/WebRequest.pm @@ -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'} ); -- GitLab