82 lines
2.4 KiB
Perl
82 lines
2.4 KiB
Perl
![]() |
package Lemonldap::NG::Portal::Lib::Proxy;
|
||
|
|
||
|
use strict;
|
||
|
use Mouse;
|
||
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
|
||
|
|
||
|
our $VERSION = '2.0.0';
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
sub proxyQuery {
|
||
|
my ( $self, $req ) = @_;
|
||
|
return PE_OK if ( $req->datas->{_proxyQueryDone} );
|
||
|
my $soap = SOAP::Lite->proxy( $self->conf->{soapAuthService} )
|
||
|
->uri('urn:Lemonldap::NG::Common::CGI::SOAPService');
|
||
|
my $r = $soap->getCookies( $self->{user}, $self->{password} );
|
||
|
if ( $r->fault ) {
|
||
|
$req->lmLog(
|
||
|
"Unable to query authentication service: "
|
||
|
. $r->fault->{faultstring},
|
||
|
'error'
|
||
|
);
|
||
|
return PE_ERROR;
|
||
|
}
|
||
|
my $res = $r->result();
|
||
|
|
||
|
# If authentication failed, display error
|
||
|
if ( $res->{error} ) {
|
||
|
$self->userError( "Authentication failed for $self->{user}: "
|
||
|
. $soap->error( $res->{error} )->result() );
|
||
|
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;
|