This is an automated email from the ASF dual-hosted git repository.

joerghoh pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-auth-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 2af6e2b  SLING-12448 Adding requestURL to the log for better 
traceablility (#17)
2af6e2b is described below

commit 2af6e2bab0acad6c13e904e7edefdd506dc74b93
Author: Patrique Legault <[email protected]>
AuthorDate: Fri Oct 11 11:24:01 2024 -0400

    SLING-12448 Adding requestURL to the log for better traceablility (#17)
    
    * Adding logging to capture request method and URL within authentication 
handler
    * adding recommendations made in the PR
    * moving string creation in the debug statement
---
 .../sling/auth/core/impl/AuthenticationHandlerHolder.java   | 13 ++++++++++---
 .../sling/auth/core/impl/SlingAuthenticatorOsgiTest.java    |  3 +++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlerHolder.java
 
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlerHolder.java
index 64ef415..51edb97 100644
--- 
a/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlerHolder.java
+++ 
b/src/main/java/org/apache/sling/auth/core/impl/AuthenticationHandlerHolder.java
@@ -78,7 +78,7 @@ final class AuthenticationHandlerHolder extends
     @Override
     public AuthenticationInfo doExtractCredentials(HttpServletRequest request,
             HttpServletResponse response) {
-        logger.debug("doExtractCredentials: Using AuthenticationHandler class 
{} to extract credentials", handler);
+        this.logDebugMessage("doExtractCredentials", request);
         return handler.extractCredentials(request, response);
     }
 
@@ -88,7 +88,7 @@ final class AuthenticationHandlerHolder extends
 
         // call handler if ok by its authentication type
         if (doesRequestCredentials(request)) {
-            logger.debug("doRequestCredentials: Using AuthenticationHandler 
class {} to request credentials", handler);
+            this.logDebugMessage("doRequestCredentials", request);
             return handler.requestCredentials(request, response);
         }
 
@@ -99,7 +99,7 @@ final class AuthenticationHandlerHolder extends
     @Override
     public void doDropCredentials(HttpServletRequest request,
             HttpServletResponse response) throws IOException {
-        logger.debug("doDropCredentials: Using AuthenticationHandler class {} 
to drop credentials", handler);
+        this.logDebugMessage("doDropCredentials", request);
         handler.dropCredentials(request, response);
     }
 
@@ -165,4 +165,11 @@ final class AuthenticationHandlerHolder extends
         final String requestLogin = AuthUtil.getAttributeOrParameter(request, 
REQUEST_LOGIN_PARAMETER, null);
         return requestLogin == null || authType.equals(requestLogin);
     }
+
+    private void logDebugMessage(String functionName, HttpServletRequest 
request) {
+        if (logger.isDebugEnabled()) {
+            String message = functionName + ": Using AuthenticationHandler 
class {} to request credentials for request {} {}";
+            logger.debug(message, handler, request.getMethod() 
,request.getRequestURL());
+        }
+    }
 }
diff --git 
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java 
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
index d96f031..9670f05 100644
--- 
a/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
+++ 
b/src/test/java/org/apache/sling/auth/core/impl/SlingAuthenticatorOsgiTest.java
@@ -105,6 +105,7 @@ public class SlingAuthenticatorOsgiTest {
     @Test
     public void testHandleSecurity() throws IOException {
         HttpServletRequest req = mock(HttpServletRequest.class);
+        when(req.getRequestURL()).thenReturn(new StringBuffer("/"));
         when(req.getServletPath()).thenReturn("/");
         when(req.getServerName()).thenReturn("localhost");
         when(req.getServerPort()).thenReturn(80);
@@ -131,6 +132,7 @@ public class SlingAuthenticatorOsgiTest {
                     // provide test authInfo 
                     AuthenticationInfo authInfo = new 
AuthenticationInfo("testing", "admin", "admin".toCharArray());
                     authInfo.put(AuthConstants.AUTH_INFO_LOGIN, Boolean.TRUE);
+                    when(req.getRequestURL()).thenReturn(new 
StringBuffer("/test"));
                     when(testAuthHandler.extractCredentials(req, 
resp)).thenReturn(authInfo);
                 },
                 () -> 
testEventHandler.collectedEvents(AuthConstants.TOPIC_LOGIN),
@@ -147,6 +149,7 @@ public class SlingAuthenticatorOsgiTest {
                 (req, resp) -> {
                     // provide invalid test authInfo 
                     AuthenticationInfo authInfo = new 
AuthenticationInfo("testing", "invalid", "invalid".toCharArray());
+                    when(req.getRequestURL()).thenReturn(new 
StringBuffer("/testing"));
                     when(testAuthHandler.extractCredentials(req, 
resp)).thenReturn(authInfo);
                     // throw exception to trigger FailedLogin event
                     try {

Reply via email to