Commit bead38b6 authored by Xavier Guimard's avatar Xavier Guimard

CDA included in Simple.pm

parent cb10ec49
......@@ -32,6 +32,11 @@ __PACKAGE__->init(
# You can also fix the port (for redirections after authentications)
#port => 80,
# CROSS-DOMAIN
# If your handler is not on the same domain than the portal, uncomment
# this (and don't forget to set "cda => 1" in the portal
#cda => 1,
# CUSTOM FUNCTION
# If you want to create customFunctions in rules, declare them here:
#customFunctions => 'function1 function2',
......
......@@ -13,43 +13,14 @@ our $VERSION = '0.2';
use base qw(Lemonldap::NG::Handler::SharedConf);
*EXPORT_TAGS = *Lemonldap::NG::Handler::SharedConf::EXPORT_TAGS;
*EXPORT_OK = *Lemonldap::NG::Handler::SharedConf::EXPORT_OK;
## @rmethod int run(Apache2::RequestRec apacheRequest)
# overload run subroutine to implement cross-domain mechanism.
# @param $apacheRequest
# @return Apache constant
sub run ($$) {
my $class;
( $class, $apacheRequest ) = @_;
my $args = $apacheRequest->args;
if ( $args =~ s/[\?&]?($cookieName=\w+)$//oi ) {
my $str = $1;
$class->lmLog(
"Found a CDA id. Redirecting "
. $apacheRequest->connection->remote_ip
. " to myself with new cookie",
'debug'
);
$apacheRequest->args($args);
my $host = $apacheRequest->get_server_name();
my $portString = $port || $apacheRequest->get_server_port();
lmSetErrHeaderOut( $apacheRequest,
'Location' => "http"
. ( $https ? 's' : '' )
. "://$host:$portString"
. $apacheRequest->uri
. ( $apacheRequest->args ? "?" . $apacheRequest->args : "" ) );
$host =~ s/^[^\.]+\.(.*\..*$)/$1/;
lmSetErrHeaderOut( $apacheRequest,
'Set-Cookie' => "$str; domain=$host; path=/"
. ( $https ? "; secure" : "" ) );
return REDIRECT;
}
else {
return $class->SUPER::run($apacheRequest);
}
$cda = 1;
return $class->SUPER::run($apacheRequest);
}
1;
......@@ -65,9 +36,10 @@ mechanisms with Cross-Domain-Authentication.
New usage:
package My::Package;
use Lemonldap::NG::Handler::CDA;
@ISA = qw(Lemonldap::NG::Handler::CDA);
use Lemonldap::NG::Handler;
@ISA = qw(Lemonldap::NG::Handler);
__PACKAGE__->init ( {
cda => 1,
localStorage => "Cache::FileCache",
localStorageOptions => {
'namespace' => 'MyNamespace',
......
......@@ -43,6 +43,7 @@ our (
$whatToTrace, $https, $refLocalStorage,
$safe, $port, $statusPipe,
$statusOut, $customFunctions, $transform,
$cda,
);
##########################################
......@@ -70,6 +71,7 @@ BEGIN {
traces => [qw( $whatToTrace $statusPipe $statusOut )],
apache => [qw( MP OK REDIRECT FORBIDDEN DONE DECLINED SERVER_ERROR )],
post => [qw($transform)],
cda => ['$cda'],
);
push( @EXPORT_OK, @{ $EXPORT_TAGS{$_} } ) foreach ( keys %EXPORT_TAGS );
$EXPORT_TAGS{all} = \@EXPORT_OK;
......@@ -559,6 +561,7 @@ sub defaultValuesInit {
$cookieName .= 'http' if ( $args->{securedCookie} == 2 and $https == 0 );
$port = $args->{port} || 0 unless defined($port);
$customFunctions = $args->{customFunctions};
$cda = $args->{cda} || 0;
1;
}
......@@ -861,8 +864,28 @@ sub run ($$) {
my $class;
( $class, $apacheRequest ) = @_;
return DECLINED unless ( $apacheRequest->is_initial_req );
my $uri = $apacheRequest->uri
. ( $apacheRequest->args ? "?" . $apacheRequest->args : "" );
my $args = $apacheRequest->args;
# Cross domain authentication
if ( $cda and $args =~ s/[\?&]?($cookieName=\w+)$//oi ) {
my $str = $1;
$class->lmLog( 'CDA request', 'debug' );
$apacheRequest->args($args);
my $host = $apacheRequest->get_server_name();
my $portString = $port || $apacheRequest->get_server_port();
lmSetErrHeaderOut( $apacheRequest,
'Location' => "http"
. ( $https ? 's' : '' )
. "://$host:$portString"
. $apacheRequest->uri
. ( $apacheRequest->args ? "?" . $apacheRequest->args : "" ) );
$host =~ s/^[^\.]+\.(.*\..*$)/$1/;
lmSetErrHeaderOut( $apacheRequest,
'Set-Cookie' => "$str; domain=$host; path=/"
. ( $https ? "; secure" : "" ) );
return REDIRECT;
}
my $uri = $apacheRequest->uri . ( $args ? "?$args" : "" );
# AUTHENTICATION
# I - recover the cookie
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment