2016-05-26 23:26:49 +02:00
|
|
|
package Lemonldap::NG::Portal::Lib::Remote;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
|
|
|
use Lemonldap::NG::Common::Session;
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_REDIRECT);
|
|
|
|
use MIME::Base64;
|
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
2016-06-09 20:40:20 +02:00
|
|
|
# INITIALIZATION
|
|
|
|
|
2016-05-26 23:26:49 +02:00
|
|
|
sub init {
|
|
|
|
my $self = shift;
|
|
|
|
my @missing = ();
|
|
|
|
foreach (qw(remotePortal remoteGlobalStorage)) {
|
|
|
|
push @missing, $_ unless ( defined( $self->conf->{$_} ) );
|
|
|
|
}
|
|
|
|
if (@missing) {
|
|
|
|
$self->error( "Missing required parameters" . join( ', ', @missing ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
eval "require " . $self->conf->{remoteGlobalStorage};
|
|
|
|
if ($@) {
|
|
|
|
$self->error($@);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
$self->conf->{remoteCookieName} ||= $self->conf->{cookieName};
|
|
|
|
}
|
|
|
|
|
2016-06-09 20:40:20 +02:00
|
|
|
# RUNNING METHODS
|
|
|
|
|
2016-05-26 23:26:49 +02:00
|
|
|
## @apmethod int checkRemoteId()
|
2016-12-19 21:47:44 +01:00
|
|
|
# check if a CDA mechanism has been instantiated and if session is available.
|
2016-05-26 23:26:49 +02:00
|
|
|
# Redirect the user to the remote portal else by calling goToPortal().
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
sub checkRemoteId {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my %h;
|
|
|
|
|
|
|
|
if ( my $rId = $req->param( $self->conf->{remoteCookieName} ) ) {
|
|
|
|
$req->mustRedirect(1);
|
|
|
|
|
|
|
|
# Trying to recover session from global session storage
|
|
|
|
|
|
|
|
my $remoteSession = Lemonldap::NG::Common::Session->new(
|
|
|
|
{
|
|
|
|
storageModule => $self->conf->{remoteGlobalStorage},
|
|
|
|
storageModuleOptions =>
|
|
|
|
$self->conf->{remoteGlobalStorageOptions},
|
|
|
|
cacheModule => $self->conf->{localSessionStorage},
|
|
|
|
cacheModuleOptions => $self->conf->{localSessionStorageOptions},
|
|
|
|
id => $rId,
|
|
|
|
kind => "REMOTE",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( $remoteSession->error ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("Remote session error");
|
|
|
|
$self->logger->error( $remoteSession->error );
|
2016-05-26 23:26:49 +02:00
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
%{ $req->datas->{rSessionInfo} } = %{ $remoteSession->data() };
|
|
|
|
delete( $req->datas->{rSessionInfo}->{'_password'} )
|
|
|
|
unless ( $self->conf->{storePassword} );
|
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
return $self->goToPortal($req);
|
|
|
|
}
|
|
|
|
|
|
|
|
## @method protected void goToPortal()
|
|
|
|
# Redirect the user to the remote portal.
|
|
|
|
sub goToPortal {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
$req->urldc(
|
|
|
|
$self->conf->{remotePortal} . "?url="
|
|
|
|
. encode_base64(
|
2017-01-04 17:36:54 +01:00
|
|
|
$self->conf->{portal}
|
|
|
|
. ( $req->query_string ? '?' . $req->query_string : '' ),
|
|
|
|
''
|
2016-05-26 23:26:49 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
return PE_REDIRECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|