[Rt-commit] rt branch 5.0/improve-log-info-for-web-remote-user-auth created. rt-5.0.3-216-g967b19eb66

BPS Git Server git at git.bestpractical.com
Wed Dec 28 21:52:04 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/improve-log-info-for-web-remote-user-auth has been created
        at  967b19eb660a3c0277b3754564dd07a62bbe17b5 (commit)

- Log -----------------------------------------------------------------
commit 967b19eb660a3c0277b3754564dd07a62bbe17b5
Author: Ronaldo Richieri <ronaldo at bestpractical.com>
Date:   Tue Dec 27 12:43:28 2022 -0300

    Add Log Info/Debug/Error when user log in and out with web remote user auth.
    
    Change Logout menu behavior when LogoutURL is set to first delete session from RT and then redirect.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index da6382ec27..5dbd275011 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -806,6 +806,7 @@ sub AttemptExternalAuth {
         }
 
         if ( _UserLoggedIn() ) {
+            RT->Logger->info("Session created from REMOTE_USER for user $user");
             $HTML::Mason::Commands::session{'WebExternallyAuthed'} = 1;
             $m->callback( %$ARGS, CallbackName => 'ExternalAuthSuccessfulLogin', CallbackPage => '/autohandler' );
             # It is possible that we did a redirect to the login page,
@@ -5306,4 +5307,4 @@ sub GetDashboards {
 package RT::Interface::Web;
 RT::Base->_ImportOverlays();
 
-1;
+1;
\ No newline at end of file
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index f3dc87c541..58704791ff 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -338,11 +338,8 @@ sub BuildMainNav {
             );
         }
     }
-    my $logout_url = RT->Config->Get('LogoutURL');
-    if ( $current_user->Name
-         && (   !RT->Config->Get('WebRemoteUserAuth')
-              || RT->Config->Get('WebFallbackToRTLogin') )) {
-        $about_me->child( logout => title => loc('Logout'), path => $logout_url );
+    if ( $current_user->Name ) {
+        _BuildLogoutMenu( $about_me );
     }
     if ( $request_path =~ m{^/Dashboards/(\d+)?}) {
         if ( my $id = ( $1 || $HTML::Mason::Commands::DECODED_ARGS->{'id'} ) ) {
@@ -1624,6 +1621,18 @@ sub _BuildAdminMenu {
     }
 }
 
+sub _BuildLogoutMenu {
+    my $about_me = shift;
+
+    my $logout_url = RT->Config->Get('LogoutURL') || '';
+    # If user is not externally authenticated, show the logout link
+    # otherwise, show the logout link if LogoutURL is set to something other than the default
+    if ( !$HTML::Mason::Commands::session{'WebExternallyAuthed'} || $logout_url ne '/NoAuth/Logout.html' )
+    {
+        $about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' );
+    }
+}
+
 sub BuildSelfServiceNav {
     my $request_path = shift;
     my $top          = shift;
@@ -1694,11 +1703,8 @@ sub BuildSelfServiceNav {
         $about_me->child( prefs => title => loc('Preferences'), path => '/SelfService/Prefs.html' );
     }
 
-    my $logout_url = RT->Config->Get('LogoutURL');
-    if ( $current_user->Name
-         && (   !RT->Config->Get('WebRemoteUserAuth')
-              || RT->Config->Get('WebFallbackToRTLogin') )) {
-        $about_me->child( logout => title => loc('Logout'), path => $logout_url );
+    if ( $current_user->Name ) {
+        _BuildLogoutMenu($about_me);
     }
 
     if ( RT->Config->Get('SelfServiceShowArticleSearch') ) {
diff --git a/share/html/NoAuth/Logout.html b/share/html/NoAuth/Logout.html
index 4587533211..07703660bb 100644
--- a/share/html/NoAuth/Logout.html
+++ b/share/html/NoAuth/Logout.html
@@ -77,11 +77,26 @@ $m->callback( %ARGS, CallbackName => 'ModifyLoginRedirect', URL => \$URL );
 
 $m->callback( %ARGS, CallbackName => 'BeforeSessionDelete' );
 
+my $username;
 if (keys %session) {
+    $username = $session{'CurrentUser'}->Name;
+
+    # If WebRemoteUserAuth and LogoutURL are set, redirect to the LogoutURL set on Config
+    if (
+        RT->Config->Get('WebRemoteUserAuth')
+        && $session{'WebExternallyAuthed'}
+        && RT->Config->Get('LogoutURL')
+    ) {
+        $URL = RT->Config->Get('LogoutURL');
+    }
+
+    # Clear the session
     RT::Interface::Web::InstantiateNewSession();
     $session{'CurrentUser'} = RT::CurrentUser->new;
 }
 
 $m->callback( %ARGS, CallbackName => 'AfterSessionDelete' );
 $m->notes->{RefreshURL} = $URL;
+
+RT->Logger->info("User $username logged out. Redirecting to $URL") if $username;
 </%INIT>

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list