2009-09-23 14:42:34 +02:00
|
|
|
## @file
|
2009-09-27 09:54:05 +02:00
|
|
|
# Proxy authentication and userDB base.
|
2009-09-23 14:42:34 +02:00
|
|
|
|
|
|
|
## @class
|
2009-09-27 09:54:05 +02:00
|
|
|
# Proxy authentication and userDB base class.
|
|
|
|
package Lemonldap::NG::Portal::_Proxy;
|
2009-09-23 14:42:34 +02:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Lemonldap::NG::Portal::Simple;
|
|
|
|
use MIME::Base64;
|
|
|
|
use SOAP::Lite;
|
|
|
|
|
2010-11-20 16:05:40 +01:00
|
|
|
our $VERSION = '1.0.0';
|
2010-09-23 17:09:27 +02:00
|
|
|
our $initDone;
|
2009-09-23 14:42:34 +02:00
|
|
|
|
2010-10-30 21:25:38 +02:00
|
|
|
BEGIN {
|
|
|
|
eval {
|
|
|
|
require threads::shared;
|
|
|
|
threads::shared::share($initDone);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-09-27 09:54:05 +02:00
|
|
|
## @apmethod int proxyInit()
|
2009-09-23 14:42:34 +02:00
|
|
|
# Checks if remote portal parameters are set.
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
2009-09-27 09:54:05 +02:00
|
|
|
sub proxyInit {
|
2009-09-23 14:42:34 +02:00
|
|
|
my $self = shift;
|
|
|
|
$self->{soapSessionService} ||=
|
|
|
|
$self->{soapAuthService} . 'index.pl/sessions';
|
|
|
|
$self->{soapSessionService} =~ s/\.plindex.pl/\.pl/;
|
|
|
|
$self->{remoteCookieName} ||= $self->{cookieName};
|
2010-09-23 17:09:27 +02:00
|
|
|
|
|
|
|
return PE_OK if ($initDone);
|
|
|
|
|
|
|
|
my @missing = ();
|
|
|
|
foreach (qw(soapAuthService)) {
|
|
|
|
push @missing, $_ unless ( defined( $self->{$_} ) );
|
|
|
|
}
|
2009-09-23 14:42:34 +02:00
|
|
|
$self->abort( "Missing parameters",
|
|
|
|
"Required parameters: " . join( ', ', @missing ) )
|
|
|
|
if (@missing);
|
2010-09-23 17:09:27 +02:00
|
|
|
$initDone = 1;
|
2009-09-23 14:42:34 +02:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-27 09:54:05 +02:00
|
|
|
## @apmethod int proxyQuery()
|
2009-09-23 14:42:34 +02:00
|
|
|
# Queries the remote portal to authenticate users using given credentials
|
2009-09-27 09:54:05 +02:00
|
|
|
sub proxyQuery {
|
2009-09-23 14:42:34 +02:00
|
|
|
my $self = shift;
|
2009-09-27 09:54:05 +02:00
|
|
|
return PE_OK if ( $self->{_proxyQueryDone} );
|
2009-09-23 14:42:34 +02:00
|
|
|
my $soap =
|
|
|
|
SOAP::Lite->proxy( $self->{soapAuthService} )
|
|
|
|
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
|
|
|
|
my $r = $soap->getCookies( $self->{user}, $self->{password} );
|
|
|
|
if ( $r->fault ) {
|
|
|
|
$self->abort( "Unable to query authentication service",
|
|
|
|
$r->fault->{faultstring} );
|
|
|
|
}
|
|
|
|
my $res = $r->result();
|
|
|
|
|
|
|
|
# If authentication failed, display error
|
|
|
|
if ( $res->{error} ) {
|
|
|
|
$self->_sub( 'userError',
|
|
|
|
"Authentication failed for $self->{user} "
|
|
|
|
. $soap->error( 'fr', $res->{error} )->result() );
|
|
|
|
return PE_BADCREDENTIALS;
|
|
|
|
}
|
2010-10-07 13:05:36 +02:00
|
|
|
$self->{_remoteId} = $res->{cookies}->{ $self->{remoteCookieName} }
|
2009-09-23 14:42:34 +02:00
|
|
|
or $self->abort("No cookie named $self->{remoteCookieName}");
|
2009-09-27 09:54:05 +02:00
|
|
|
$self->{_proxyQueryDone}++;
|
2009-09-23 14:42:34 +02:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
## @apmethod int setSessionInfo()
|
|
|
|
# Queries the remote portal to get users attributes and
|
|
|
|
# store them in local session
|
|
|
|
sub setSessionInfo {
|
|
|
|
my $self = shift;
|
|
|
|
return PE_OK if ( $self->{_setSessionInfoDone} );
|
|
|
|
my $soap =
|
|
|
|
SOAP::Lite->proxy( $self->{soapSessionService} )
|
|
|
|
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
|
2010-10-07 13:05:36 +02:00
|
|
|
my $r = $soap->getAttributes( $self->{_remoteId} );
|
2009-09-23 14:42:34 +02:00
|
|
|
if ( $r->fault ) {
|
|
|
|
$self->abort( "Unable to query authentication service",
|
|
|
|
$r->fault->{faultstring} );
|
|
|
|
}
|
|
|
|
my $res = $r->result();
|
|
|
|
if ( $res->{error} ) {
|
|
|
|
$self->_sub( 'userError',
|
|
|
|
"Unable to get attributes for $self->{user} " );
|
|
|
|
return PE_ERROR;
|
|
|
|
}
|
2009-09-23 15:35:19 +02:00
|
|
|
foreach ( keys %{ $res->{attributes} } ) {
|
2009-12-11 22:17:06 +01:00
|
|
|
$self->{sessionInfo}->{$_} ||= $res->{attributes}->{$_}
|
|
|
|
unless (/^_/);
|
2009-09-23 15:35:19 +02:00
|
|
|
}
|
2009-09-23 14:42:34 +02:00
|
|
|
$self->{_setSessionInfoDone}++;
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|