2016-06-12 18:52:37 +02:00
|
|
|
package Lemonldap::NG::Portal::Issuer::Get;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2016-06-12 21:26:14 +02:00
|
|
|
use URI::Escape;
|
2016-06-12 18:52:37 +02:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_BADURL);
|
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Main::Issuer';
|
|
|
|
|
|
|
|
# RUNNING METHODS
|
|
|
|
|
|
|
|
sub run {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
# Session ID
|
2017-03-03 13:17:15 +01:00
|
|
|
my $session_id = $req->{sessionInfo}->{_session_id} || $self->{id};
|
2016-06-12 18:52:37 +02:00
|
|
|
|
|
|
|
# Session creation timestamp
|
2017-03-03 13:17:15 +01:00
|
|
|
my $time = $req->{sessionInfo}->{_utime} || time();
|
2016-06-12 21:26:14 +02:00
|
|
|
$req->path =~ m#^$self->{conf}->{issuerDBGetPath}/(log(?:in|out))#;
|
2016-06-12 18:52:37 +02:00
|
|
|
my $logInOut = $1 || 'login';
|
|
|
|
if ( $logInOut eq 'login' ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("IssuerGet: request for login");
|
2016-06-12 18:52:37 +02:00
|
|
|
$self->computeGetParams($req);
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
elsif ( $logInOut eq 'logout' ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("IssuerGet: request for logout");
|
2016-06-12 18:52:37 +02:00
|
|
|
|
|
|
|
# TODO
|
|
|
|
# Display a link to the provided URL
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("IssuerGet: bad url");
|
2016-06-12 18:52:37 +02:00
|
|
|
return PE_BADURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Nothing to do here for now
|
|
|
|
sub logout {
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
# INTERNAL METHODS
|
|
|
|
|
|
|
|
sub computeGetParams {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
# Additional GET variables
|
|
|
|
my @getPrms;
|
|
|
|
if ( exists $self->conf->{issuerDBGetParameters} ) {
|
|
|
|
unless ( $req->urldc =~ m#^https?://([^/]+)# ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Malformed url $req->urldc");
|
2016-06-12 18:52:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $vhost = $1;
|
|
|
|
my $prms = $self->conf->{issuerDBGetParameters}->{$vhost};
|
|
|
|
unless ($prms) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->warn("IssuerGet: $vhost has no configuration");
|
2016-06-12 18:52:37 +02:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
foreach my $param ( keys %$prms ) {
|
|
|
|
my $value =
|
|
|
|
eval { uri_escape( $req->{sessionInfo}->{ $prms->{$param} } ) };
|
|
|
|
if ($@) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error(
|
|
|
|
"IssuerGet: unable to compute $param ($@)");
|
2016-06-12 18:52:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$value =~ s/[\r\n\t]//;
|
|
|
|
push @getPrms, "$param=$value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->warn("IssuerGet: no configuration");
|
2016-06-12 18:52:37 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $getVars = join '&', @getPrms;
|
|
|
|
|
|
|
|
# If there are some GET variables to send
|
|
|
|
# Add them to URL string
|
|
|
|
if ( $getVars ne "" ) {
|
|
|
|
my $urldc = $req->urldc;
|
|
|
|
|
|
|
|
$urldc .= ( $urldc =~ /\?\w/ )
|
|
|
|
?
|
|
|
|
|
|
|
|
# there are already get variables
|
|
|
|
"&" . $getVars
|
|
|
|
:
|
|
|
|
|
|
|
|
# there are no get variables
|
|
|
|
"?" . $getVars;
|
|
|
|
$req->urldc($urldc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|