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

transfer actions and parameters definitions in WebRequest class

parent 7b2e2ec4
Branches
Tags
No related merge requests found
...@@ -8,38 +8,16 @@ use lib qw(lib); ...@@ -8,38 +8,16 @@ use lib qw(lib);
use IdPAccountManager::Configuration; use IdPAccountManager::Configuration;
use IdPAccountManager::WebRequest; 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( my $configuration = IdPAccountManager::Configuration->new(
file => 'conf/IdPAccountManager.conf' 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 ## Gives writes for the group
umask 0002; umask 0002;
chdir $configuration->{root_manager_dir}; chdir $configuration->{root_manager_dir};
my $request = new IdPAccountManager::WebRequest( my $request = new IdPAccountManager::WebRequest(
actions => \%actions,
format => \%format,
configuration => $configuration configuration => $configuration
); );
......
...@@ -13,13 +13,35 @@ use IdPAccountManager::Data::ServiceProvider; ...@@ -13,13 +13,35 @@ use IdPAccountManager::Data::ServiceProvider;
use IdPAccountManager::Logger; use IdPAccountManager::Logger;
use IdPAccountManager::SAMLMetadata; 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 ## New web request
sub new { sub new {
my ($pkg, %args) = @_; my ($pkg, %args) = @_;
my $self = { my $self = {
format => $args{format},
actions => $args{actions},
configuration => $args{configuration}, configuration => $args{configuration},
}; };
...@@ -59,7 +81,7 @@ sub execute { ...@@ -59,7 +81,7 @@ sub execute {
$self->{param_out} = { $self->{param_out} = {
url_cgi => $ENV{SCRIPT_NAME}, url_cgi => $ENV{SCRIPT_NAME},
env => \%ENV, env => \%ENV,
actions => $self->{actions}, actions => \%actions,
conf => $self->{configuration}, conf => $self->{configuration},
}; };
...@@ -74,9 +96,9 @@ sub execute { ...@@ -74,9 +96,9 @@ sub execute {
$parameters{$parameter} =~ s/^\s+//; # remove leading spaces $parameters{$parameter} =~ s/^\s+//; # remove leading spaces
# format check # format check
if (defined $self->{format}->{$parameter} if (defined $format{$parameter}
&& !ref($self->{format}->{$parameter})) { && !ref($format{$parameter})) {
if ($parameters{$parameter} !~ /^$self->format->{$parameter}$/) { if ($parameters{$parameter} !~ /^$format{$parameter}$/) {
push @{ $self->{param_out}->{errors} }, "format_$parameter"; push @{ $self->{param_out}->{errors} }, "format_$parameter";
$self->{logger}->log( $self->{logger}->log(
level => LOG_ERROR, level => LOG_ERROR,
...@@ -103,11 +125,9 @@ sub execute { ...@@ -103,11 +125,9 @@ sub execute {
# Check the requested action # Check the requested action
my $action = $parameters{action} || 'home'; my $action = $parameters{action} || 'home';
if ($self->{actions}->{$action}) { if ($actions{$action}) {
## Execute the target subroutine named req_actionName my $method = $actions{$action};
no strict 'refs'; $status = $self->$method();
my $sub = 'req_' . $action;
$status = &{$sub}($self);
} else { } else {
## inknown action ## inknown action
push @{ $self->{param_out}->{errors} }, "unknown_action"; push @{ $self->{param_out}->{errors} }, "unknown_action";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment