Commit d51877a4 authored by Christophe Maudoux's avatar Christophe Maudoux 🐛
Browse files

Code refactoring

parent f378c863
......@@ -2,11 +2,18 @@ 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;
use Lemonldap::NG::Common::Session;
use Lemonldap::NG::Portal::Main::Constants qw(
URIRE
PE_OK
PE_ERROR
PE_REDIRECT
);
our $VERSION = '2.0.14';
our $VERSION = '2.0.0';
has cookieName => ( is => 'rw' );
# INITIALIZATION
......@@ -20,29 +27,37 @@ sub init {
$self->error( "Missing required parameters" . join( ', ', @missing ) );
return 0;
}
unless ( $self->conf->{remotePortal} =~ URIRE ) {
$self->error("Bad remotePortal URL");
return 0;
}
eval "require " . $self->conf->{remoteGlobalStorage};
if ($@) {
$self->error($@);
return 0;
}
$self->conf->{remoteCookieName} ||= $self->conf->{cookieName};
$self->cookieName( $self->conf->{remoteCookieName}
|| $self->conf->{cookieName} );
return 1;
}
# RUNNING METHODS
## @apmethod int checkRemoteId()
# check if a CDA mechanism has been instantiated and if session is available.
# Redirect the user to the remote portal else by calling goToPortal().
# Redirect user to 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} ) ) {
if ( my $rId = $req->param( $self->cookieName ) ) {
$req->mustRedirect(1);
# Trying to recover session from global session storage
my $remoteSession = Lemonldap::NG::Common::Session->new( {
storageModule => $self->conf->{remoteGlobalStorage},
storageModuleOptions =>
......@@ -53,7 +68,6 @@ sub checkRemoteId {
kind => "SSO",
}
);
if ( $remoteSession->error ) {
$self->logger->error("Remote session error");
$self->logger->error( $remoteSession->error );
......@@ -62,24 +76,26 @@ sub checkRemoteId {
%{ $req->data->{rSessionInfo} } = %{ $remoteSession->data() };
delete( $req->data->{rSessionInfo}->{'_password'} )
unless ( $self->conf->{storePassword} );
unless $self->conf->{storePassword};
return PE_OK;
}
return $self->goToPortal($req);
}
## @method protected void goToPortal()
# Redirect the user to the remote portal.
# Redirect user to remote portal.
sub goToPortal {
my ( $self, $req ) = @_;
$req->urldc(
$self->conf->{remotePortal} . "?url="
$self->conf->{remotePortal} . '?url='
. encode_base64(
$self->conf->{portal}
. ( $req->query_string ? '?' . $req->query_string : '' ),
''
)
);
return PE_REDIRECT;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment