From 060e4725186d3e637bbb5a839799ea93a754de9b Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Tue, 12 Mar 2024 10:39:38 +0100 Subject: [PATCH 01/10] #3102: Added regex to remove ordering prefix before sending to HTML template. --- .../lib/Lemonldap/NG/Portal/Main/Display.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 0571659e25..47de005902 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,12 @@ sub mkSessionArray { ip => $session->{ipAddr}, values => [ map { - { v => $session->{$_}, k => $_, "k_$_" => 1 } + my $modifiedKey = $_ =~ s/(\d+_)?//; + { + v => $session->{$modifiedKey}, + k => $_, + "k_$_" => 1 + } } @fields ], error => $session->{error}, -- GitLab From 42bd79365530f72ab2d692306f41cce62326c03e Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Tue, 12 Mar 2024 10:50:25 +0100 Subject: [PATCH 02/10] #3102: Changed regex to accept login history keys with digit-underscore prefix. --- .../lib/Lemonldap/NG/Manager/Build/Attributes.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 719137e024..a902697fe0 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', }, -- GitLab From fff1c7d2e6d4b9ea307e69dcba9527bcdffb6207 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Tue, 12 Mar 2024 11:10:29 +0100 Subject: [PATCH 03/10] #3102: Generated Attributes file to include regex. --- lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm index cd7d72c771..c1b0806fd3 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' => { -- GitLab From 469a2fba999b7f5be2c5e5a11cc8cce5b832a48a Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Tue, 12 Mar 2024 14:13:10 +0100 Subject: [PATCH 04/10] #3102: Fixed regex application to collect modified value. Added regex modification to _loginHistory store method. --- lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm | 4 +++- lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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 47de005902..5131e2dda6 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,9 @@ sub mkSessionArray { ip => $session->{ipAddr}, values => [ map { - my $modifiedKey = $_ =~ s/(\d+_)?//; + # Modifying key to remove ordering prefix + my $modifiedKey = $_; + $modifiedKey =~ s/(\d+_)?//; { v => $session->{$modifiedKey}, k => $_, 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 90cc9a3ed1..8cdada9218 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; -- GitLab From 6745ab02a64ee517dd8475ca6555046e78e014ee Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Tue, 12 Mar 2024 16:21:53 +0100 Subject: [PATCH 05/10] #3102: Added ordered columns to existing test data for login history. --- lemonldap-ng-manager/t/04-history-api.t | 14 ++++++++++++-- lemonldap-ng-manager/t/conf/lmConf-1.json | 5 ++++- lemonldap-ng-portal/t/63-History.t | 11 +++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lemonldap-ng-manager/t/04-history-api.t b/lemonldap-ng-manager/t/04-history-api.t index 7fdd547e89..ead230e2ff 100644 --- a/lemonldap-ng-manager/t/04-history-api.t +++ b/lemonldap-ng-manager/t/04-history-api.t @@ -94,7 +94,9 @@ newSession( "failedLogin" => [ { "_utime" => 1677062205, "error" => "5", - "ipAddr" => "10.128.239.1" + "ipAddr" => "10.128.239.1", + "cn" => "Doctor Who", + "uid" => "dwho" }, { "_utime" => 1676452178, @@ -114,7 +116,9 @@ newSession( ], "successLogin" => [ { "_utime" => 1677665858, - "ipAddr" => "10.128.239.1" + "ipAddr" => "10.128.239.1", + "cn" => "Doctor Who", + "uid" => "dwho" }, { "_utime" => 1677665776, @@ -194,6 +198,8 @@ subtest "Get last success for user" => sub { { 'date' => 1677665858, 'ipAddr' => '10.128.239.1', + 'cn' => 'Doctor Who', + 'uid' => 'dwho', 'result' => 'success' } ); @@ -207,6 +213,8 @@ subtest "Get last failure for user" => sub { 'date' => 1677062205, 'error' => '5', 'ipAddr' => '10.128.239.1', + 'cn' => 'Doctor Who', + 'uid' => 'dwho', 'result' => 'failed' } ); @@ -219,6 +227,8 @@ subtest "Get last event for user" => sub { { 'date' => 1677665858, 'ipAddr' => '10.128.239.1', + 'cn' => 'Doctor Who', + 'uid' => 'dwho', 'result' => 'success' } ); diff --git a/lemonldap-ng-manager/t/conf/lmConf-1.json b/lemonldap-ng-manager/t/conf/lmConf-1.json index 9a37b6a097..05400ab482 100644 --- a/lemonldap-ng-manager/t/conf/lmConf-1.json +++ b/lemonldap-ng-manager/t/conf/lmConf-1.json @@ -156,7 +156,10 @@ "reloadUrls": {}, "compactConf": 1, "securedCookie": 0, - "sessionDataToRemember": {}, + "sessionDataToRemember": { + "1_cn": "Name", + "0_uid": "UID" + }, "timeout": 72000, "userDB": "Same", "whatToTrace": "_whatToTrace" diff --git a/lemonldap-ng-portal/t/63-History.t b/lemonldap-ng-portal/t/63-History.t index 33e297e3ba..becb4a6367 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,12 @@ my $client = LLNG::Manager::Test->new( brutForceProtection => 0, portalMainLogo => 'common/logos/logo_llng_old.png', customPlugins => "t::HistoryPlugin", - sessionDataToRemember => - { uid => 'identity', _auth => 'AuthModule' }, + sessionDataToRemember => { + uid => 'identity', + _auth => 'AuthModule', + '1_cn' => 'Name', + '0_uid' => 'UUID' + }, } } ); -- GitLab From 0b6b76c8bddacf1c6d1e130afaedad8b31da6fe4 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Tue, 12 Mar 2024 16:51:09 +0100 Subject: [PATCH 06/10] #3102: Documenting login history column order feature. --- doc/sources/admin/loginhistory.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/sources/admin/loginhistory.rst b/doc/sources/admin/loginhistory.rst index 3571b2b905..301869e778 100644 --- a/doc/sources/admin/loginhistory.rst +++ b/doc/sources/admin/loginhistory.rst @@ -29,6 +29,7 @@ session, nothing is stored. * **Max successful logins count**: How many successful logins should be remembered in the history * **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. +* **Customise column order**: 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. 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 -- GitLab From de37fde7ea5d727de1822457340f2abf75ba97c9 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Wed, 13 Mar 2024 09:56:59 +0100 Subject: [PATCH 07/10] #3102: Added index prefix to test data. --- lemonldap-ng-portal/t/63-History.t | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lemonldap-ng-portal/t/63-History.t b/lemonldap-ng-portal/t/63-History.t index becb4a6367..1c774ce823 100644 --- a/lemonldap-ng-portal/t/63-History.t +++ b/lemonldap-ng-portal/t/63-History.t @@ -21,8 +21,7 @@ my $client = LLNG::Manager::Test->new( { sessionDataToRemember => { uid => 'identity', _auth => 'AuthModule', - '1_cn' => 'Name', - '0_uid' => 'UUID' + '0_cn' => 'Name', }, } } -- GitLab From d2c3a31c72b75e836b1e6d52b92485db0c4f4017 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Mon, 18 Mar 2024 09:54:45 +0100 Subject: [PATCH 08/10] #3102: Reverted changes to test and config --- lemonldap-ng-manager/t/04-history-api.t | 14 ++------------ lemonldap-ng-manager/t/conf/lmConf-1.json | 5 +---- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/lemonldap-ng-manager/t/04-history-api.t b/lemonldap-ng-manager/t/04-history-api.t index ead230e2ff..7fdd547e89 100644 --- a/lemonldap-ng-manager/t/04-history-api.t +++ b/lemonldap-ng-manager/t/04-history-api.t @@ -94,9 +94,7 @@ newSession( "failedLogin" => [ { "_utime" => 1677062205, "error" => "5", - "ipAddr" => "10.128.239.1", - "cn" => "Doctor Who", - "uid" => "dwho" + "ipAddr" => "10.128.239.1" }, { "_utime" => 1676452178, @@ -116,9 +114,7 @@ newSession( ], "successLogin" => [ { "_utime" => 1677665858, - "ipAddr" => "10.128.239.1", - "cn" => "Doctor Who", - "uid" => "dwho" + "ipAddr" => "10.128.239.1" }, { "_utime" => 1677665776, @@ -198,8 +194,6 @@ subtest "Get last success for user" => sub { { 'date' => 1677665858, 'ipAddr' => '10.128.239.1', - 'cn' => 'Doctor Who', - 'uid' => 'dwho', 'result' => 'success' } ); @@ -213,8 +207,6 @@ subtest "Get last failure for user" => sub { 'date' => 1677062205, 'error' => '5', 'ipAddr' => '10.128.239.1', - 'cn' => 'Doctor Who', - 'uid' => 'dwho', 'result' => 'failed' } ); @@ -227,8 +219,6 @@ subtest "Get last event for user" => sub { { 'date' => 1677665858, 'ipAddr' => '10.128.239.1', - 'cn' => 'Doctor Who', - 'uid' => 'dwho', 'result' => 'success' } ); diff --git a/lemonldap-ng-manager/t/conf/lmConf-1.json b/lemonldap-ng-manager/t/conf/lmConf-1.json index 05400ab482..9a37b6a097 100644 --- a/lemonldap-ng-manager/t/conf/lmConf-1.json +++ b/lemonldap-ng-manager/t/conf/lmConf-1.json @@ -156,10 +156,7 @@ "reloadUrls": {}, "compactConf": 1, "securedCookie": 0, - "sessionDataToRemember": { - "1_cn": "Name", - "0_uid": "UID" - }, + "sessionDataToRemember": {}, "timeout": 72000, "userDB": "Same", "whatToTrace": "_whatToTrace" -- GitLab From f7b05384b9698f5b00cc1b700a55458c69938059 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Mon, 18 Mar 2024 10:59:37 +0100 Subject: [PATCH 09/10] #3102: Added test to check for column order. --- lemonldap-ng-portal/t/63-History.t | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lemonldap-ng-portal/t/63-History.t b/lemonldap-ng-portal/t/63-History.t index 1c774ce823..e9dc304d68 100644 --- a/lemonldap-ng-portal/t/63-History.t +++ b/lemonldap-ng-portal/t/63-History.t @@ -19,7 +19,7 @@ my $client = LLNG::Manager::Test->new( { portalMainLogo => 'common/logos/logo_llng_old.png', customPlugins => "t::HistoryPlugin", sessionDataToRemember => { - uid => 'identity', + '1_uid' => 'identity', _auth => 'AuthModule', '0_cn' => 'Name', }, @@ -141,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'); -- GitLab From 5e0ae020db158c3879a6a93af39625464b419749 Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Mon, 18 Mar 2024 11:44:45 +0100 Subject: [PATCH 10/10] #3102: Added Tips subtitle section. Moved docs to tips section. --- doc/sources/admin/loginhistory.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/sources/admin/loginhistory.rst b/doc/sources/admin/loginhistory.rst index 301869e778..66875dca4d 100644 --- a/doc/sources/admin/loginhistory.rst +++ b/doc/sources/admin/loginhistory.rst @@ -29,8 +29,9 @@ session, nothing is stored. * **Max successful logins count**: How many successful logins should be remembered in the history * **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. -* **Customise column order**: 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. +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 @@ -44,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. -- GitLab