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

use a shorter namespace

parent aa8f5988
No related branches found
No related tags found
No related merge requests found
Showing with 138 additions and 80 deletions
......@@ -7,11 +7,11 @@ use lib qw(@modulesdir@);
use Config::Tiny;
use IdPAccountManager::WebRequest;
use AccountManager::WebRequest;
my $configuration = Config::Tiny->read('@sysconfdir@/manager.conf');
my $request = IdPAccountManager::WebRequest->new(
my $request = AccountManager::WebRequest->new(
configuration => $configuration
);
$request->run();
......
......@@ -15,14 +15,14 @@ use Getopt::Long qw(:config auto_help);
use Log::Any::Adapter;
use Pod::Usage;
use IdPAccountManager::AuthenticationToken;
use IdPAccountManager::AuthenticationToken::Manager;
use IdPAccountManager::ServiceProvider;
use IdPAccountManager::ServiceProvider::Manager;
use IdPAccountManager::TestAccount;
use IdPAccountManager::TestAccount::Manager;
use IdPAccountManager::SAMLMetadata;
use IdPAccountManager::Tools;
use AccountManager::AuthenticationToken;
use AccountManager::AuthenticationToken::Manager;
use AccountManager::ServiceProvider;
use AccountManager::ServiceProvider::Manager;
use AccountManager::TestAccount;
use AccountManager::TestAccount::Manager;
use AccountManager::SAMLMetadata;
use AccountManager::Tools;
my %options;
GetOptions(
......@@ -49,7 +49,7 @@ pod2usage(
my $configuration = Config::Tiny->read('@sysconfdir@/manager.conf');
IdPAccountManager::DB->register_db(
AccountManager::DB->register_db(
driver => $configuration->{database}->{type},
database => $configuration->{database}->{name},
host => $configuration->{database}->{host},
......@@ -57,7 +57,7 @@ IdPAccountManager::DB->register_db(
username => $configuration->{database}->{user}
);
my $db = IdPAccountManager::DB->new();
my $db = AccountManager::DB->new();
for ($action) {
when ('add_account') { add_account() }
......@@ -91,15 +91,15 @@ sub add_account {
my $validity_period =
$configuration->{$entity}->{account_validity_period} ||
$configuration->{service}->{account_validity_period};
my $password = IdPAccountManager::Tools::generate_password();
my $password = AccountManager::Tools::generate_password();
my $account = IdPAccountManager::TestAccount->new(
my $account = AccountManager::TestAccount->new(
db => $db,
profile => $options{profile},
sp_entityid => $options{sp_entityid},
scope => $configuration->{idp}->{scope},
password => $password,
password_hash => IdPAccountManager::Tools::sha256_hash($password),
password_hash => AccountManager::Tools::sha256_hash($password),
creation_date => DateTime->today(),
expiration_date => DateTime->today()->add(days => $validity_period)
);
......@@ -127,7 +127,7 @@ sub list_accounts {
}
my $accounts =
IdPAccountManager::TestAccount::Manager->get_testaccounts(db => $db, %args);
AccountManager::TestAccount::Manager->get_testaccounts(db => $db, %args);
if (! @$accounts) {
printf "No matching test account in DB\n";
......@@ -143,12 +143,12 @@ sub list_accounts {
}
printf "%d accounts removed\n", scalar @$accounts;
$accounts = IdPAccountManager::TestAccount::Manager->get_testaccounts(
$accounts = AccountManager::TestAccount::Manager->get_testaccounts(
db => $db
);
eval {
IdPAccountManager::Tools::update_ssp_authsources(
AccountManager::Tools::update_ssp_authsources(
$configuration->{_}->{templates_dir},
$configuration->{idp}->{accounts_file},
$accounts
......@@ -166,7 +166,7 @@ sub parse_metadata {
my $federation_metadata;
eval {
$federation_metadata = IdPAccountManager::SAMLMetadata->new(
$federation_metadata = AccountManager::SAMLMetadata->new(
file => $configuration->{_}->{federation_metadata_file}
);
};
......@@ -195,7 +195,7 @@ sub add_provider {
) unless $options{contacts};
## Check if entry already exists in DB first
my $provider = IdPAccountManager::ServiceProvider->new(
my $provider = AccountManager::ServiceProvider->new(
db => $db,
entityid => $options{sp_entityid}
);
......@@ -206,7 +206,7 @@ sub add_provider {
$provider->contacts($options{contacts});
$provider->displayname($options{displayname}) if $options{displayname};
} else {
$provider = IdPAccountManager::ServiceProvider->new(
$provider = AccountManager::ServiceProvider->new(
db => $db,
entityid => $options{sp_entityid},
contacts => $options{contacts},
......@@ -223,7 +223,7 @@ sub add_provider {
sub list_providers {
my %args;
my $providers = IdPAccountManager::ServiceProvider::Manager->get_serviceproviders(db => $db, %args);
my $providers = AccountManager::ServiceProvider::Manager->get_serviceproviders(db => $db, %args);
if (! @$providers) {
printf "No service provider in DB\n";
......@@ -256,7 +256,7 @@ sub list_tokens {
}
my $tokens =
IdPAccountManager::AuthenticationToken::Manager->get_authenticationtokens(db => $db, %args);
AccountManager::AuthenticationToken::Manager->get_authenticationtokens(db => $db, %args);
if (!@$tokens) {
printf "No corresponding token found in DB\n";
......@@ -284,7 +284,7 @@ sub get_token {
}
my $token =
IdPAccountManager::AuthenticationToken->new(db => $db, %args);
AccountManager::AuthenticationToken->new(db => $db, %args);
die "No corresponding token found in DB\n"
unless $token->load();
......@@ -311,7 +311,7 @@ sub add_token {
) unless $options{sp_entityid};
# delete any previous token for the same email/service couple
my $old_token = IdPAccountManager::AuthenticationToken->new(
my $old_token = AccountManager::AuthenticationToken->new(
db => $db,
email_address => $options{email_address},
sp_entityid => $options{sp_entityid}
......@@ -322,12 +322,12 @@ sub add_token {
}
# compute a new token
my $token = IdPAccountManager::AuthenticationToken->new(
my $token = AccountManager::AuthenticationToken->new(
db => $db,
email_address => $options{email_address},
sp_entityid => $options{sp_entityid},
creation_date => DateTime->today(),
token => IdPAccountManager::Tools::generate_token()
token => AccountManager::Tools::generate_token()
);
$token->save() or die "failed to save authentication token\n";
......
package IdPAccountManager::AuthenticationToken;
package AccountManager::AuthenticationToken;
use strict;
use warnings;
use base 'IdPAccountManager::DB::Object';
use base 'AccountManager::DB::Object';
__PACKAGE__->meta->setup(
table => 'authenticationtokens',
......
package IdPAccountManager::AuthenticationToken::Manager;
package AccountManager::AuthenticationToken::Manager;
use strict;
use warnings;
use base qw(Rose::DB::Object::Manager);
use IdPAccountManager::AuthenticationToken;
use AccountManager::AuthenticationToken;
sub object_class { 'IdPAccountManager::AuthenticationToken' }
sub object_class { 'AccountManager::AuthenticationToken' }
__PACKAGE__->make_manager_methods('authenticationtokens');
......
package IdPAccountManager::DB;
package AccountManager::DB;
use strict;
use warnings;
......
package IdPAccountManager::DB::Object;
package AccountManager::DB::Object;
use strict;
use warnings;
use base 'Rose::DB::Object';
use IdPAccountManager::DB;
use AccountManager::DB;
sub init_db {
IdPAccountManager::DB->new();
AccountManager::DB->new();
}
1;
package IdPAccountManager::SAMLMetadata;
package AccountManager::SAMLMetadata;
use strict;
use warnings;
......@@ -213,7 +213,7 @@ SAMLMetadata - loading SAML federation metadata
=head1 SYNOPSIS
# instanciate metadata object
my $metadata = IdPAccountManager::SAMLMetadata->new(
my $metadata = AccountManager::SAMLMetadata->new(
file => '/tmp/edugain-saml-metadata.xml'
);
......@@ -230,7 +230,7 @@ This class parses a SAML2 metadata file.
=item new()
Create a new IdPAccountManager::SAMLMetadata object.
Create a new AccountManager::SAMLMetadata object.
Supported arguments include:
......
package IdPAccountManager::ServiceProvider;
package AccountManager::ServiceProvider;
use strict;
use warnings;
use base 'IdPAccountManager::DB::Object';
use base 'AccountManager::DB::Object';
use List::MoreUtils qw(any);
......
package IdPAccountManager::ServiceProvider::Manager;
package AccountManager::ServiceProvider::Manager;
use strict;
use warnings;
use base qw(Rose::DB::Object::Manager);
use IdPAccountManager::ServiceProvider;
use AccountManager::ServiceProvider;
sub object_class { 'IdPAccountManager::ServiceProvider' }
sub object_class { 'AccountManager::ServiceProvider' }
__PACKAGE__->make_manager_methods('serviceproviders');
......
package IdPAccountManager::TestAccount;
package AccountManager::TestAccount;
use strict;
use warnings;
use base 'IdPAccountManager::DB::Object';
use base 'AccountManager::DB::Object';
__PACKAGE__->meta->setup(
table => 'testaccounts',
......
package IdPAccountManager::TestAccount::Manager;
package AccountManager::TestAccount::Manager;
use strict;
use warnings;
use base qw(Rose::DB::Object::Manager);
use IdPAccountManager::TestAccount;
use AccountManager::TestAccount;
sub object_class { 'IdPAccountManager::TestAccount' }
sub object_class { 'AccountManager::TestAccount' }
__PACKAGE__->make_manager_methods('testaccounts');
......
package IdPAccountManager::Tools;
package AccountManager::Tools;
use strict;
use warnings;
......@@ -91,7 +91,7 @@ __END__
=head1 NAME
IdPAccountManager::Tools - Set of subroutines usefull for the Test Account manager
AccountManager::Tools - Set of subroutines usefull for the Test Account manager
=head1 DESCRIPTION
......
package IdPAccountManager::WebRequest;
package AccountManager::WebRequest;
use strict;
use warnings;
......@@ -10,12 +10,12 @@ use Template;
use Log::Any::Adapter;
use List::MoreUtils qw(uniq);
use IdPAccountManager::TestAccount;
use IdPAccountManager::TestAccount::Manager;
use IdPAccountManager::AuthenticationToken;
use IdPAccountManager::ServiceProvider;
use IdPAccountManager::SAMLMetadata;
use IdPAccountManager::Tools;
use AccountManager::TestAccount;
use AccountManager::TestAccount::Manager;
use AccountManager::AuthenticationToken;
use AccountManager::ServiceProvider;
use AccountManager::SAMLMetadata;
use AccountManager::Tools;
## Defining parameters format
my $urn_or_url_regex = '(http(s?):\/\/|urn:)[^\\\$\*\"\'\`\^\|\<\>\n\s]+'
......@@ -53,7 +53,7 @@ sub new {
$self->{logger} = Log::Any->get_logger();
IdPAccountManager::DB->register_db(
AccountManager::DB->register_db(
driver => $self->{configuration}->{database}->{type},
database => $self->{configuration}->{database}->{name},
host => $self->{configuration}->{database}->{host},
......@@ -61,7 +61,7 @@ sub new {
username => $self->{configuration}->{database}->{user}
);
$self->{db} = IdPAccountManager::DB->new();
$self->{db} = AccountManager::DB->new();
$self->{cgi} = CGI->new();
bless $self, $pkg;
......@@ -186,7 +186,7 @@ sub req_account_wizard {
my $metadata;
eval {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => $self->{configuration}->{_}->{federation_metadata_file}
);
};
......@@ -215,7 +215,7 @@ sub req_select_sp {
}
# Create a persistent service provider object
my $provider = IdPAccountManager::ServiceProvider->new(
my $provider = AccountManager::ServiceProvider->new(
db => $self->{db},
entityid => $self->{in}->{sp_entityid}
);
......@@ -227,7 +227,7 @@ sub req_select_sp {
my $metadata;
eval {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => $self->{configuration}->{_}->{federation_metadata_file}
);
};
......@@ -290,7 +290,7 @@ sub req_generate_token {
return;
}
my $provider = IdPAccountManager::ServiceProvider->new(
my $provider = AccountManager::ServiceProvider->new(
db => $self->{db},
entityid => $self->{in}->{sp_entityid},
);
......@@ -321,7 +321,7 @@ sub req_generate_token {
}
# delete any previous token for the same email/service couple
my $old_token = IdPAccountManager::AuthenticationToken->new(
my $old_token = AccountManager::AuthenticationToken->new(
db => $self->{db},
email_address => $self->{in}->{email_address},
sp_entityid => $self->{in}->{sp_entityid}
......@@ -339,12 +339,12 @@ sub req_generate_token {
}
# compute a new token
my $token = IdPAccountManager::AuthenticationToken->new(
my $token = AccountManager::AuthenticationToken->new(
db => $self->{db},
email_address => $self->{in}->{email_address},
sp_entityid => $self->{in}->{sp_entityid},
creation_date => DateTime->today(),
token => IdPAccountManager::Tools::generate_token()
token => AccountManager::Tools::generate_token()
);
unless ($token->save()) {
......@@ -424,7 +424,7 @@ sub req_validate_token {
return;
}
my $token = IdPAccountManager::AuthenticationToken->new(
my $token = AccountManager::AuthenticationToken->new(
db => $self->{db},
token => $self->{in}->{authentication_token}
);
......@@ -469,14 +469,14 @@ sub req_validate_token {
$self->{configuration}->{service}->{account_validity_period};
foreach my $profile (split(/, */, $profiles)) {
my $password = IdPAccountManager::Tools::generate_password();
my $account = IdPAccountManager::TestAccount->new(
my $password = AccountManager::Tools::generate_password();
my $account = AccountManager::TestAccount->new(
db => $self->{db},
profile => $profile,
sp_entityid => $entity,
scope => $self->{configuration}->{idp}->{scope},
password => $password,
password_hash => IdPAccountManager::Tools::sha256_hash($password),
password_hash => AccountManager::Tools::sha256_hash($password),
creation_date => DateTime->today(),
expiration_date => DateTime->today()->add(days => $validity_period)
);
......@@ -494,12 +494,12 @@ sub req_validate_token {
}
## Update simpleSAMLphp configuration to enable test accounts
my $accounts = IdPAccountManager::TestAccount::Manager->get_testaccounts(
my $accounts = AccountManager::TestAccount::Manager->get_testaccounts(
db => $self->{db}
);
eval {
IdPAccountManager::Tools::update_ssp_authsources(
AccountManager::Tools::update_ssp_authsources(
$self->{configuration}->{_}->{templates_dir},
$self->{configuration}->{idp}->{accounts_file},
$accounts
......
modulesdir = $(pkgdatadir)/lib
nobase_modules_DATA = \
IdPAccountManager/AuthenticationToken.pm \
IdPAccountManager/AuthenticationToken/Manager.pm \
IdPAccountManager/DB.pm \
IdPAccountManager/DB/Object.pm \
IdPAccountManager/SAMLMetadata.pm \
IdPAccountManager/ServiceProvider.pm \
IdPAccountManager/ServiceProvider/Manager.pm \
IdPAccountManager/TestAccount.pm \
IdPAccountManager/TestAccount/Manager.pm \
IdPAccountManager/Tools.pm \
IdPAccountManager/WebRequest.pm
AccountManager/AuthenticationToken.pm \
AccountManager/AuthenticationToken/Manager.pm \
AccountManager/DB.pm \
AccountManager/DB/Object.pm \
AccountManager/SAMLMetadata.pm \
AccountManager/ServiceProvider.pm \
AccountManager/ServiceProvider/Manager.pm \
AccountManager/TestAccount.pm \
AccountManager/TestAccount/Manager.pm \
AccountManager/Tools.pm \
AccountManager/WebRequest.pm
EXTRA_DIST = $(nobase_modules_DATA)
......@@ -8,19 +8,19 @@ use File::Temp;
use Test::More;
use Test::Exception;
use IdPAccountManager::SAMLMetadata;
use AccountManager::SAMLMetadata;
plan tests => 21;
my $metadata;
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new();
$metadata = AccountManager::SAMLMetadata->new();
} qr/^missing argument 'file'/,
'instanciation: no file argument';
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => '/no/such/file',
);
} qr/^non-existing file/,
......@@ -31,7 +31,7 @@ my $file1 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
chmod 0000, $file1;
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => $file1->filename()
);
} qr/^non-readable file/,
......@@ -40,7 +40,7 @@ throws_ok {
chmod 0644, $file1;
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => $file1->filename()
);
} qr/^Failed to parse file: \S+ parser error : Document is empty/,
......@@ -54,7 +54,7 @@ EOF
close($file2);
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => $file2->filename()
);
} qr/^Failed to parse file: \S+ parser error : Start tag expected/,
......@@ -69,14 +69,14 @@ EOF
close($file3);
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => $file3->filename()
);
} qr/^incorrect root element type 'root'/,
'instanciation: incorrect xml file';
lives_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
$metadata = AccountManager::SAMLMetadata->new(
file => 't/edugain.xml'
);
} 'instanciation: edugain metadata';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment