Commit f60e6516 authored by Thomas Chemineau's avatar Thomas Chemineau

adding Lemonldap::NG::Handler::UpdateCookie.pm and associated files

parent 810505b1
......@@ -360,6 +360,7 @@ install_handler_site: install_conf_dir
@install -v -d ${RHANDLERDIR}
@cp --remove-destination ${SRCHANDLERDIR}/example/MyHandler.pm ${RHANDLERDIR}
@cp --remove-destination ${SRCHANDLERDIR}/example/MyHandlerZimbra.pm ${RHANDLERDIR}
@cp --remove-destination ${SRCHANDLERDIR}/example/MyUpdateCookieHandler.pm ${RHANDLERDIR}
@rm -rf $$(find $(RHANDLERDIR) -type d -name .svn)
install_test_site:
......
# Handler to manage update cookie
package My::Package::UpdateCookie;
use Lemonldap::NG::Handler::UpdateCookie;
@ISA = qw(Lemonldap::NG::Handler::UpdateCookie);
__PACKAGE__->init(
{
# See Lemonldap::NG::Handler
}
);
1;
package Lemonldap::NG::Handler::UpdateCookie;
use strict;
use Lemonldap::NG::Handler::SharedConf qw(:all);
use Data::Dumper;
our @ISA = qw(Lemonldap::NG::Handler::SharedConf);
our $VERSION = '0.1';
## @rmethod int run(Apache2::RequestRec apacheRequest)
# Main method used to control access.
# Calls :
# - fetchId()
# - fetchUTime()
# - SUPER::run()
# @param $apacheRequest Current request
# @return Apache2::Const value (OK, FORBIDDEN, REDIRECT or SERVER_ERROR)
sub run {
my $class = shift;
$apacheRequest = $_[0];
# I - Recover the main cookie.
# If not present, then call parent.
my $id;
if ( $id = $class->SUPER::fetchId ) {
# II - Found update cookie.
# If found, remove session from local cache when utime is recent.
my $utime;
if ( $utime = $class->fetchUTime ) {
my $clear = 0;
if ( $id eq $datas->{_session_id} and $datas->{_utime} lt $utime ) {
$datas->{_session_id} = 0;
$clear = 1;
}
elsif ( $refLocalStorage and my $ldatas = $refLocalStorage->get($id) ) {
if ( $ldatas->{_utime} lt $utime ) {
$clear = 1;
}
}
if ( $clear ) {
$class->lmLog( "$class: remove $id from local cache", 'debug' );
$refLocalStorage->remove($id);
}
}
}
# III - Call parent process.
$class->SUPER::run(@_);
}
## @rmethod protected $ fetchUTime()
# Get user cookies and search for Lemonldap::NG update cookie.
# @return Value of the cookie if found, 0 else
sub fetchUTime {
my $t = lmHeaderIn( $apacheRequest, 'Cookie' );
my $c = $cookieName . 'update';
return ( $t =~ /$c=([^,; ]+)/o ) ? $1 : 0;
}
1;
__END__
=head1 NAME
=encoding utf8
Lemonldap::NG::Handler::UpdateCookie - Perl extension to manage update
cookie sent by client, to reload session in local cache.
=head1 SYNOPSIS
package My::Package;
use Lemonldap::NG::Handler::UpdateCookie;
@ISA = qw(Lemonldap::NG::Handler::SharedConf);
__PACKAGE__->init ( {
# See Lemonldap::NG::Handler for more
# Local storage used for sessions and configuration
} );
=head1 DESCRIPTION
Lemonldap::NG::Handler::UpdateCookie is a special Lemonldap::NG:: hander that
allow a session to be removed from local cache of the current handler, if a
update cookie is sent by the user.
The update cookie should be name "lemonldapupdate" and only contains a simple
timestamp.
=head2 EXPORT
See L<Lemonldap::NG::Handler>
=head1 SEE ALSO
L<Lemonldap::NG::Handler>
=head1 AUTHOR
Thomas Chemineau, E<lt>thomas.chemineau@gmail.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2010 by Thomas Chemineau
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.
=cut
......@@ -23,6 +23,7 @@ print Lemonldap::NG::Common::BuildWSDL->new->buildWSDL(<<EOT);
<complexType name="CookiesSequence">
<sequence>
__XMLCOOKIELIST__
<element name="lemonldapupdate" type="xsd:string"></element>
</sequence>
</complexType>
<complexType name="AttributesSequence">
......
......@@ -1111,9 +1111,6 @@ sub setAuthSessionInfo {
# Get the current authentication module
$self->{sessionInfo}->{_auth} = $self->get_module("auth");
# Store primary informations
$self->{sessionInfo}->{'_utime'} = time();
return $self->SUPER::setAuthSessionInfo();
}
......
......@@ -83,6 +83,7 @@ sub getCookies {
setMacros setLocalGroups setGroups authenticate removeOther grantSession
store buildCookie)
);
$self->updateSession();
}
my @tmp = ();
push @tmp, SOAP::Data->name( error => $self->{error} );
......@@ -91,6 +92,8 @@ sub getCookies {
foreach ( @{ $self->{cookie} } ) {
push @cookies, SOAP::Data->name( $_->name, $_->value );
}
push @cookies, SOAP::Data->name(
$self->{cookieName} . 'update', time() );
}
else {
my @cookieNames = split /\s+/, $self->{cookieName};
......
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