2016-12-20 13:19:26 +01:00
|
|
|
package Lemonldap::NG::Portal::Issuer::CAS;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2016-12-21 23:39:12 +01:00
|
|
|
use URI;
|
2018-06-26 19:13:06 +02:00
|
|
|
use Lemonldap::NG::Common::FormEncode;
|
2016-12-20 13:19:26 +01:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
2019-02-07 09:27:56 +01:00
|
|
|
PE_CAS_SERVICE_NOT_ALLOWED
|
2019-06-11 16:04:24 +02:00
|
|
|
PE_INFO
|
2019-02-07 09:27:56 +01:00
|
|
|
PE_ERROR
|
|
|
|
PE_LOGOUT_OK
|
|
|
|
PE_OK
|
2019-06-27 12:36:18 +02:00
|
|
|
PE_BADURL
|
2019-02-07 09:27:56 +01:00
|
|
|
PE_SENDRESPONSE
|
2016-12-20 13:19:26 +01:00
|
|
|
);
|
|
|
|
|
2019-02-12 18:21:38 +01:00
|
|
|
our $VERSION = '2.1.0';
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Main::Issuer',
|
2019-02-07 09:27:56 +01:00
|
|
|
'Lemonldap::NG::Portal::Lib::CAS';
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# INITIALIZATION
|
|
|
|
|
2018-06-30 07:44:05 +02:00
|
|
|
use constant beforeAuth => 'storeEnvAndCheckGateway';
|
|
|
|
use constant sessionKind => 'ICAS';
|
2018-06-23 10:18:55 +02:00
|
|
|
|
2019-02-14 22:12:40 +01:00
|
|
|
has rule => ( is => 'rw' );
|
2019-02-06 22:16:34 +01:00
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
sub init {
|
|
|
|
my ($self) = @_;
|
2019-02-06 22:16:34 +01:00
|
|
|
|
2019-02-06 22:54:15 +01:00
|
|
|
# Parse activation rule
|
|
|
|
my $hd = $self->p->HANDLER;
|
|
|
|
$self->logger->debug( "CAS rule -> " . $self->conf->{issuerDBCASRule} );
|
2019-02-07 09:27:56 +01:00
|
|
|
my $rule =
|
|
|
|
$hd->buildSub( $hd->substitute( $self->conf->{issuerDBCASRule} ) );
|
2019-02-06 22:16:34 +01:00
|
|
|
unless ($rule) {
|
2019-02-06 22:54:15 +01:00
|
|
|
$self->error( "Bad CAS rule -> " . $hd->tsv->{jail}->error );
|
2019-02-06 22:16:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$self->{rule} = $rule;
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2019-02-06 22:54:15 +01:00
|
|
|
# Launch parents initialization subroutines, then launch IdP and SP lists
|
2016-12-21 23:39:12 +01:00
|
|
|
my $res = $self->Lemonldap::NG::Portal::Main::Issuer::init();
|
2017-04-14 09:40:01 +02:00
|
|
|
return 0 unless ( $self->loadApp );
|
2016-12-21 23:39:12 +01:00
|
|
|
$self->addUnauthRoute(
|
|
|
|
( $self->path ) => {
|
|
|
|
serviceValidate => 'serviceValidate',
|
|
|
|
validate => 'validate',
|
|
|
|
proxyValidate => 'proxyValidate',
|
2018-02-08 22:40:06 +01:00
|
|
|
proxy => 'proxy',
|
|
|
|
p3 => {
|
|
|
|
serviceValidate => 'serviceValidate',
|
|
|
|
proxyValidate => 'proxyValidate'
|
|
|
|
}
|
2016-12-21 23:39:12 +01:00
|
|
|
},
|
|
|
|
['GET']
|
|
|
|
);
|
2019-06-27 16:55:12 +02:00
|
|
|
|
|
|
|
# Add CAS Services, so we can check service= parameter on logout
|
|
|
|
foreach my $casSrv ( keys %{ $self->conf->{casAppMetaDataOptions} } ) {
|
|
|
|
if ( my $serviceUrl =
|
|
|
|
$self->conf->{casAppMetaDataOptions}->{$casSrv}
|
|
|
|
->{casAppMetaDataOptionsService} )
|
|
|
|
{
|
|
|
|
push @{ $self->p->{additionalTrustedDomains} }, $serviceUrl;
|
|
|
|
$self->logger->debug(
|
|
|
|
"CAS Service $serviceUrl added in trusted domains");
|
|
|
|
}
|
|
|
|
}
|
2016-12-21 23:39:12 +01:00
|
|
|
return $res;
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# RUNNING METHODS
|
|
|
|
|
2018-06-25 10:10:22 +02:00
|
|
|
sub storeEnvAndCheckGateway {
|
2018-06-23 10:18:55 +02:00
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my $service = $self->p->getHiddenFormValue( $req, 'service' )
|
2019-02-07 09:27:56 +01:00
|
|
|
|| $req->param('service');
|
2019-06-11 21:02:43 +02:00
|
|
|
$service = '' if ( $self->p->checkXSSAttack( 'service', $service ) );
|
2018-06-25 10:10:22 +02:00
|
|
|
my $gateway = $self->p->getHiddenFormValue( $req, 'gateway' )
|
2019-02-07 09:27:56 +01:00
|
|
|
|| $req->param('gateway');
|
2018-06-25 10:10:22 +02:00
|
|
|
|
|
|
|
if ( $gateway and $gateway eq "true" ) {
|
|
|
|
$self->logger->debug(
|
|
|
|
"Gateway mode requested, redirect without authentication");
|
|
|
|
$req->response( [ 302, [ Location => $service ], [] ] );
|
2019-06-09 09:11:10 +02:00
|
|
|
for my $s ( $self->ipath, $self->ipath . 'Path' ) {
|
|
|
|
$self->logger->debug("Removing $s from pdata")
|
|
|
|
if delete $req->pdata->{$s};
|
|
|
|
}
|
|
|
|
|
2018-06-25 10:10:22 +02:00
|
|
|
return PE_SENDRESPONSE;
|
|
|
|
}
|
2018-06-23 10:18:55 +02:00
|
|
|
|
|
|
|
if ( $service and $service =~ m#^(https?://[^/]+)(/.*)?$# ) {
|
|
|
|
my ( $host, $uri ) = ( $1, $2 );
|
|
|
|
my $app = $self->casAppList->{$host};
|
|
|
|
|
|
|
|
if ($app) {
|
|
|
|
$req->env->{llng_cas_app} = $app;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
# Main method (launched only for authenticated users, see Main/Issuer)
|
|
|
|
sub run {
|
|
|
|
my ( $self, $req, $target ) = @_;
|
|
|
|
|
2019-02-06 22:54:15 +01:00
|
|
|
# Check activation rule
|
2019-02-06 22:16:34 +01:00
|
|
|
unless ( $self->rule->( $req, $req->sessionInfo ) ) {
|
|
|
|
$self->userLogger->error('CAS service not authorized');
|
|
|
|
return PE_CAS_SERVICE_NOT_ALLOWED;
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
# CAS URL
|
2018-02-08 22:40:06 +01:00
|
|
|
my $cas_login = 'login';
|
|
|
|
my $cas_logout = 'logout';
|
|
|
|
my $cas_validate = 'validate';
|
|
|
|
my $cas_serviceValidate = 'serviceValidate';
|
|
|
|
my $cas_p3_serviceValidate = 'p3/serviceValidate';
|
|
|
|
my $cas_proxyValidate = 'proxyValidate';
|
|
|
|
my $cas_p3_proxyValidate = 'p3/proxyValidate';
|
|
|
|
my $cas_proxy = 'proxy';
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# Called URL
|
|
|
|
my $url = $req->uri();
|
|
|
|
|
|
|
|
# Session ID
|
2019-12-31 17:14:44 +01:00
|
|
|
my $session_id = $req->{sessionInfo}->{_session_id} || $req->id;
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# Session creation timestamp
|
|
|
|
my $time = $req->{sessionInfo}->{_utime} || time();
|
|
|
|
|
|
|
|
# 1. LOGIN
|
|
|
|
if ( $target eq $cas_login ) {
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("URL $url detected as an CAS LOGIN URL");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# GET parameters
|
2016-12-21 19:06:23 +01:00
|
|
|
my $service = $self->p->getHiddenFormValue( $req, 'service' )
|
2019-02-07 09:27:56 +01:00
|
|
|
|| $req->param('service');
|
2019-06-11 21:30:15 +02:00
|
|
|
$service = '' if ( $self->p->checkXSSAttack( 'service', $service ) );
|
2019-02-06 22:16:34 +01:00
|
|
|
my $renew = $self->p->getHiddenFormValue( $req, 'renew' )
|
2019-02-07 09:27:56 +01:00
|
|
|
|| $req->param('renew');
|
2016-12-21 19:06:23 +01:00
|
|
|
my $gateway = $self->p->getHiddenFormValue( $req, 'gateway' )
|
2019-02-07 09:27:56 +01:00
|
|
|
|| $req->param('gateway');
|
2016-12-20 13:19:26 +01:00
|
|
|
my $casServiceTicket;
|
|
|
|
|
|
|
|
# Renew
|
2018-05-15 19:46:02 +02:00
|
|
|
if ( $renew
|
|
|
|
and $renew eq 'true'
|
2019-02-07 09:27:56 +01:00
|
|
|
and time - $req->sessionInfo->{_utime} >
|
|
|
|
$self->conf->{portalForceAuthnInterval} )
|
2018-05-15 19:46:02 +02:00
|
|
|
{
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# Authentication must be replayed
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Authentication renew requested");
|
2016-12-20 13:19:26 +01:00
|
|
|
$self->{updateSession} = 1;
|
2018-05-14 21:33:21 +02:00
|
|
|
$req->env->{QUERY_STRING} =~ s/renew=true/renew=false/;
|
|
|
|
return $self->reAuth($req);
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# If no service defined, exit
|
|
|
|
unless ( defined $service ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("No service defined in CAS URL");
|
2016-12-20 13:19:26 +01:00
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
2017-04-14 09:40:01 +02:00
|
|
|
unless ( $service =~ m#^(https?://[^/]+)(/.*)?$# ) {
|
|
|
|
$self->logger->error("Bad service $service");
|
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
my ( $host, $uri ) = ( $1, $2 );
|
|
|
|
my $app = $self->casAppList->{$host};
|
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
# Check access on the service
|
|
|
|
my $casAccessControlPolicy = $self->conf->{casAccessControlPolicy};
|
|
|
|
|
|
|
|
if ( $casAccessControlPolicy =~ /^(error|faketicket)$/i ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"CAS access control requested on service $service");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2017-04-14 09:40:01 +02:00
|
|
|
unless ($app) {
|
2017-04-13 21:17:29 +02:00
|
|
|
$self->userLogger->error('CAS service not configured');
|
|
|
|
return PE_CAS_SERVICE_NOT_ALLOWED;
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
2017-11-11 13:51:48 +01:00
|
|
|
if ( my $rule = $self->spRules->{$app} ) {
|
2017-04-14 09:40:01 +02:00
|
|
|
if ( $rule->( $req, $req->sessionInfo ) ) {
|
2019-02-07 09:27:56 +01:00
|
|
|
$self->logger->debug("CAS service $service access allowed");
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-09-19 16:18:51 +02:00
|
|
|
$self->userLogger->warn( 'User '
|
|
|
|
. $req->sessionInfo->{ $self->conf->{whatToTrace} }
|
|
|
|
. " is not authorized to access to $service" );
|
2017-04-13 21:17:29 +02:00
|
|
|
|
|
|
|
if ( $casAccessControlPolicy =~ /^(error)$/i ) {
|
|
|
|
$self->logger->debug(
|
2019-02-07 09:27:56 +01:00
|
|
|
"Return error instead of redirecting user on CAS service"
|
2017-04-13 21:17:29 +02:00
|
|
|
);
|
|
|
|
return PE_CAS_SERVICE_NOT_ALLOWED;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
$self->logger->debug(
|
2019-02-07 09:27:56 +01:00
|
|
|
"Redirect user on CAS service with a fake ticket");
|
2017-04-13 21:17:29 +02:00
|
|
|
$casServiceTicket = "ST-F4K3T1CK3T";
|
|
|
|
}
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 16:52:08 +02:00
|
|
|
$self->userLogger->notice( 'User '
|
|
|
|
. $req->sessionInfo->{ $self->conf->{whatToTrace} }
|
|
|
|
. " is authorized to access to $service" );
|
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
unless ($casServiceTicket) {
|
|
|
|
|
|
|
|
# Check last authentication time to decide if
|
|
|
|
# the authentication is recent or not
|
2019-07-02 20:03:40 +02:00
|
|
|
my $casRenewFlag = 0;
|
2019-02-07 09:27:56 +01:00
|
|
|
my $last_authn_utime = $req->{sessionInfo}->{_lastAuthnUTime} || 0;
|
|
|
|
if (
|
|
|
|
time() - $last_authn_utime <
|
|
|
|
$self->conf->{portalForceAuthnInterval} )
|
2016-12-20 13:19:26 +01:00
|
|
|
{
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"Authentication is recent, will set CAS renew flag to true"
|
2016-12-20 13:19:26 +01:00
|
|
|
);
|
|
|
|
$casRenewFlag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create a service ticket
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"Create a CAS service ticket for service $service");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
my $Sinfos;
|
|
|
|
$Sinfos->{type} = 'casService';
|
|
|
|
$Sinfos->{service} = $service;
|
|
|
|
$Sinfos->{renew} = $casRenewFlag;
|
|
|
|
$Sinfos->{_cas_id} = $session_id;
|
|
|
|
$Sinfos->{_utime} = $time;
|
2017-04-14 09:40:01 +02:00
|
|
|
$Sinfos->{_casApp} = $app;
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2017-02-20 22:00:05 +01:00
|
|
|
my $casServiceSession = $self->getCasSession( undef, $Sinfos );
|
|
|
|
|
|
|
|
unless ($casServiceSession) {
|
|
|
|
$self->logger->error("Unable to create CAS session");
|
|
|
|
return PE_ERROR;
|
|
|
|
}
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
my $casServiceSessionID = $casServiceSession->id;
|
|
|
|
$casServiceTicket = "ST-" . $casServiceSessionID;
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"CAS service session $casServiceSessionID created");
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Redirect to service
|
|
|
|
my $service_url = $service;
|
2018-06-26 19:13:06 +02:00
|
|
|
$service_url .= ( $service =~ /\?/ ? '&' : '?' )
|
2019-02-07 09:27:56 +01:00
|
|
|
. build_urlencoded( ticket => $casServiceTicket );
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Redirect user to $service_url");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2016-12-21 19:06:23 +01:00
|
|
|
$req->{urldc} = $service_url;
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2016-12-21 23:39:12 +01:00
|
|
|
$req->steps( [] );
|
2016-12-21 19:06:23 +01:00
|
|
|
return PE_OK;
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# 2. LOGOUT
|
|
|
|
if ( $target eq $cas_logout ) {
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("URL $url detected as an CAS LOGOUT URL");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2017-01-20 07:29:49 +01:00
|
|
|
# Disable Content-Security-Policy header since logout can be embedded
|
|
|
|
# in a frame
|
|
|
|
$req->frame(1);
|
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
# GET parameters
|
2017-09-11 17:26:44 +02:00
|
|
|
my $logout_url = $req->param('url'); # CAS 2.0
|
|
|
|
my $logout_service = $req->param('service'); # CAS 3.0
|
2019-06-11 21:30:15 +02:00
|
|
|
$logout_service = ''
|
|
|
|
if ( $self->p->checkXSSAttack( 'service', $logout_service ) );
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2019-06-27 12:36:18 +02:00
|
|
|
# If we use access control, check that the service URL is trusted
|
|
|
|
if ( $self->conf->{casAccessControlPolicy} =~ /^(error|faketicket)$/i )
|
|
|
|
{
|
|
|
|
if ( $logout_service
|
|
|
|
and not $self->p->isTrustedUrl($logout_service) )
|
|
|
|
{
|
|
|
|
$self->userLogger->error(
|
|
|
|
"Untrusted service URL $logout_service"
|
|
|
|
. "specified for CAS Logout" );
|
|
|
|
return PE_BADURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
# Delete linked CAS sessions
|
|
|
|
$self->deleteCasSecondarySessions($session_id);
|
|
|
|
|
|
|
|
# Delete local session
|
2017-01-24 06:10:57 +01:00
|
|
|
if ( my $session = $self->p->getApacheSession($session_id) ) {
|
2016-12-22 21:18:59 +01:00
|
|
|
unless ( $self->p->_deleteSession( $req, $session ) ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Fail to delete session $session_id ");
|
2016-12-22 21:18:59 +01:00
|
|
|
}
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2016-12-22 21:18:59 +01:00
|
|
|
if ($logout_url) {
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2016-12-22 21:18:59 +01:00
|
|
|
# Display a link to the provided URL
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"Logout URL $logout_url will be displayed");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2017-02-07 18:57:19 +01:00
|
|
|
$req->info(
|
2017-10-10 13:04:40 +02:00
|
|
|
$self->loadTemplate(
|
2019-06-28 13:40:56 +02:00
|
|
|
$req, 'casBack2Url',
|
|
|
|
params => { url => $logout_url }
|
2017-10-10 13:04:40 +02:00
|
|
|
)
|
2016-12-22 21:18:59 +01:00
|
|
|
);
|
2018-07-05 22:56:16 +02:00
|
|
|
$req->data->{activeTimer} = 0;
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2019-06-11 16:04:24 +02:00
|
|
|
delete $req->pdata->{_url};
|
|
|
|
return PE_INFO;
|
2016-12-22 21:18:59 +01:00
|
|
|
}
|
2017-09-11 17:26:44 +02:00
|
|
|
|
|
|
|
if ($logout_service) {
|
2017-09-26 21:11:04 +02:00
|
|
|
$self->logger->debug(
|
|
|
|
"User will be redirected to $logout_service");
|
2017-09-11 17:26:44 +02:00
|
|
|
$req->{urldc} = $logout_service;
|
|
|
|
$req->steps( [] );
|
|
|
|
return PE_OK;
|
|
|
|
}
|
2016-12-22 21:18:59 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->info("Unknown session $session_id");
|
2016-12-20 13:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return PE_LOGOUT_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# 3. VALIDATE [CAS 1.0]
|
|
|
|
if ( $target eq $cas_validate ) {
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("URL $url detected as an CAS VALIDATE URL");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# This URL must not be called by authenticated users
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->userLogger->info(
|
|
|
|
"CAS VALIDATE URL called by authenticated user, ignore it");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
# 4. SERVICE VALIDATE [CAS 2.0]
|
2019-02-06 22:16:34 +01:00
|
|
|
if ( $target eq $cas_serviceValidate
|
|
|
|
|| $target eq $cas_p3_serviceValidate )
|
2018-02-08 22:40:06 +01:00
|
|
|
{
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"URL $url detected as an CAS SERVICE VALIDATE URL");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# This URL must not be called by authenticated users
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->userLogger->info(
|
2019-02-07 09:27:56 +01:00
|
|
|
"CAS SERVICE VALIDATE URL called by authenticated user, ignore it");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
# 5. PROXY VALIDATE [CAS 2.0]
|
2018-02-08 22:40:06 +01:00
|
|
|
if ( $target eq $cas_proxyValidate || $target eq $cas_p3_proxyValidate ) {
|
2016-12-20 13:19:26 +01:00
|
|
|
|
2019-02-07 09:27:56 +01:00
|
|
|
$self->logger->debug("URL $url detected as an CAS PROXY VALIDATE URL");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# This URL must not be called by authenticated users
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->userLogger->info(
|
|
|
|
"CAS PROXY VALIDATE URL called by authenticated user, ignore it");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
# 6. PROXY [CAS 2.0]
|
|
|
|
if ( $target eq $cas_proxy ) {
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("URL $url detected as an CAS PROXY URL");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# This URL must not be called by authenticated users
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->userLogger->info(
|
|
|
|
"CAS PROXY URL called by authenticated user, ignore it");
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub logout {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
# Session ID
|
2019-12-31 17:14:44 +01:00
|
|
|
my $session_id = $req->{sessionInfo}->{_session_id} || $req->id;
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
# Delete linked CAS sessions
|
2019-04-02 16:13:45 +02:00
|
|
|
$self->deleteCasSecondarySessions($session_id) if ($session_id);
|
2016-12-20 13:19:26 +01:00
|
|
|
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-21 23:39:12 +01:00
|
|
|
# Direct request from SP to IdP
|
|
|
|
|
|
|
|
sub validate {
|
|
|
|
my ( $self, $req ) = @_;
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
'URL ' . $req->uri . ' detected as an CAS VALIDATE URL' );
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# GET parameters
|
|
|
|
my $service = $req->param('service');
|
|
|
|
my $ticket = $req->param('ticket');
|
|
|
|
my $renew = $req->param('renew');
|
|
|
|
|
|
|
|
# Required parameters: service and ticket
|
|
|
|
unless ( $service and $ticket ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Service and Ticket parameters required");
|
2016-12-21 23:39:12 +01:00
|
|
|
return $self->returnCasValidateError();
|
|
|
|
}
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"Get validate request with ticket $ticket for service $service");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
unless ( $ticket =~ s/^ST-// ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Provided ticket is not a service ticket (ST)");
|
2016-12-21 23:39:12 +01:00
|
|
|
return $self->returnCasValidateError();
|
|
|
|
}
|
|
|
|
|
|
|
|
my $casServiceSession = $self->getCasSession($ticket);
|
|
|
|
|
|
|
|
unless ($casServiceSession) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Service ticket session $ticket not found");
|
2016-12-21 23:39:12 +01:00
|
|
|
return $self->returnCasValidateError();
|
|
|
|
}
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Service ticket session $ticket found");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
my $service1_uri = URI->new($service);
|
|
|
|
my $service2_uri = URI->new( $casServiceSession->data->{service} );
|
|
|
|
|
|
|
|
# Check service
|
|
|
|
unless ( $service1_uri->eq($service2_uri) ) {
|
|
|
|
|
|
|
|
# Tolerate that relative URI are the same
|
|
|
|
if ( $service1_uri->rel($service2_uri) eq "./"
|
|
|
|
or $service2_uri->rel($service1_uri) eq "./" )
|
|
|
|
{
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->notice(
|
2019-02-07 09:27:56 +01:00
|
|
|
"Submitted service $service1_uri does not exactly match initial service "
|
|
|
|
. $service2_uri
|
|
|
|
. ' but difference is tolerated.' );
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error(
|
2016-12-21 23:39:12 +01:00
|
|
|
"Submitted service $service does not match initial service "
|
2019-02-07 09:27:56 +01:00
|
|
|
. $casServiceSession->data->{service} );
|
2016-12-21 23:39:12 +01:00
|
|
|
$self->deleteCasSession($casServiceSession);
|
|
|
|
return $self->returnCasValidateError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-02-07 09:27:56 +01:00
|
|
|
$self->logger->debug("Submitted service $service math initial servce");
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check renew
|
2016-12-22 23:06:13 +01:00
|
|
|
if ( $renew and $renew eq 'true' ) {
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# We should check the ST was delivered with primary credentials
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Renew flag detected ");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
unless ( $casServiceSession->data->{renew} ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error(
|
2019-02-07 09:27:56 +01:00
|
|
|
"Authentication renew requested, but not done in former authentication process"
|
2016-12-21 23:39:12 +01:00
|
|
|
);
|
|
|
|
$self->deleteCasSession($casServiceSession);
|
|
|
|
return $self->returnCasValidateError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Open local session
|
2019-02-07 09:27:56 +01:00
|
|
|
my $localSession =
|
|
|
|
$self->p->getApacheSession( $casServiceSession->data->{_cas_id} );
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
unless ($localSession) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->warn( "Local session "
|
2019-02-07 09:27:56 +01:00
|
|
|
. $casServiceSession->data->{_cas_id}
|
|
|
|
. " notfound" );
|
2016-12-21 23:39:12 +01:00
|
|
|
$self->deleteCasSession($casServiceSession);
|
|
|
|
return $self->returnCasValidateError();
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get username
|
2019-04-25 20:35:41 +02:00
|
|
|
my $app = $casServiceSession->data->{_casApp};
|
|
|
|
my $username_attribute =
|
|
|
|
( $app
|
|
|
|
and $self->conf->{casAppMetaDataOptions}->{$app}
|
|
|
|
->{casAppMetaDataOptionsUserAttribute} )
|
|
|
|
? $self->conf->{casAppMetaDataOptions}->{$app}
|
|
|
|
->{casAppMetaDataOptionsUserAttribute}
|
|
|
|
: ( $self->conf->{casAttr}
|
|
|
|
|| $self->conf->{whatToTrace} );
|
|
|
|
|
|
|
|
my $username = $localSession->data->{$username_attribute};
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Get username $username");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# Return success message
|
|
|
|
$self->deleteCasSession($casServiceSession);
|
2019-04-28 19:29:54 +02:00
|
|
|
return $self->returnCasValidateSuccess( $req, $username );
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub proxy {
|
|
|
|
my ( $self, $req ) = @_;
|
2018-05-14 12:15:26 +02:00
|
|
|
|
|
|
|
$self->logger->debug(
|
|
|
|
'URL ' . $req->uri . " detected as an CAS PROXY URL" );
|
|
|
|
|
|
|
|
# GET parameters
|
|
|
|
my $pgt = $req->param('pgt');
|
|
|
|
my $targetService = $req->param('targetService');
|
|
|
|
|
|
|
|
# Required parameters: pgt and targetService
|
|
|
|
unless ( $pgt and $targetService ) {
|
|
|
|
$self->logger->error("Pgt and TargetService parameters required");
|
|
|
|
$self->returnCasProxyError( $req, 'INVALID_REQUEST',
|
|
|
|
'Missing mandatory parameters (pgt, targetService)' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->logger->debug(
|
|
|
|
"Get proxy request with ticket $pgt for service $targetService");
|
|
|
|
|
|
|
|
# Get CAS session corresponding to ticket
|
|
|
|
unless ( $pgt =~ s/^PGT-// ) {
|
|
|
|
$self->logger->error(
|
|
|
|
"Provided ticket is not a proxy granting ticket (PGT)");
|
|
|
|
$self->returnCasProxyError( $req, 'BAD_PGT',
|
|
|
|
'Provided ticket is not a proxy granting ticket' );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $casProxyGrantingSession = $self->getCasSession($pgt);
|
|
|
|
|
|
|
|
unless ($casProxyGrantingSession) {
|
|
|
|
$self->logger->error("Proxy granting ticket session $pgt not found");
|
|
|
|
$self->returnCasProxyError( $req, 'BAD_PGT', 'Ticket not found' );
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->logger->debug("Proxy granting session $pgt found");
|
|
|
|
|
|
|
|
# Create a proxy ticket
|
|
|
|
$self->logger->debug(
|
|
|
|
"Create a CAS proxy ticket for service $targetService");
|
|
|
|
|
|
|
|
my $casProxySession = $self->getCasSession();
|
|
|
|
|
|
|
|
unless ($casProxySession) {
|
|
|
|
$self->logger->error("Unable to create CAS proxy session");
|
|
|
|
$self->returnCasProxyError( $req, 'INTERNAL_ERROR',
|
|
|
|
'Error in proxy session management' );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $Pinfos;
|
|
|
|
$Pinfos->{type} = 'casProxy';
|
|
|
|
$Pinfos->{service} = $targetService;
|
|
|
|
$Pinfos->{_cas_id} = $casProxyGrantingSession->data->{_cas_id};
|
|
|
|
$Pinfos->{_utime} = $casProxyGrantingSession->data->{_utime};
|
|
|
|
$Pinfos->{proxies} = $casProxyGrantingSession->data->{proxies};
|
|
|
|
|
|
|
|
$casProxySession->update($Pinfos);
|
|
|
|
|
|
|
|
my $casProxySessionID = $casProxySession->id;
|
|
|
|
my $casProxyTicket = "PT-" . $casProxySessionID;
|
|
|
|
|
|
|
|
$self->logger->debug("CAS proxy session $casProxySessionID created");
|
|
|
|
|
|
|
|
return $self->returnCasProxySuccess( $req, $casProxyTicket );
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub serviceValidate {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
return $self->_validate2( 'SERVICE', $req );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub proxyValidate {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
return $self->_validate2( 'PROXY', $req );
|
|
|
|
}
|
|
|
|
|
|
|
|
# INTERNAL METHODS
|
|
|
|
|
|
|
|
sub _validate2 {
|
|
|
|
my ( $self, $urlType, $req ) = @_;
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
'URL ' . $req->uri . " detected as an CAS $urlType VALIDATE URL" );
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# GET parameters
|
|
|
|
my $service = $req->param('service');
|
|
|
|
my $ticket = $req->param('ticket');
|
|
|
|
my $pgtUrl = $req->param('pgtUrl');
|
2016-12-22 06:57:44 +01:00
|
|
|
my $renew = $req->param('renew') // 'false';
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# PGTIOU
|
|
|
|
my $casProxyGrantingTicketIOU;
|
|
|
|
|
|
|
|
# Required parameters: service and ticket
|
|
|
|
unless ( $service and $ticket ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Service and Ticket parameters required");
|
2018-10-29 08:10:01 +01:00
|
|
|
return $self->returnCasServiceValidateError( $req, 'INVALID_REQUEST',
|
2016-12-21 23:39:12 +01:00
|
|
|
'Missing mandatory parameters (service, ticket)' );
|
|
|
|
}
|
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug( "Get "
|
2019-02-07 09:27:56 +01:00
|
|
|
. lc($urlType)
|
|
|
|
. " validate request with ticket $ticket for service $service" );
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# Get CAS session corresponding to ticket
|
|
|
|
if ( $urlType eq 'SERVICE' and !( $ticket =~ s/^ST-// ) ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Provided ticket is not a service ticket (ST)");
|
2018-10-29 08:10:01 +01:00
|
|
|
return $self->returnCasServiceValidateError( $req, 'INVALID_TICKET',
|
2016-12-21 23:39:12 +01:00
|
|
|
'Provided ticket is not a service ticket' );
|
|
|
|
}
|
|
|
|
elsif ( $urlType eq 'PROXY' and !( $ticket =~ s/^(P|S)T-// ) ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->userLogger->error(
|
|
|
|
"Provided ticket is not a service or proxy ticket ($1T)");
|
2018-10-29 08:10:01 +01:00
|
|
|
return $self->returnCasServiceValidateError( $req, 'INVALID_TICKET',
|
2016-12-21 23:39:12 +01:00
|
|
|
'Provided ticket is not a service or proxy ticket' );
|
|
|
|
}
|
|
|
|
|
|
|
|
my $casServiceSession = $self->getCasSession($ticket);
|
|
|
|
|
|
|
|
unless ($casServiceSession) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("$urlType ticket session $ticket not found");
|
2018-10-29 08:10:01 +01:00
|
|
|
return $self->returnCasServiceValidateError( $req, 'INVALID_TICKET',
|
2016-12-21 23:39:12 +01:00
|
|
|
'Ticket not found' );
|
|
|
|
}
|
2017-04-14 09:40:01 +02:00
|
|
|
my $app = $casServiceSession->data->{_casApp};
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("$urlType ticket session $ticket found");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
my $service1_uri = URI->new($service);
|
|
|
|
my $service2_uri = URI->new( $casServiceSession->data->{service} );
|
|
|
|
|
|
|
|
# Check service
|
|
|
|
unless ( $service1_uri->eq($service2_uri) ) {
|
|
|
|
|
|
|
|
# Tolerate that relative URI are the same
|
|
|
|
if ( $service1_uri->rel($service2_uri) eq "./"
|
|
|
|
or $service2_uri->rel($service1_uri) eq "./" )
|
|
|
|
{
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->notice(
|
2019-02-07 09:27:56 +01:00
|
|
|
"Submitted service $service1_uri does not exactly match initial service "
|
|
|
|
. $service2_uri
|
|
|
|
. ' but difference is tolerated.' );
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->userLogger->error(
|
2016-12-21 23:39:12 +01:00
|
|
|
"Submitted service $service does not match initial service "
|
2019-02-07 09:27:56 +01:00
|
|
|
. $casServiceSession->data->{service} );
|
2016-12-21 23:39:12 +01:00
|
|
|
$self->deleteCasSession($casServiceSession);
|
2018-10-29 08:10:01 +01:00
|
|
|
return $self->returnCasServiceValidateError( $req,
|
|
|
|
'INVALID_SERVICE',
|
2016-12-21 23:39:12 +01:00
|
|
|
'Submitted service does not match initial service' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"Submitted service $service match initial service");
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check renew
|
2016-12-22 23:06:13 +01:00
|
|
|
if ( $renew and $renew eq 'true' ) {
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# We should check the ST was delivered with primary credentials
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Renew flag detected ");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
unless ( $casServiceSession->data->{renew} ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error(
|
2019-02-07 09:27:56 +01:00
|
|
|
"Authentication renew requested, but not done in former authentication process"
|
2016-12-21 23:39:12 +01:00
|
|
|
);
|
|
|
|
$self->deleteCasSession($casServiceSession);
|
|
|
|
return $self->returnCasValidateError();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Proxies (for PROXY VALIDATE only)
|
|
|
|
my $proxies = $casServiceSession->data->{proxies};
|
|
|
|
|
|
|
|
# Proxy granting ticket
|
|
|
|
if ($pgtUrl) {
|
|
|
|
|
|
|
|
# Create a proxy granting ticket
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"Create a CAS proxy granting ticket for service $service");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-20 22:00:05 +01:00
|
|
|
my $PGinfos;
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-20 22:00:05 +01:00
|
|
|
# PGT session
|
|
|
|
$PGinfos->{type} = 'casProxyGranting';
|
|
|
|
$PGinfos->{service} = $service;
|
|
|
|
$PGinfos->{_cas_id} = $casServiceSession->data->{_cas_id};
|
|
|
|
$PGinfos->{_utime} = $casServiceSession->data->{_utime};
|
2017-04-14 09:40:01 +02:00
|
|
|
$PGinfos->{_casApp} = $app;
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-20 22:00:05 +01:00
|
|
|
# Trace proxies
|
|
|
|
$PGinfos->{proxies} = (
|
|
|
|
$proxies
|
2018-05-14 12:21:17 +02:00
|
|
|
? $proxies . $self->conf->{multiValuesSeparator} . $pgtUrl
|
2017-02-20 22:00:05 +01:00
|
|
|
: $pgtUrl
|
|
|
|
);
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-20 22:00:05 +01:00
|
|
|
my $casProxyGrantingSession = $self->getCasSession( undef, $PGinfos );
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-20 22:00:05 +01:00
|
|
|
if ($casProxyGrantingSession) {
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
my $casProxyGrantingSessionID = $casProxyGrantingSession->id;
|
2019-02-07 09:27:56 +01:00
|
|
|
my $casProxyGrantingTicket = "PGT-" . $casProxyGrantingSessionID;
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"CAS proxy granting session $casProxyGrantingSessionID created"
|
2016-12-21 23:39:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
# Generate the proxy granting ticket IOU
|
|
|
|
my $tmpCasSession = $self->getCasSession();
|
|
|
|
|
|
|
|
if ($tmpCasSession) {
|
|
|
|
|
|
|
|
$casProxyGrantingTicketIOU = "PGTIOU-" . $tmpCasSession->id;
|
|
|
|
$self->deleteCasSession($tmpCasSession);
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
2019-02-07 09:27:56 +01:00
|
|
|
"Generate proxy granting ticket IOU $casProxyGrantingTicketIOU"
|
2016-12-21 23:39:12 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
# Request pgtUrl
|
2019-02-07 09:27:56 +01:00
|
|
|
if (
|
|
|
|
$self->callPgtUrl(
|
2016-12-21 23:39:12 +01:00
|
|
|
$pgtUrl, $casProxyGrantingTicketIOU,
|
|
|
|
$casProxyGrantingTicket
|
|
|
|
)
|
2019-02-07 09:27:56 +01:00
|
|
|
)
|
2016-12-21 23:39:12 +01:00
|
|
|
{
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug(
|
|
|
|
"Proxy granting URL $pgtUrl called with success");
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error(
|
|
|
|
"Error calling proxy granting URL $pgtUrl");
|
2016-12-21 23:39:12 +01:00
|
|
|
$casProxyGrantingTicketIOU = undef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->warn(
|
|
|
|
"Error in proxy granting ticket management, bypass it");
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Open local session
|
2019-02-07 09:27:56 +01:00
|
|
|
my $localSession =
|
|
|
|
$self->p->getApacheSession( $casServiceSession->data->{_cas_id} );
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
unless ($localSession) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->userLogger->error( "Local session "
|
2019-02-07 09:27:56 +01:00
|
|
|
. $casServiceSession->data->{_cas_id}
|
|
|
|
. " notfound" );
|
2016-12-21 23:39:12 +01:00
|
|
|
$self->deleteCasSession($casServiceSession);
|
2018-10-29 08:10:01 +01:00
|
|
|
return $self->returnCasServiceValidateError( $req, 'INTERNAL_ERROR',
|
2016-12-21 23:39:12 +01:00
|
|
|
'No session associated to ticket' );
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get username
|
2019-04-25 20:35:41 +02:00
|
|
|
my $username_attribute =
|
|
|
|
( $app
|
|
|
|
and $self->conf->{casAppMetaDataOptions}->{$app}
|
|
|
|
->{casAppMetaDataOptionsUserAttribute} )
|
|
|
|
? $self->conf->{casAppMetaDataOptions}->{$app}
|
|
|
|
->{casAppMetaDataOptionsUserAttribute}
|
|
|
|
: ( $self->conf->{casAttr}
|
|
|
|
|| $self->conf->{whatToTrace} );
|
|
|
|
|
|
|
|
my $username = $localSession->data->{$username_attribute};
|
2016-12-21 23:39:12 +01:00
|
|
|
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug("Get username $username");
|
2016-12-21 23:39:12 +01:00
|
|
|
|
|
|
|
# Get attributes [CAS 3.0]
|
|
|
|
my $attributes = {};
|
2019-02-07 09:27:56 +01:00
|
|
|
my $ev =
|
|
|
|
( $app and $self->conf->{casAppMetaDataExportedVars}->{$app} )
|
|
|
|
? $self->conf->{casAppMetaDataExportedVars}->{$app}
|
|
|
|
: {};
|
2017-04-14 09:40:01 +02:00
|
|
|
unless (%$ev) {
|
|
|
|
$ev = $self->conf->{casAttributes} || {};
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $casAttribute ( keys %$ev ) {
|
2019-10-22 18:52:04 +02:00
|
|
|
my $sessionAttr = $ev->{$casAttribute};
|
|
|
|
my $value;
|
|
|
|
|
|
|
|
# Lookup per-service macros first, and then local sessions
|
|
|
|
#
|
|
|
|
if ( $app and $self->spMacros->{$app}->{$sessionAttr} ) {
|
|
|
|
$value = $self->spMacros->{$app}->{$sessionAttr}
|
|
|
|
->( $req, $localSession->data );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$value = $localSession->data->{$sessionAttr};
|
|
|
|
}
|
|
|
|
|
|
|
|
$attributes->{$casAttribute} = $value
|
|
|
|
if defined $value;
|
2016-12-21 23:39:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Return success message
|
|
|
|
$self->deleteCasSession($casServiceSession);
|
2016-12-22 06:57:44 +01:00
|
|
|
return $self->returnCasServiceValidateSuccess( $req, $username,
|
2016-12-21 23:39:12 +01:00
|
|
|
$casProxyGrantingTicketIOU, $proxies, $attributes );
|
|
|
|
}
|
|
|
|
|
2016-12-20 13:19:26 +01:00
|
|
|
1;
|