diff --git a/doc/sources/admin/loginhistory.rst b/doc/sources/admin/loginhistory.rst index 3571b2b90511d3b38b338cf11c13f010fa1a1c8c..66875dca4d67ba66d3c55673e905c323e56d9c45 100644 --- a/doc/sources/admin/loginhistory.rst +++ b/doc/sources/admin/loginhistory.rst @@ -30,6 +30,8 @@ session, nothing is stored. * **Max failed logins count**: How many failed logins should be remembered in the history * **Session data to store**: additional session variables to store in the history. *Key* is the variable (or macro) name, *Value* is the title of the column used when displaying the field. Use ``__hidden__`` to store a variables without displaying it to the user. +Tips +~~~~ By default, login time and IP address are stored in history, and the error message prompted to the user for failed logins. It is possible to store any additional session data. For example to store authentication, add a new key @@ -43,3 +45,5 @@ You can also display a check box on the authentication form, to allow user to see their login history before being redirected to the protected application (see :ref:`portal customization`). + +The order of the columns can be specified by add a number value to the *Key*. Use ``X_key`` where ``X`` is a digit value representing the order and the ``key`` represents the attribute to be retrieved and displayed. diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm index cd7d72c7719011f1f3d3280d854df71252c96a4b..c1b0806fd3720e98ed520cd4cf2265442553cf7e 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm @@ -4895,7 +4895,7 @@ qr/(?:(?:https?):\/\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.] }, 'sessionDataToRemember' => { 'keyMsgFail' => '__invalidSessionData__', - 'keyTest' => qr/^[_a-zA-Z][a-zA-Z0-9_]*$/, + 'keyTest' => qr/^(\d+_)?[_a-zA-Z][a-zA-Z0-9_]*$/, 'type' => 'keyTextContainer' }, 'sfEngine' => { diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm index 719137e024474758caa7060a0dd01079c48d31e2..a902697fe03a05e4f9a012ac75a23729599e0a92 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm @@ -1756,7 +1756,7 @@ sub attributes { }, sessionDataToRemember => { type => 'keyTextContainer', - keyTest => qr/^[_a-zA-Z][a-zA-Z0-9_]*$/, + keyTest => qr/^(\d+_)?[_a-zA-Z][a-zA-Z0-9_]*$/, keyMsgFail => '__invalidSessionData__', documentation => 'Data to remember in login history', }, diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm index 0571659e25ee8b392078c65c3b2d99cf420b9b27..5131e2dda637292fb43ed1f358cc11814767545e 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -796,7 +796,14 @@ sub mkSessionArray { ip => $session->{ipAddr}, values => [ map { - { v => $session->{$_}, k => $_, "k_$_" => 1 } + # Modifying key to remove ordering prefix + my $modifiedKey = $_; + $modifiedKey =~ s/(\d+_)?//; + { + v => $session->{$modifiedKey}, + k => $_, + "k_$_" => 1 + } } @fields ], error => $session->{error}, diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index 90cc9a3ed15ac3b2dcc60f6102379439aff7d2a8..8cdada9218bc47da683a948d7ce104d5e3845555 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -1254,7 +1254,11 @@ sub _sumUpSession { $res->{$_} = $session->{$_} foreach ( "_utime", "ipAddr", - keys %{ $self->conf->{sessionDataToRemember} }, + map { + # Modifying key to remove ordering prefix + $_ =~ s/(\d+_)?//; + $_; + } keys %{ $self->conf->{sessionDataToRemember} }, keys %{ $self->pluginSessionDataToRemember } ); return $res; diff --git a/lemonldap-ng-portal/t/63-History.t b/lemonldap-ng-portal/t/63-History.t index 33e297e3bacd044a8a4921686553d109ac618fb3..e9dc304d68dcd2d7df96713adb5c13a20b3400da 100644 --- a/lemonldap-ng-portal/t/63-History.t +++ b/lemonldap-ng-portal/t/63-History.t @@ -9,8 +9,7 @@ BEGIN { my $res; -my $client = LLNG::Manager::Test->new( - { +my $client = LLNG::Manager::Test->new( { ini => { logLevel => 'error', authentication => 'Demo', @@ -19,8 +18,11 @@ my $client = LLNG::Manager::Test->new( brutForceProtection => 0, portalMainLogo => 'common/logos/logo_llng_old.png', customPlugins => "t::HistoryPlugin", - sessionDataToRemember => - { uid => 'identity', _auth => 'AuthModule' }, + sessionDataToRemember => { + '1_uid' => 'identity', + _auth => 'AuthModule', + '0_cn' => 'Name', + }, } } ); @@ -139,13 +141,15 @@ my @ccv1 = ( $res->[2]->[0] =~ /dwho<\/td>/gs ); my @ccv2 = ( $res->[2]->[0] =~ /Demo<\/td>/gs ); my @ccv3 = ( $res->[2]->[0] =~ /en<\/td>/gs ); my @ccv4 = ( $res->[2]->[0] =~ /1<\/td>/gs ); +my @ccv5 = ( $res->[2]->[0] =~ /Doctor Who<\/td>\s*dwho<\/td>/gs); # History with 5 entries and 10 custom values ok( @c == 5, ' -> Five entries found' ); ok( @cf == 2, " -> Two 'failedLogin' entries found" ); is( @ccv1 + @ccv2 + @ccv3, 15, "Custom value entries found" ); is( @ccv4, 0, "Hidden history field is missing" ); -count(4); +is( @ccv5, 5, "Found Name before UID as specified by Prefix" ); +count(5); # Check psession content my $psession = getPSession('dwho');