Factor psession id calculation into Common
This commit is contained in:
parent
21e6cbb2c4
commit
4497f39efe
|
@ -3,12 +3,12 @@ package Lemonldap::NG::Common::CliSessions;
|
||||||
use strict;
|
use strict;
|
||||||
use Mouse;
|
use Mouse;
|
||||||
use JSON;
|
use JSON;
|
||||||
use Digest::MD5 qw(md5_hex);
|
|
||||||
use MIME::Base64;
|
use MIME::Base64;
|
||||||
use Lemonldap::NG::Common::Conf;
|
use Lemonldap::NG::Common::Conf;
|
||||||
use Lemonldap::NG::Common::Logger::Std;
|
use Lemonldap::NG::Common::Logger::Std;
|
||||||
use Lemonldap::NG::Common::Apache::Session;
|
use Lemonldap::NG::Common::Apache::Session;
|
||||||
use Lemonldap::NG::Common::Session;
|
use Lemonldap::NG::Common::Session;
|
||||||
|
use Lemonldap::NG::Common::Util qw/getPSessionID/;
|
||||||
|
|
||||||
our $VERSION = '2.0.8';
|
our $VERSION = '2.0.8';
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ sub _get_one_session {
|
||||||
# Handle --persistent
|
# Handle --persistent
|
||||||
elsif ( $self->opts->{persistent} ) {
|
elsif ( $self->opts->{persistent} ) {
|
||||||
$backendStorage = "persistentStorage";
|
$backendStorage = "persistentStorage";
|
||||||
$id = $self->_md5hash($id);
|
$id = getPSessionID($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
# In any case, fall back to global storage if we couldn't find the backend
|
# In any case, fall back to global storage if we couldn't find the backend
|
||||||
|
@ -195,13 +195,6 @@ sub get {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return md5(s)
|
|
||||||
# TODO factor with portal function
|
|
||||||
sub _md5hash {
|
|
||||||
my ( $self, $s ) = @_;
|
|
||||||
return substr( Digest::MD5::md5_hex($s), 0, 32 );
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO factor with manager API function
|
# TODO factor with manager API function
|
||||||
sub _genId2F {
|
sub _genId2F {
|
||||||
my ( $self, $device ) = @_;
|
my ( $self, $device ) = @_;
|
||||||
|
@ -211,7 +204,7 @@ sub _genId2F {
|
||||||
|
|
||||||
sub _get_psession {
|
sub _get_psession {
|
||||||
my ( $self, $uid ) = @_;
|
my ( $self, $uid ) = @_;
|
||||||
my $psession_id = $self->_md5hash($uid);
|
my $psession_id = getPSessionID($uid);
|
||||||
my $res = $self->_get_one_session( $psession_id, 'persistent' );
|
my $res = $self->_get_one_session( $psession_id, 'persistent' );
|
||||||
die "Could not get psession for user $uid" unless $res;
|
die "Could not get psession for user $uid" unless $res;
|
||||||
return $res;
|
return $res;
|
||||||
|
|
|
@ -1,11 +1,19 @@
|
||||||
package Lemonldap::NG::Common::Util;
|
package Lemonldap::NG::Common::Util;
|
||||||
require Exporter;
|
require Exporter;
|
||||||
|
|
||||||
|
use Digest::MD5;
|
||||||
|
|
||||||
use 5.10.0;
|
use 5.10.0;
|
||||||
|
|
||||||
our $VERSION = '2.0.9';
|
our $VERSION = '2.0.9';
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT_OK = qw(getSameSite);
|
our @EXPORT_OK = qw(getSameSite getPSessionID);
|
||||||
|
|
||||||
|
# Return stable psession ID from username
|
||||||
|
sub getPSessionID {
|
||||||
|
my ($uid) = @_;
|
||||||
|
return substr( Digest::MD5::md5_hex($uid), 0, 32 );
|
||||||
|
}
|
||||||
|
|
||||||
sub getSameSite {
|
sub getSameSite {
|
||||||
my ($conf) = @_;
|
my ($conf) = @_;
|
||||||
|
@ -49,6 +57,10 @@ modules.
|
||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
|
|
||||||
|
=head3 getPSessionID($uid)
|
||||||
|
|
||||||
|
This method computes the psession ID from the user login
|
||||||
|
|
||||||
=head3 getSameSite($conf)
|
=head3 getSameSite($conf)
|
||||||
|
|
||||||
Try to find a sensible value for the SameSite cookie attribute.
|
Try to find a sensible value for the SameSite cookie attribute.
|
||||||
|
|
|
@ -16,6 +16,7 @@ package Lemonldap::NG::Portal::Main;
|
||||||
use strict;
|
use strict;
|
||||||
use URI::Escape;
|
use URI::Escape;
|
||||||
use JSON;
|
use JSON;
|
||||||
|
use Lemonldap::NG::Common::Util qw(getPSessionID);
|
||||||
|
|
||||||
has trOverCache => ( is => 'rw', default => sub { {} } );
|
has trOverCache => ( is => 'rw', default => sub { {} } );
|
||||||
|
|
||||||
|
@ -465,7 +466,7 @@ sub getPersistentSession {
|
||||||
return unless ( defined $uid and !$self->conf->{disablePersistentStorage} );
|
return unless ( defined $uid and !$self->conf->{disablePersistentStorage} );
|
||||||
|
|
||||||
# Compute persistent identifier
|
# Compute persistent identifier
|
||||||
my $pid = $self->_md5hash($uid);
|
my $pid = getPSessionID($uid);
|
||||||
|
|
||||||
$info->{_session_uid} = $uid;
|
$info->{_session_uid} = $uid;
|
||||||
|
|
||||||
|
@ -530,7 +531,7 @@ sub updatePersistentSession {
|
||||||
|
|
||||||
if ( $persistentSession->error ) {
|
if ( $persistentSession->error ) {
|
||||||
$self->logger->error(
|
$self->logger->error(
|
||||||
"Cannot update persistent session " . $self->_md5hash($uid) );
|
"Cannot update persistent session " . getPSessionID($uid) );
|
||||||
$self->logger->error( $persistentSession->error );
|
$self->logger->error( $persistentSession->error );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -639,12 +640,6 @@ sub _deleteSession {
|
||||||
return $session->error ? 0 : 1;
|
return $session->error ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return md5(s)
|
|
||||||
sub _md5hash {
|
|
||||||
my ( $self, $s ) = @_;
|
|
||||||
return substr( Digest::MD5::md5_hex($s), 0, 32 );
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if an URL's domain name is declared in LL::NG config or is declared as
|
# Check if an URL's domain name is declared in LL::NG config or is declared as
|
||||||
# trusted domain
|
# trusted domain
|
||||||
sub isTrustedUrl {
|
sub isTrustedUrl {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user