lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Proxy.pm

90 lines
2.5 KiB
Perl
Raw Normal View History

2016-06-09 20:40:20 +02:00
# Auth/Proxy.pm and UserDB/Proxy.pm simple inheritance of this package
2016-06-06 22:49:59 +02:00
package Lemonldap::NG::Portal::Lib::Proxy;
use strict;
use Mouse;
2016-06-07 23:04:24 +02:00
use SOAP::Lite;
2016-06-06 22:49:59 +02:00
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
our $VERSION = '2.0.0';
2016-06-09 20:40:20 +02:00
# INITIALIZATION
2016-06-06 22:49:59 +02:00
sub init {
my ($self) = @_;
$self->conf->{soapSessionService} ||=
$self->conf->{soapAuthService} . 'index.pl/sessions';
$self->conf->{soapSessionService} =~ s/\.plindex.pl/\.pl/;
$self->conf->{remoteCookieName} ||= $self->conf->{cookieName};
unless ( defined $self->conf->{soapAuthService} ) {
$self->error("Missing soapAuthService parameter");
return 0;
}
return 1;
}
2016-06-09 20:40:20 +02:00
# RUNNING METHODS
2016-06-09 13:45:06 +02:00
*authenticate = *getUser;
sub getUser {
2016-06-06 22:49:59 +02:00
my ( $self, $req ) = @_;
return PE_OK if ( $req->datas->{_proxyQueryDone} );
2016-06-07 23:04:24 +02:00
my $soap = SOAP::Lite->proxy( $self->conf->{soapSessionService} )
2016-06-06 22:49:59 +02:00
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
2016-06-07 23:04:24 +02:00
my $r = $soap->getCookies( $req->{user}, $req->datas->{password} );
2016-06-06 22:49:59 +02:00
if ( $r->fault ) {
2016-06-07 23:04:24 +02:00
$self->lmLog(
2016-06-06 22:49:59 +02:00
"Unable to query authentication service: "
. $r->fault->{faultstring},
'error'
);
return PE_ERROR;
}
my $res = $r->result();
# If authentication failed, display error
2016-06-07 23:04:24 +02:00
if ( $res->{errorCode} ) {
$self->p->userError(
"Authentication failed for $req->{user}: error $res->{errorCode}");
2016-06-06 22:49:59 +02:00
return PE_BADCREDENTIALS;
}
unless ( $req->datas->{_remoteId} =
$res->{cookies}->{ $self->conf->{remoteCookieName} } )
{
$self->lmLog( "No cookie named $self->{remoteCookieName}", 'error' );
return PE_ERROR;
}
$req->datas->{_proxyQueryDone}++;
PE_OK;
}
sub setSessionInfo {
my ( $self, $req ) = @_;
return PE_OK if ( $req->datas->{_setSessionInfoDone} );
my $soap =
SOAP::Lite->proxy( $self->conf->{soapSessionService} )
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
my $r = $soap->getAttributes( $req->datas->{_remoteId} );
if ( $r->fault ) {
$self->lmLog(
"Unable to query authentication service" . $r->fault->{faultstring},
'error'
);
}
my $res = $r->result();
if ( $res->{error} ) {
$self->userError("Unable to get attributes for $self->{user} ");
return PE_ERROR;
}
foreach ( keys %{ $res->{attributes} } ) {
$req->{sessionInfo}->{$_} ||= $res->{attributes}->{$_}
unless (/^_/);
}
$req->datas->{_setSessionInfoDone}++;
PE_OK;
}
1;