From 273df5a88dc245e8d1ba54fb8818130aef27cd70 Mon Sep 17 00:00:00 2001 From: "renater.salaun" <renater.salaun@047e039d-479c-447e-8a29-aa6bf4a09bab> Date: Tue, 14 Oct 2014 11:41:22 +0000 Subject: [PATCH] New configuration parameter to use a hard-coded set of SP contacts. Paramater: dev_sp_contact git-svn-id: https://svn.geant.net/GEANT/edugain_testidp_account_manager/trunk@24 047e039d-479c-447e-8a29-aa6bf4a09bab --- bin/account-manager-client.pl | 17 ++++++++++++++++- lib/IdPAccountManager/Tools.pm | 21 +++++++++++++++++---- templates/web/select_sp.tt2.html | 11 +++++++++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/bin/account-manager-client.pl b/bin/account-manager-client.pl index 9e2ecc4..0d3cbf4 100755 --- a/bin/account-manager-client.pl +++ b/bin/account-manager-client.pl @@ -17,7 +17,9 @@ use IdPAccountManager::ServiceProvider; use IdPAccountManager::AuthenticationToken; my %options; -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', 'get_authentication_token', 'add_authentication_token','email_address=s','token=s')) { +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', 'get_authentication_token', 'add_authentication_token','email_address=s', + 'token=s','send_notice')) { die "Unknown options."; } @@ -175,6 +177,19 @@ if ($options{'add_test_account'}) { $authentication_token->print(); +}elsif ($options{'send_notice'}) { + unless ($options{'email_address'}) { + die "Missing email_address option"; + } + + unless (&IdPAccountManager::Tools::mail_notice('template' => 'templates/mail/notification_generic_error.tt2.eml', + 'data' => {}, + 'to' => $options{'email_address'})) { + die "Failed to send mail notice to $options{'email_address'}\n"; + } + + printf "Mail notice sent to $options{'email_address'}\n"; + }else { die "Missing arguments"; diff --git a/lib/IdPAccountManager/Tools.pm b/lib/IdPAccountManager/Tools.pm index 0229d4a..190e44d 100644 --- a/lib/IdPAccountManager/Tools.pm +++ b/lib/IdPAccountManager/Tools.pm @@ -174,10 +174,23 @@ sub mail_notice { $mail_data->{'to'} = $notice_email; ## Protection to prevent notifications during test dev phases - ## Notify only admin_email - if ($Conf::global{'no_mail_outside'}) { - &do_log('info',"no_mail_outside option set; notification for %s rerouted to admins ; ", $notice_email); - $notice_email = $Conf::global{'admin_email'}; + ## Notify only admin_email or dev_sp_contact addresses + if ($Conf::global{'dev_no_mail_outside'}) { + my %rcpt = map {$_ => 1} split(/,/, $notice_email); + my %authorized_rcpt = map {$_ => 1} split(/,/, join(',', $Conf::global{'admin_email'}, $Conf::global{'dev_sp_contact'})); + + my $change_rcpt = 0; + foreach my $email (keys %rcpt) { + unless ($authorized_rcpt{$email}) { + $change_rcpt = 1; + last + } + } + + if ($change_rcpt) { + &do_log('info',"no_mail_outside option set; notification for %s rerouted to admins ; ", $notice_email); + $notice_email = $Conf::global{'admin_email'}; + } } &do_log('trace', '(template=%s, to=%s)', $in{'template'}, $mail_data->{'to'}); diff --git a/templates/web/select_sp.tt2.html b/templates/web/select_sp.tt2.html index b28867f..1c54533 100644 --- a/templates/web/select_sp.tt2.html +++ b/templates/web/select_sp.tt2.html @@ -14,10 +14,17 @@ Before you can create test accounts at this Identity Provider, we need to ensure <label for="sp_entityid">The email addresses below have been extracted from your SP SAML metadata.<br/>Please select the email address where an email challenge can be sent to validate your identity</label> + [% FOREACH contact IN sp_metadata_as_hashref.contacts -%] -[% matches = contact.EmailAddress.match('^(mailto:)?(.*)$') %] -[% SET email = matches.1%] + [% matches = contact.EmailAddress.match('^(mailto:)?(.*)$') %] + [% contacts.${matches.1} = 1 %] +[% END %] + +[% FOREACH email IN conf.dev_sp_contact.split(',') %] +[% contacts.${email} = 1 %] +[% END %] +[% FOREACH email IN contacts.keys.sort %] <input name="email_address" value="[% email %]" id="email_address" type="radio" class="required"/> <label for="email_address">[% email %]</label> -- GitLab