Lemonldap::NG::Handler::UpdateCookie - Perl extension to manage update


Lemonldap-NG-Handler documentation Contained in the Lemonldap-NG-Handler distribution.

Index


Code Index:

NAME

Top

Lemonldap::NG::Handler::UpdateCookie - Perl extension to manage update cookie sent by client, to reload session in local cache.

SYNOPSIS

Top

  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
  } );

DESCRIPTION

Top

Lemonldap::NG::Handler::UpdateCookie is a special Lemonldap::NG:: handler 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.

EXPORT

See Lemonldap::NG::Handler

SEE ALSO

Top

Lemonldap::NG::Handler

AUTHOR

Top

Thomas Chemineau, <thomas.chemineau@gmail.com>

COPYRIGHT AND LICENSE

Top


Lemonldap-NG-Handler documentation Contained in the Lemonldap-NG-Handler distribution.

## @file
# Lemonldap::NG special handler

## @class
# Lemonldap::NG special handler
package Lemonldap::NG::Handler::UpdateCookie;

use strict;
use Lemonldap::NG::Handler::SharedConf qw(:all);
use base qw(Lemonldap::NG::Handler::SharedConf);

our $VERSION = '1.0.0';

## @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__