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

92 lines
2.4 KiB
Perl
Raw Normal View History

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 ) {
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} );
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 ) {
$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;
}
2017-01-10 17:09:28 +01:00
sub authLogout {
PE_OK;
}
2016-06-06 22:49:59 +02:00
1;