diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl index c1dccd6970b3ec92a6318be133a9d2b35d8ac8d0..79a2c3c06b86ee289f6362786bf016435a259892 100755 --- a/bin/account-manager-client.pl +++ b/bin/account-manager-client.pl @@ -5,7 +5,7 @@ use strict; use utf8; -use lib "/opt/testidp/IdPAccountManager/lib"; +use lib "/opt/testidp/IdPAccountManager/lib", ; use lib "/opt/testidp/IdPAccountManager/conf"; use Getopt::Long; @@ -14,17 +14,18 @@ use POSIX; use IdPAccountManager::TestAccount; use IdPAccountManager::SAMLMetadata; use IdPAccountManager::ServiceProvider; +use IdPAccountManager::AuthenticationToken; my %options; -unless (&GetOptions(\%options, 'help', 'create_test_account', 'account_profile=s', 'sp_entityid=s', 'list_test_accounts', 'parse_federation_metadata', 'list_service_providers')) { +unless (&GetOptions(\%options, 'help', 'add_test_account', 'account_profile=s', 'sp_entityid=s', 'list_test_accounts', 'parse_federation_metadata', 'list_service_providers','list_authentication_tokens', 'add_authentication_token','email_address=s')) { die "Unknown options."; } if ($options{'help'}) { - printf "$0 --create_test_account --account_profile=<profile_id> --sp_entityid=<entityid>\n"; + printf "$0 --add_test_account --account_profile=<profile_id> --sp_entityid=<entityid>\n"; } -if ($options{'create_test_account'}) { +if ($options{'add_test_account'}) { unless ($options{'account_profile'}) { die "Missing account_profile option"; @@ -62,6 +63,10 @@ if ($options{'create_test_account'}) { my $all = IdPAccountManager::TestAccount::list_test_accounts(%args); + if ($#{$all} < 0) { + printf "No test account in DB\n"; + } + foreach my $test_account (@$all) { $test_account->print(); } @@ -92,10 +97,55 @@ if ($options{'create_test_account'}) { my $all = IdPAccountManager::ServiceProvider::list_service_providers(%args); + if ($#{$all} < 0) { + printf "No service provider in DB\n"; + } + foreach my $service_provider (@$all) { $service_provider->print(); } +}elsif ($options{'list_authentication_tokens'}) { + + my %args; + + my $all = IdPAccountManager::AuthenticationToken::list_authentication_tokens(%args); + + if ($#{$all} < 0) { + printf "No token in DB\n"; + } + + foreach my $authentication_token (@$all) { + $authentication_token->print(); + } + +}elsif ($options{'add_authentication_token'}) { + + unless ($options{'email_address'}) { + die "Missing email_address option"; + } + + unless ($options{'sp_entityid'}) { + die "Missing sp_entityid option"; + } + + my $authentication_token = new IdPAccountManager::AuthenticationToken(); + unless (defined $authentication_token) { + IdPAccountManager::Tools::do_log('error',"Failed to create token object"); + exit -1; + } + unless ($authentication_token->set('email_address' => $options{'email_address'})) { + IdPAccountManager::Tools::do_log('error',"Failed to set token value"); + exit -1; + } + + unless ($authentication_token->save()) { + IdPAccountManager::Tools::do_log('error',"Failed to create token"); + exit -1; + } + + $authentication_token->print(); + }else { die "Missing arguments";