lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CDA.pm

64 lines
1.6 KiB
Perl
Raw Normal View History

2016-04-03 10:44:58 +02:00
package Lemonldap::NG::Portal::Plugins::CDA;
use strict;
use Mouse;
2017-04-19 10:32:42 +02:00
use Lemonldap::NG::Portal::Main::Constants qw(
PE_APACHESESSIONERROR
PE_OK
);
2016-04-03 10:44:58 +02:00
2016-06-09 20:40:20 +02:00
our $VERSION = '2.0.0';
2016-06-02 23:20:36 +02:00
extends 'Lemonldap::NG::Common::Module';
2016-04-03 10:44:58 +02:00
2016-06-09 20:40:20 +02:00
# INTERFACE
2016-04-03 10:44:58 +02:00
sub afterDatas {
return 'changeUrldc';
}
2016-06-09 20:40:20 +02:00
# RUNNING METHOD
2016-04-03 10:44:58 +02:00
sub changeUrldc {
my ( $self, $req ) = @_;
2016-05-23 18:55:18 +02:00
my $urldc = $req->{urldc};
2016-04-03 10:44:58 +02:00
if ( $req->id
and $urldc !~ m#^https?://[^/]*$self->{conf}->{domain}(:\d+)?/#oi
2016-04-03 18:27:13 +02:00
and $self->p->isTrustedUrl($urldc) )
2016-04-03 10:44:58 +02:00
{
my $ssl = $urldc =~ /^https/;
2017-02-15 07:41:50 +01:00
$self->logger->debug('CDA request');
2016-11-15 14:33:39 +01:00
# Create CDA session
2017-01-24 06:10:57 +01:00
if ( my $cdaSession = $self->getApacheSession( undef, kind => "CDA" ) )
2016-11-15 14:33:39 +01:00
{
my $cdaInfos = { '_utime' => time };
if ( $self->{conf}->{securedCookie} < 2 or $ssl ) {
$cdaInfos->{cookie_value} = $req->id;
$cdaInfos->{cookie_name} = $self->{conf}->{cookieName};
}
else {
$cdaInfos->{cookie_value} =
$req->{sessionInfo}->{_httpSession};
$cdaInfos->{cookie_name} = $self->{conf}->{cookieName} . "http";
}
$self->updateSession( $cdaInfos, $cdaSession->id );
$req->{urldc} .=
( $urldc =~ /\?/ ? '&' : '?' )
. $self->{conf}->{cookieName} . "cda="
. $cdaSession->id;
2017-02-15 07:41:50 +01:00
$self->logger->debug( "CDA redirection to " . $req->{urldc} );
2016-11-15 14:33:39 +01:00
}
else {
2017-02-15 07:41:50 +01:00
$self->logger->error("Unable to create CDA session");
2016-11-15 14:33:39 +01:00
return PE_APACHESESSIONERROR;
}
2016-04-03 10:44:58 +02:00
}
PE_OK;
}
1;