From e3eacb3814a0f2707bb7213b4ed31593f908b473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Oudot?= Date: Tue, 15 Apr 2014 14:02:39 +0000 Subject: [PATCH] Use new session API in UpdateCookie Handler (#671) --- .../Handler/SpecificHandlers/UpdateCookie.pm | 34 +++++++++++++++---- .../lib/Lemonldap/NG/Handler/UpdateCookie.pm | 34 +++++++++++++++---- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/SpecificHandlers/UpdateCookie.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/SpecificHandlers/UpdateCookie.pm index d387e322d..429afc8ba 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/SpecificHandlers/UpdateCookie.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/SpecificHandlers/UpdateCookie.pm @@ -13,8 +13,9 @@ use Lemonldap::NG::Handler::DefaultHandler qw(:all); use base qw(Lemonldap::NG::Handler::DefaultHandler); use Lemonldap::NG::Handler::Main::Headers; use Lemonldap::NG::Handler::Main::Logger; +use Lemonldap::NG::Common::Session; -our $VERSION = '1.0.0'; +our $VERSION = '1.4.0'; ## @rmethod int run(Apache2::RequestRec apacheRequest) # Main method used to control access. @@ -38,21 +39,40 @@ sub run { my $utime; if ( $utime = $class->fetchUTime ) { my $clear = 0; + + my $apacheSession = Lemonldap::NG::Common::Session->new( + { + storageModule => $tsv->{globalStorage}, + storageModuleOptions => $tsv->{globalStorageOptions}, + cacheModule => $tsv->{localSessionStorage}, + cacheModuleOptions => $tsv->{localSessionStorageOptions}, + id => $id, + kind => "SSO", + } + ); + + # Check process data if ( $id eq $datas->{_session_id} and $datas->{_utime} lt $utime ) { $datas->{_session_id} = 0; $clear = 1; } - elsif ( $tsv->{refLocalStorage} - and my $ldatas = $tsv->{refLocalStorage}->get($id) ) - { - if ( $ldatas->{_utime} lt $utime ) { - $clear = 1; + + # Get session + else { + unless ( $apacheSession->data ) { + Lemonldap::NG::Handler::Main::Logger->lmLog( + "Session $id can't be retrieved", 'info' ); + } + else { + $clear = 1 if ( $apacheSession->data->{_utime} lt $utime ); } } + + # Clear cache if needed if ($clear) { Lemonldap::NG::Handler::Main::Logger->lmLog( "$class: remove $id from local cache", 'debug' ); - $tsv->{refLocalStorage}->remove($id); + $apacheSession->cacheUpdate(); } } diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/UpdateCookie.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/UpdateCookie.pm index 7e16ffbb6..083862bc2 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/UpdateCookie.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/UpdateCookie.pm @@ -14,8 +14,9 @@ use Lemonldap::NG::Handler::DefaultHandler qw(:all); use base qw(Lemonldap::NG::Handler::DefaultHandler); use Lemonldap::NG::Handler::Main::Headers; use Lemonldap::NG::Handler::Main::Logger; +use Lemonldap::NG::Common::Session; -our $VERSION = '1.0.0'; +our $VERSION = '1.4.0'; ## @rmethod int run(Apache2::RequestRec apacheRequest) # Main method used to control access. @@ -39,21 +40,40 @@ sub run { my $utime; if ( $utime = $class->fetchUTime ) { my $clear = 0; + + my $apacheSession = Lemonldap::NG::Common::Session->new( + { + storageModule => $tsv->{globalStorage}, + storageModuleOptions => $tsv->{globalStorageOptions}, + cacheModule => $tsv->{localSessionStorage}, + cacheModuleOptions => $tsv->{localSessionStorageOptions}, + id => $id, + kind => "SSO", + } + ); + + # Check process data if ( $id eq $datas->{_session_id} and $datas->{_utime} lt $utime ) { $datas->{_session_id} = 0; $clear = 1; } - elsif ( $tsv->{refLocalStorage} - and my $ldatas = $tsv->{refLocalStorage}->get($id) ) - { - if ( $ldatas->{_utime} lt $utime ) { - $clear = 1; + + # Get session + else { + unless ( $apacheSession->data ) { + Lemonldap::NG::Handler::Main::Logger->lmLog( + "Session $id can't be retrieved", 'info' ); + } + else { + $clear = 1 if ( $apacheSession->data->{_utime} lt $utime ); } } + + # Clear cache if needed if ($clear) { Lemonldap::NG::Handler::Main::Logger->lmLog( "$class: remove $id from local cache", 'debug' ); - $tsv->{refLocalStorage}->remove($id); + $apacheSession->cacheUpdate(); } }