Web::Session

Build Status

Web::Session is a fork of Apache::Session::Browseable, which itself extends Apache::Session: sessions are stored in a database and can be searched, listed and purged through indexes (searchOn(), searchOnExpr(), searchLt(), searchGt(), get_key_from_all_sessions(), deleteIfLowerThan()).

It has been written to increase the performance of LemonLDAP::NG.

Backends

| Database | Module | |------------|-----------------------------------------------------| | PostgreSQL | Web::Session::PgJSON (alias: Web::Session::Postgres), Web::Session::Patroni | | MySQL | Web::Session::MySQLJSON (alias: Web::Session::MySQL) | | MariaDB | Web::Session::MariaDBJSON (alias: Web::Session::MariaDB) | | SQLite | Web::Session::SQLite | | Redis | Web::Session::Redis | | Cassandra | Web::Session::Cassandra | | LDAP | Web::Session::LDAP | | Files | Web::Session::File |

Read the documentation of the chosen module to create the table and the indexes: perldoc Web::Session::PgJSON, for example.

Example

use Web::Session::PgJSON;

my $args = {
    DataSource => 'dbi:Pg:dbname=sessions',
    UserName   => $user,
    Password   => $password,
    Commit     => 1,    # needed by the connection pool (default)
};

# Use it like Apache::Session
tie my %session, 'Web::Session::PgJSON', undef, $args;
$session{uid} = 'dwho';
my $id = $session{_session_id};
untie %session;

# Search sessions
my $sessions =
  Web::Session::PgJSON->searchOn( $args, 'uid', 'dwho', '_utime' );

# Purge old sessions
Web::Session::PgJSON->deleteIfLowerThan( $args,
    { or => { _utime => time - 7200 } } );

Migrating from Apache::Session::Browseable

See Changes for the full list of changes.

Installation

perl Build.PL
./Build
./Build test
./Build install

Run the tests through ./Build test (or prove -b after ./Build), not prove -l: some modules use AutoLoader, and their autosplit files exist only in blib/.

Tests of database backends run only when the database is available: see t/lib/SQLBackendTests.pm and .github/workflows/ci.yml for the environment variables (PG_DSN, MYSQL_DSN, MARIADB_DSN, REDIS_URL, LDAP_URL...).

License

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.1 or, at your option, any later version of Perl 5 you may have available. See COPYRIGHT and LICENSE.