2017-01-09 07:11:30 +01:00
|
|
|
package Lemonldap::NG::Portal::Lib::SOAPProxy;
|
2016-06-06 22:49:59 +02:00
|
|
|
|
|
|
|
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) = @_;
|
2017-01-10 13:25:30 +01:00
|
|
|
$self->conf->{remoteCookieName} ||= $self->conf->{cookieName};
|
|
|
|
$self->conf->{proxySessionService} ||= $self->conf->{proxyAuthService};
|
2016-06-06 22:49:59 +02:00
|
|
|
|
2017-01-09 07:11:30 +01:00
|
|
|
unless ( defined $self->conf->{proxyAuthService} ) {
|
|
|
|
$self->error("Missing proxyAuthService parameter");
|
2016-06-06 22:49:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-06-09 20:40:20 +02:00
|
|
|
# RUNNING METHODS
|
|
|
|
|
2017-01-10 13:25:30 +01:00
|
|
|
no warnings 'once';
|
|
|
|
|
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} );
|
2017-01-09 07:11:30 +01:00
|
|
|
my $soap = SOAP::Lite->proxy( $self->conf->{proxyAuthService} )
|
2017-01-07 21:37:07 +01:00
|
|
|
->uri('urn:Lemonldap/NG/Common/PSGI/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 ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error( "Unable to query authentication service: "
|
|
|
|
. $r->fault->{faultstring} );
|
2016-06-06 22:49:59 +02:00
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
my $res = $r->result();
|
|
|
|
|
|
|
|
# If authentication failed, display error
|
2016-06-07 23:04:24 +02:00
|
|
|
if ( $res->{errorCode} ) {
|
2017-02-15 15:16:59 +01:00
|
|
|
$self->userLogger->warn(
|
2016-06-07 23:04:24 +02:00
|
|
|
"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} } )
|
|
|
|
{
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("No cookie named $self->{remoteCookieName}");
|
2016-06-06 22:49:59 +02:00
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
$req->datas->{_proxyQueryDone}++;
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setSessionInfo {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
return PE_OK if ( $req->datas->{_setSessionInfoDone} );
|
2017-01-10 13:25:30 +01:00
|
|
|
my $soap = SOAP::Lite->proxy( $self->conf->{proxySessionService} )
|
2017-01-07 21:37:07 +01:00
|
|
|
->uri('urn:Lemonldap/NG/Common/PSGI/SOAPService');
|
2016-06-06 22:49:59 +02:00
|
|
|
my $r = $soap->getAttributes( $req->datas->{_remoteId} );
|
|
|
|
if ( $r->fault ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error( "Unable to query authentication service"
|
|
|
|
. $r->fault->{faultstring} );
|
2016-06-06 22:49:59 +02:00
|
|
|
}
|
|
|
|
my $res = $r->result();
|
|
|
|
if ( $res->{error} ) {
|
2017-02-15 15:16:59 +01:00
|
|
|
$self->userLogger->warn("Unable to get attributes for $self->{user} ");
|
2016-06-06 22:49:59 +02:00
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
foreach ( keys %{ $res->{attributes} } ) {
|
|
|
|
$req->{sessionInfo}->{$_} ||= $res->{attributes}->{$_}
|
|
|
|
unless (/^_/);
|
|
|
|
}
|
|
|
|
$req->datas->{_setSessionInfoDone}++;
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-10 17:09:28 +01:00
|
|
|
sub authLogout {
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-06 22:49:59 +02:00
|
|
|
1;
|