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
No related branches found
No related tags found
No related merge requests found
......@@ -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
);
......
......@@ -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";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment