From a87808f160b389a22d3a9b6524fcdf452d22b8b2 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Fri, 3 Nov 2017 16:44:41 +0100 Subject: [PATCH] transfer actions and parameters definitions in WebRequest class --- bin/account-manager-web.pl | 22 --------------- lib/IdPAccountManager/WebRequest.pm | 42 +++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/bin/account-manager-web.pl b/bin/account-manager-web.pl index e862c55..1f695c0 100755 --- a/bin/account-manager-web.pl +++ b/bin/account-manager-web.pl @@ -8,38 +8,16 @@ use lib qw(lib); use IdPAccountManager::Configuration; use IdPAccountManager::WebRequest; -## Defining parameters format -my $urn_or_url_regex = '(http(s?):\/\/|urn:)[^\\\$\*\"\'\`\^\|\<\>\n\s]+' - ; ## Format de type URL HTTP ou URN -my $url_regex = 'http(s?):\/\/[^\\\$\*\"\'\`\^\|\<\>\n\s]+'; -my $email_regex = '([\w\-\_\.\/\+\=\'\&]+|\".*\")\@[\w\-]+(\.[\w\-]+)+'; -my $domains_regex = '[\w\.\-]+(,[\w\.\-]+)*'; -my %format = ( - ## URL - #'attributeauthority' => $url_regex, - 'sp_entityid' => $urn_or_url_regex, -); - my $configuration = IdPAccountManager::Configuration->new( file => 'conf/IdPAccountManager.conf' ); -my %actions = ( - 'select_sp' => { 'title_en' => 'Select your Service Provider' }, - 'account_wizard' => { 'title_en' => 'Select your Service Provider' }, - 'generate_token' => { 'title_en' => 'Generate an authentication token' }, - 'validate_token' => { 'title_en' => 'Complete Email Challenge' }, - 'home' => { 'title_en' => $configuration->{app_name} }, -); - ## Gives writes for the group umask 0002; chdir $configuration->{root_manager_dir}; my $request = new IdPAccountManager::WebRequest( - actions => \%actions, - format => \%format, configuration => $configuration ); diff --git a/lib/IdPAccountManager/WebRequest.pm b/lib/IdPAccountManager/WebRequest.pm index 0bdc94b..6cc0c14 100755 --- a/lib/IdPAccountManager/WebRequest.pm +++ b/lib/IdPAccountManager/WebRequest.pm @@ -13,13 +13,35 @@ use IdPAccountManager::Data::ServiceProvider; use IdPAccountManager::Logger; use IdPAccountManager::SAMLMetadata; +## Defining parameters format +my $urn_or_url_regex = '(http(s?):\/\/|urn:)[^\\\$\*\"\'\`\^\|\<\>\n\s]+' + ; ## Format de type URL HTTP ou URN +my $url_regex = 'http(s?):\/\/[^\\\$\*\"\'\`\^\|\<\>\n\s]+'; +my $email_regex = '([\w\-\_\.\/\+\=\'\&]+|\".*\")\@[\w\-]+(\.[\w\-]+)+'; +my $domains_regex = '[\w\.\-]+(,[\w\.\-]+)*'; +my %format = ( + ## URL + #'attributeauthority' => $url_regex, + 'sp_entityid' => $urn_or_url_regex, +); + +my $configuration = IdPAccountManager::Configuration->new( + file => 'conf/IdPAccountManager.conf' +); + +my %actions = ( + select_sp => 'req_select_sp', + account_wizard => 'req_account_wizard', + generate_token => 'req_generate_token', + validate_token => 'req_validation_token', + home => 'req_home', +); + ## New web request sub new { my ($pkg, %args) = @_; my $self = { - format => $args{format}, - actions => $args{actions}, configuration => $args{configuration}, }; @@ -59,7 +81,7 @@ sub execute { $self->{param_out} = { url_cgi => $ENV{SCRIPT_NAME}, env => \%ENV, - actions => $self->{actions}, + actions => \%actions, conf => $self->{configuration}, }; @@ -74,9 +96,9 @@ sub execute { $parameters{$parameter} =~ s/^\s+//; # remove leading spaces # format check - if (defined $self->{format}->{$parameter} - && !ref($self->{format}->{$parameter})) { - if ($parameters{$parameter} !~ /^$self->format->{$parameter}$/) { + if (defined $format{$parameter} + && !ref($format{$parameter})) { + if ($parameters{$parameter} !~ /^$format{$parameter}$/) { push @{ $self->{param_out}->{errors} }, "format_$parameter"; $self->{logger}->log( level => LOG_ERROR, @@ -103,11 +125,9 @@ sub execute { # Check the requested action my $action = $parameters{action} || 'home'; - if ($self->{actions}->{$action}) { - ## Execute the target subroutine named req_actionName - no strict 'refs'; - my $sub = 'req_' . $action; - $status = &{$sub}($self); + if ($actions{$action}) { + my $method = $actions{$action}; + $status = $self->$method(); } else { ## inknown action push @{ $self->{param_out}->{errors} }, "unknown_action"; -- GitLab