Commit 898b52ab authored by Clément OUDOT's avatar Clément OUDOT
Browse files

Show error from Common::Session module in logs (#LEMONLDAP-741)

git-svn-id: svn://svn.forge.objectweb.org/svnroot/lemonldap/branches/lemonldap-ng_version_1_4-bugfixes@3515 1dbb9719-a921-0410-b57f-c3a383c2c641
parent 881a62af
...@@ -58,6 +58,11 @@ has 'cacheModuleOptions' => ( ...@@ -58,6 +58,11 @@ has 'cacheModuleOptions' => (
isa => 'HashRef|Undef', isa => 'HashRef|Undef',
); );
has 'error' => (
is => 'rw',
isa => 'Str|Undef',
);
sub BUILD { sub BUILD {
my $self = shift; my $self = shift;
...@@ -128,7 +133,12 @@ sub _tie_session { ...@@ -128,7 +133,12 @@ sub _tie_session {
} }
}; };
return undef if ( $@ or not tied(%h) ); if ( $@ or not tied(%h) ) {
my $msg = "Session cannot be tied";
$msg .= ": $@" if $@;
$self->error($msg);
return undef;
}
return \%h; return \%h;
} }
...@@ -144,7 +154,10 @@ sub update { ...@@ -144,7 +154,10 @@ sub update {
my $self = shift; my $self = shift;
my $infos = shift; my $infos = shift;
return 0 unless ( ref $infos eq "HASH" ); unless ( ref $infos eq "HASH" ) {
$self->error("You need to provide a HASHREF");
return 0;
}
my $data = $self->_tie_session; my $data = $self->_tie_session;
...@@ -164,6 +177,7 @@ sub update { ...@@ -164,6 +177,7 @@ sub update {
return 1; return 1;
} }
$self->error("No data found in session");
return 0; return 0;
} }
...@@ -174,7 +188,11 @@ sub remove { ...@@ -174,7 +188,11 @@ sub remove {
eval { tied(%$data)->delete(); }; eval { tied(%$data)->delete(); };
return 0 if $@; if ($@) {
$self->error("Unable to delete session: $@");
return 0;
}
return 1; return 1;
} }
......
...@@ -18,7 +18,7 @@ use Lemonldap::NG::Handler::SharedConf qw(:all); ...@@ -18,7 +18,7 @@ use Lemonldap::NG::Handler::SharedConf qw(:all);
#link Lemonldap::NG::Handler::_CGI protected _handler #link Lemonldap::NG::Handler::_CGI protected _handler
our $VERSION = '1.2.3'; our $VERSION = '1.4.1';
## @cmethod Lemonldap::NG::Handler::CGI new(hashRef args) ## @cmethod Lemonldap::NG::Handler::CGI new(hashRef args)
# Constructor. # Constructor.
...@@ -116,9 +116,11 @@ sub authenticate { ...@@ -116,9 +116,11 @@ sub authenticate {
} }
); );
unless ( $apacheSession->data ) { if ( $apacheSession->error ) {
Lemonldap::NG::Handler::Main::Logger->lmLog( Lemonldap::NG::Handler::Main::Logger->lmLog(
"Session $id can't be retrieved", 'info' ); "Session $id can't be retrieved", 'info' );
Lemonldap::NG::Handler::Main::Logger->lmLog( $apacheSession->error,
'info' );
return $self->goToPortal(); return $self->goToPortal();
} }
......
...@@ -31,7 +31,7 @@ use constant MAINTENANCE_CODE => 503; ...@@ -31,7 +31,7 @@ use constant MAINTENANCE_CODE => 503;
#inherits Apache::Session #inherits Apache::Session
#link Lemonldap::NG::Common::Apache::Session::SOAP protected globalStorage #link Lemonldap::NG::Common::Apache::Session::SOAP protected globalStorage
our $VERSION = '1.4.0'; our $VERSION = '1.4.1';
our %EXPORT_TAGS; our %EXPORT_TAGS;
...@@ -204,7 +204,7 @@ sub updateStatus { ...@@ -204,7 +204,7 @@ sub updateStatus {
print $statusPipe "$user => " print $statusPipe "$user => "
. $apacheRequest->hostname . $apacheRequest->hostname
. "$url $action\n" . "$url $action\n"
if ( $statusPipe ); if ($statusPipe);
}; };
} }
...@@ -367,11 +367,21 @@ sub retrieveSession { ...@@ -367,11 +367,21 @@ sub retrieveSession {
} }
); );
if ( $datas = $apacheSession->data ) { unless ( $apacheSession->error ) {
$datas = $apacheSession->data;
# Update the session to notify activity, if necessary # Update the session to notify activity, if necessary
$apacheSession->update( { '_lastSeen' => time } ) if ( $tsv->{timeoutActivity} ) {
if ( $tsv->{timeoutActivity} ); $apacheSession->update( { '_lastSeen' => time } );
if ( $apacheSession->error ) {
Lemonldap::NG::Handler::Main::Logger->lmLog(
"Cannot update session $id", 'error' );
Lemonldap::NG::Handler::Main::Logger->lmLog(
$apacheSession->error, 'error' );
}
}
$datasUpdate = time(); $datasUpdate = time();
return 1; return 1;
...@@ -379,6 +389,9 @@ sub retrieveSession { ...@@ -379,6 +389,9 @@ sub retrieveSession {
else { else {
Lemonldap::NG::Handler::Main::Logger->lmLog( Lemonldap::NG::Handler::Main::Logger->lmLog(
"Session $id can't be retrieved", 'info' ); "Session $id can't be retrieved", 'info' );
Lemonldap::NG::Handler::Main::Logger->lmLog( $apacheSession->error,
'info' );
return 0; return 0;
} }
} }
...@@ -821,7 +834,7 @@ sub unlog ($$) { ...@@ -821,7 +834,7 @@ sub unlog ($$) {
sub status($$) { sub status($$) {
my ( $class, $r ) = splice @_; my ( $class, $r ) = splice @_;
my $statusOut = $tsv->{statusOut}; my $statusOut = $tsv->{statusOut};
my $statusPipe = $tsv->{statusPipe}; my $statusPipe = $tsv->{statusPipe};
Lemonldap::NG::Handler::Main::Logger->lmLog( "$class: request for status", Lemonldap::NG::Handler::Main::Logger->lmLog( "$class: request for status",
......
...@@ -23,7 +23,7 @@ use base qw(Lemonldap::NG::Handler::SharedConf); ...@@ -23,7 +23,7 @@ use base qw(Lemonldap::NG::Handler::SharedConf);
use utf8; use utf8;
no utf8; no utf8;
our $VERSION = '1.4.0'; our $VERSION = '1.4.1';
# We need just this constant, that's why Portal is 'required' but not 'used' # We need just this constant, that's why Portal is 'required' but not 'used'
*PE_OK = *Lemonldap::NG::Portal::SharedConf::PE_OK; *PE_OK = *Lemonldap::NG::Portal::SharedConf::PE_OK;
...@@ -144,9 +144,11 @@ sub run ($$) { ...@@ -144,9 +144,11 @@ sub run ($$) {
} }
); );
unless ( $apacheSession->data ) { if ( $apacheSession->error ) {
Lemonldap::NG::Handler::Main::Logger->lmLog( Lemonldap::NG::Handler::Main::Logger->lmLog(
"The cookie $session_id isn't yet available", 'info' ); "The cookie $session_id isn't yet available", 'info' );
Lemonldap::NG::Handler::Main::Logger->lmLog( $apacheSession->error,
'info' );
$class->updateStatus( $class->ip(), $apacheRequest->uri, $class->updateStatus( $class->ip(), $apacheRequest->uri,
'EXPIRED' ); 'EXPIRED' );
return $class->goToPortal($uri); return $class->goToPortal($uri);
......
...@@ -15,7 +15,7 @@ use Lemonldap::NG::Handler::Main::Headers; ...@@ -15,7 +15,7 @@ use Lemonldap::NG::Handler::Main::Headers;
use Lemonldap::NG::Handler::Main::Logger; use Lemonldap::NG::Handler::Main::Logger;
use Lemonldap::NG::Common::Session; use Lemonldap::NG::Common::Session;
our $VERSION = '1.4.0'; our $VERSION = '1.4.1';
## @rmethod int run(Apache2::RequestRec apacheRequest) ## @rmethod int run(Apache2::RequestRec apacheRequest)
# Main method used to control access. # Main method used to control access.
...@@ -59,9 +59,11 @@ sub run { ...@@ -59,9 +59,11 @@ sub run {
# Get session # Get session
else { else {
unless ( $apacheSession->data ) { if ( $apacheSession->error ) {
Lemonldap::NG::Handler::Main::Logger->lmLog( Lemonldap::NG::Handler::Main::Logger->lmLog(
"Session $id can't be retrieved", 'info' ); "Session $id can't be retrieved", 'info' );
Lemonldap::NG::Handler::Main::Logger->lmLog(
$apacheSession->error, 'info' );
} }
else { else {
$clear = 1 if ( $apacheSession->data->{_utime} lt $utime ); $clear = 1 if ( $apacheSession->data->{_utime} lt $utime );
......
...@@ -72,14 +72,6 @@ sub new { ...@@ -72,14 +72,6 @@ sub new {
# Load default skin if no other specified # Load default skin if no other specified
$self->{managerSkin} ||= 'default'; $self->{managerSkin} ||= 'default';
# Now try to load Apache::Session module
#unless ( $tsv->{globalStorage}->can('populate') ) {
# eval "require $tsv->{globalStorage}";
# $class->abort( "Unable to load $tsv->{globalStorage}", $@ ) if ($@);
#}
#%{ $self->{globalStorageOptions} } = %{$tsv->{globalStorageOptions}};
#$self->{globalStorageOptions}->{backend} = $tsv->{globalStorage};
# IP field # IP field
$self->{ipField} = "ipAddr"; $self->{ipField} = "ipAddr";
...@@ -376,8 +368,9 @@ sub delete { ...@@ -376,8 +368,9 @@ sub delete {
} }
); );
unless ( $apacheSession->data ) { if ( $apacheSession->error ) {
$self->lmLog( "Apache::Session error", 'error' ); $self->lmLog( "Unable to open session $id", 'error' );
$self->lmLog( $apacheSession->error, 'error' );
$res .= '<h1 class="ui-widget-header ui-corner-all">' $res .= '<h1 class="ui-widget-header ui-corner-all">'
. $self->translate('error') . '</h1>'; . $self->translate('error') . '</h1>';
$res .= '<div class="ui-corner-all ui-widget-content">'; $res .= '<div class="ui-corner-all ui-widget-content">';
...@@ -400,8 +393,15 @@ sub delete { ...@@ -400,8 +393,15 @@ sub delete {
} }
); );
if ( &apacheSession2->data ) { if ( $apacheSession2->data ) {
$apacheSession2->remove; unless ( $apacheSession2->remove ) {
$self->lmLog( "Unable to remove session $id2", 'error' );
$self->lmLog( $apacheSession2->error, 'error' );
}
}
else {
$self->lmLog( "Unable to open session $id2", 'error' );
$self->lmLog( $apacheSession2->error, 'error' );
} }
} }
...@@ -412,6 +412,7 @@ sub delete { ...@@ -412,6 +412,7 @@ sub delete {
} }
else { else {
$self->lmLog( "Unable to remove session $id", 'error' ); $self->lmLog( "Unable to remove session $id", 'error' );
$self->lmLog( $apacheSession->error, 'error' );
$res .= '<h1 class="ui-widget-header ui-corner-all">' $res .= '<h1 class="ui-widget-header ui-corner-all">'
. $self->translate('error') . '</h1>'; . $self->translate('error') . '</h1>';
$res .= '<div class="ui-corner-all ui-widget-content">'; $res .= '<div class="ui-corner-all ui-widget-content">';
...@@ -441,9 +442,9 @@ sub session { ...@@ -441,9 +442,9 @@ sub session {
} }
); );
unless ( $apacheSession->data ) { if ( $apacheSession->error ) {
$self->lmLog( "Unable to open session $id", 'error' );
$self->lmLog( "Apache::Session error", 'error' ); $self->lmLog( $apacheSession->error, 'error' );
$res .= '<h1 class="ui-widget-header ui-corner-all">' $res .= '<h1 class="ui-widget-header ui-corner-all">'
. $self->translate('error') . '</h1>'; . $self->translate('error') . '</h1>';
$res .= '<div class="ui-corner-all ui-widget-content">'; $res .= '<div class="ui-corner-all ui-widget-content">';
......
...@@ -71,7 +71,7 @@ use Digest::MD5; ...@@ -71,7 +71,7 @@ use Digest::MD5;
#inherits Apache::Session #inherits Apache::Session
#link Lemonldap::NG::Common::Apache::Session::SOAP protected globalStorage #link Lemonldap::NG::Common::Apache::Session::SOAP protected globalStorage
our $VERSION = '1.4.0'; our $VERSION = '1.4.1';
use base qw(Lemonldap::NG::Common::CGI Exporter); use base qw(Lemonldap::NG::Common::CGI Exporter);
our @ISA; our @ISA;
...@@ -850,7 +850,10 @@ sub getApacheSession { ...@@ -850,7 +850,10 @@ sub getApacheSession {
} }
); );
return unless $apacheSession->data; if ( $apacheSession->error ) {
$self->lmLog( $apacheSession->error, 'debug' );
return;
}
unless ($noInfo) { unless ($noInfo) {
$self->setApacheUser( $apacheSession->data->{ $self->{whatToTrace} } ) $self->setApacheUser( $apacheSession->data->{ $self->{whatToTrace} } )
...@@ -880,6 +883,10 @@ sub getPersistentSession { ...@@ -880,6 +883,10 @@ sub getPersistentSession {
} }
); );
if ( $persistentSession->error ) {
$self->lmLog( $persistentSession->error, 'debug' );
}
return $persistentSession; return $persistentSession;
} }
...@@ -916,6 +923,14 @@ sub updatePersistentSession { ...@@ -916,6 +923,14 @@ sub updatePersistentSession {
$self->getPersistentSession( $self->_md5hash($uid) ); $self->getPersistentSession( $self->_md5hash($uid) );
$persistentSession->update($infos); $persistentSession->update($infos);
if ( $persistentSession->error ) {
$self->lmLog(
"Cannot update persistent session " . $self->_md5hash($uid),
'error' );
$self->lmLog( $persistentSession->error, 'error' );
}
} }
## @method void updateSession(hashRef infos, string id) ## @method void updateSession(hashRef infos, string id)
...@@ -960,6 +975,11 @@ sub updateSession { ...@@ -960,6 +975,11 @@ sub updateSession {
# Store/update session values # Store/update session values
$apacheSession->update($infos); $apacheSession->update($infos);
if ( $apacheSession->error ) {
$self->lmLog( "Cannot update session $id", 'error' );
$self->lmLog( $apacheSession->error, 'error' );
}
} }
} }
} }
...@@ -1197,6 +1217,11 @@ sub _deleteSession { ...@@ -1197,6 +1217,11 @@ sub _deleteSession {
if ( my $id2 = $session->data->{_httpSession} ) { if ( my $id2 = $session->data->{_httpSession} ) {
if ( my $session2 = $self->getApacheSession( $id2, 1 ) ) { if ( my $session2 = $self->getApacheSession( $id2, 1 ) ) {
$session2->remove; $session2->remove;
if ( $session2->error ) {
$self->lmLog( "Unable to remove linked session $id2",
'debug' );
$self->lmLog( $session2->error, 'debug' );
}
} }
} }
...@@ -1232,7 +1257,7 @@ sub _deleteSession { ...@@ -1232,7 +1257,7 @@ sub _deleteSession {
$self->_sub( 'userNotice', "User $user has been disconnected" ) $self->_sub( 'userNotice', "User $user has been disconnected" )
if $user; if $user;
return 1; return $session->error ? 0 : 1;
} }
##@method private void _dump(void* variable) ##@method private void _dump(void* variable)
...@@ -1571,6 +1596,7 @@ sub controlExistingSession { ...@@ -1571,6 +1596,7 @@ sub controlExistingSession {
# Delete session # Delete session
unless ( $self->_deleteSession($apacheSession) ) { unless ( $self->_deleteSession($apacheSession) ) {
$self->lmLog( "Unable to delete session $id", 'error' ); $self->lmLog( "Unable to delete session $id", 'error' );
$self->lmLog( $apacheSession->error, 'error' );
return PE_ERROR; return PE_ERROR;
} }
else { else {
......
...@@ -10,7 +10,7 @@ use Lemonldap::NG::Portal::_Browser; ...@@ -10,7 +10,7 @@ use Lemonldap::NG::Portal::_Browser;
use Lemonldap::NG::Common::Session; use Lemonldap::NG::Common::Session;
our @ISA = (qw(Lemonldap::NG::Portal::_Browser)); our @ISA = (qw(Lemonldap::NG::Portal::_Browser));
our $VERSION = '1.4.0'; our $VERSION = '1.4.1';
## @method hashref getCasSession(string id) ## @method hashref getCasSession(string id)
# Try to recover the CAS session corresponding to id and return session datas # Try to recover the CAS session corresponding to id and return session datas
...@@ -31,12 +31,13 @@ sub getCasSession { ...@@ -31,12 +31,13 @@ sub getCasSession {
} }
); );
unless ( $casSession->data ) { if ( $casSession->error ) {
if ($id) { if ($id) {
$self->_sub( 'userInfo', "CAS session $id isn't yet available" ); $self->_sub( 'userInfo', "CAS session $id isn't yet available" );
} }
else { else {
$self->lmLog( "Unable to create new CAS session", 'error' ); $self->lmLog( "Unable to create new CAS session", 'error' );
$self->lmLog( $casSession->error, 'error' );
} }
return undef; return undef;
} }
...@@ -228,7 +229,10 @@ sub deleteCasSession { ...@@ -228,7 +229,10 @@ sub deleteCasSession {
my $session_id = $session->id; my $session_id = $session->id;
# Delete session # Delete session
$session->remove; unless ( $session->remove ) {
$self->lmLog( $session->error, 'error' );
return 0;
}
$self->lmLog( "CAS session $session_id deleted", 'debug' ); $self->lmLog( "CAS session $session_id deleted", 'debug' );
......
...@@ -10,7 +10,7 @@ use Lemonldap::NG::Portal::Simple; ...@@ -10,7 +10,7 @@ use Lemonldap::NG::Portal::Simple;
use Lemonldap::NG::Common::Session; use Lemonldap::NG::Common::Session;
use MIME::Base64; use MIME::Base64;
our $VERSION = '1.4.0'; our $VERSION = '1.4.1';
our $initDone; our $initDone;
BEGIN { BEGIN {
...@@ -68,8 +68,9 @@ sub checkRemoteId { ...@@ -68,8 +68,9 @@ sub checkRemoteId {
} }
); );
unless ( $remoteSession->data ) { if ( $remoteSession->error ) {
$self->lmLog( "Remote session error", 'error' ); $self->lmLog( "Remote session error", 'error' );
$self->lmLog( $remoteSession->error, 'error' );
return PE_ERROR; return PE_ERROR;
} }
......
...@@ -1238,6 +1238,7 @@ sub extractRelayState { ...@@ -1238,6 +1238,7 @@ sub extractRelayState {
} }
else { else {
$self->lmLog( "Unable to delete relaystate $relaystate", 'error' ); $self->lmLog( "Unable to delete relaystate $relaystate", 'error' );
$self->lmLog( $samlSessionInfo->error, 'error' );
} }
return 1; return 1;
...@@ -1666,6 +1667,7 @@ sub replayProtection { ...@@ -1666,6 +1667,7 @@ sub replayProtection {
"Unable to delete assertion session $session (Message ID $samlID)", "Unable to delete assertion session $session (Message ID $samlID)",
'error' 'error'
); );
$self->lmLog( $samlSessionInfo->error, 'error' );
return 0; return 0;
} }
} }
...@@ -1800,6 +1802,7 @@ sub loadArtifact { ...@@ -1800,6 +1802,7 @@ sub loadArtifact {
else { else {
$self->lmLog( "Unable to delete artifact session $session (ID $id)", $self->lmLog( "Unable to delete artifact session $session (ID $id)",
'error' ); 'error' );
$self->lmLog( $samlSessionInfo->error, 'error' );
return; return;
} }
}