ソースを参照

add log messages

Shinsuke Sugaya 5 年 前
コミット
f3e5858d00

+ 5 - 1
src/main/java/org/codelibs/fess/sso/SsoManager.java

@@ -33,7 +33,11 @@ public class SsoManager {
     protected final List<SsoAuthenticator> authenticatorList = new ArrayList<>();
     protected final List<SsoAuthenticator> authenticatorList = new ArrayList<>();
 
 
     public boolean available() {
     public boolean available() {
-        return !NONE.equals(getSsoType());
+        final String ssoType = getSsoType();
+        if (logger.isDebugEnabled()) {
+            logger.debug("sso.type: {}", ssoType);
+        }
+        return !NONE.equals(ssoType);
     }
     }
 
 
     public LoginCredential getLoginCredential() {
     public LoginCredential getLoginCredential() {

+ 9 - 0
src/main/java/org/codelibs/fess/sso/aad/AzureAdAuthenticator.java

@@ -123,6 +123,9 @@ public class AzureAdAuthenticator implements SsoAuthenticator {
     @Override
     @Override
     public LoginCredential getLoginCredential() {
     public LoginCredential getLoginCredential() {
         return LaRequestUtil.getOptionalRequest().map(request -> {
         return LaRequestUtil.getOptionalRequest().map(request -> {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Logging in with Azure AD Authenticator");
+            }
             final HttpSession session = request.getSession(false);
             final HttpSession session = request.getSession(false);
             if (session != null && containsAuthenticationData(request)) {
             if (session != null && containsAuthenticationData(request)) {
                 try {
                 try {
@@ -336,10 +339,16 @@ public class AzureAdAuthenticator implements SsoAuthenticator {
     }
     }
 
 
     protected boolean containsAuthenticationData(final HttpServletRequest request) {
     protected boolean containsAuthenticationData(final HttpServletRequest request) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("HTTP Method: {}", request.getMethod());
+        }
         if (!request.getMethod().equalsIgnoreCase("POST")) {
         if (!request.getMethod().equalsIgnoreCase("POST")) {
             return false;
             return false;
         }
         }
         final Map<String, String[]> params = request.getParameterMap();
         final Map<String, String[]> params = request.getParameterMap();
+        if (logger.isDebugEnabled()) {
+            logger.debug("params: {}", params);
+        }
         return params.containsKey(ERROR) || params.containsKey(ID_TOKEN) || params.containsKey(CODE);
         return params.containsKey(ERROR) || params.containsKey(ID_TOKEN) || params.containsKey(CODE);
     }
     }
 
 

+ 12 - 6
src/main/java/org/codelibs/fess/sso/oic/OpenIdConnectAuthenticator.java

@@ -84,6 +84,9 @@ public class OpenIdConnectAuthenticator implements SsoAuthenticator {
     @Override
     @Override
     public LoginCredential getLoginCredential() {
     public LoginCredential getLoginCredential() {
         return LaRequestUtil.getOptionalRequest().map(request -> {
         return LaRequestUtil.getOptionalRequest().map(request -> {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Logging in with OpenID Connect Authenticator");
+            }
             final HttpSession session = request.getSession(false);
             final HttpSession session = request.getSession(false);
             if (session != null) {
             if (session != null) {
                 final String sesState = (String) session.getAttribute(OIC_STATE);
                 final String sesState = (String) session.getAttribute(OIC_STATE);
@@ -91,12 +94,12 @@ public class OpenIdConnectAuthenticator implements SsoAuthenticator {
                     session.removeAttribute(OIC_STATE);
                     session.removeAttribute(OIC_STATE);
                     final String code = request.getParameter("code");
                     final String code = request.getParameter("code");
                     final String reqState = request.getParameter("state");
                     final String reqState = request.getParameter("state");
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("code: {}, state(request): {}, state(session): {}", code, reqState, sesState);
+                    }
                     if (sesState.equals(reqState) && StringUtil.isNotBlank(code)) {
                     if (sesState.equals(reqState) && StringUtil.isNotBlank(code)) {
                         return processCallback(request, code);
                         return processCallback(request, code);
                     }
                     }
-                    if (logger.isDebugEnabled()) {
-                        logger.debug("code:" + code + " state(request):" + reqState + " state(session):" + sesState);
-                    }
                     return null;
                     return null;
                 }
                 }
             }
             }
@@ -126,9 +129,9 @@ public class OpenIdConnectAuthenticator implements SsoAuthenticator {
             final String jwtSigniture = new String(Base64.decodeBase64(jwt[2]), Constants.UTF_8_CHARSET);
             final String jwtSigniture = new String(Base64.decodeBase64(jwt[2]), Constants.UTF_8_CHARSET);
 
 
             if (logger.isDebugEnabled()) {
             if (logger.isDebugEnabled()) {
-                logger.debug("jwtHeader: " + jwtHeader);
-                logger.debug("jwtClaim: " + jwtClaim);
-                logger.debug("jwtSigniture: " + jwtSigniture);
+                logger.debug("jwtHeader: {}", jwtHeader);
+                logger.debug("jwtClaim: {}", jwtClaim);
+                logger.debug("jwtSigniture: {}", jwtSigniture);
             }
             }
 
 
             // TODO validate signiture
             // TODO validate signiture
@@ -142,6 +145,9 @@ public class OpenIdConnectAuthenticator implements SsoAuthenticator {
             attributes.put("jwtclaim", jwtClaim);
             attributes.put("jwtclaim", jwtClaim);
             attributes.put("jwtsign", jwtSigniture);
             attributes.put("jwtsign", jwtSigniture);
 
 
+            if (logger.isDebugEnabled()) {
+                logger.debug("attribute: {}", attributes);
+            }
             parseJwtClaim(jwtClaim, attributes);
             parseJwtClaim(jwtClaim, attributes);
 
 
             return new OpenIdConnectCredential(attributes);
             return new OpenIdConnectCredential(attributes);

+ 15 - 1
src/main/java/org/codelibs/fess/sso/spnego/SpnegoAuthenticator.java

@@ -16,6 +16,7 @@
 package org.codelibs.fess.sso.spnego;
 package org.codelibs.fess.sso.spnego;
 
 
 import java.io.File;
 import java.io.File;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Enumeration;
 
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PostConstruct;
@@ -102,6 +103,9 @@ public class SpnegoAuthenticator implements SsoAuthenticator {
         return LaRequestUtil
         return LaRequestUtil
                 .getOptionalRequest()
                 .getOptionalRequest()
                 .map(request -> {
                 .map(request -> {
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("Logging in with SPNEGO Authenticator");
+                    }
                     final HttpServletResponse response = LaResponseUtil.getResponse();
                     final HttpServletResponse response = LaResponseUtil.getResponse();
                     final SpnegoHttpServletResponse spnegoResponse = new SpnegoHttpServletResponse(response);
                     final SpnegoHttpServletResponse spnegoResponse = new SpnegoHttpServletResponse(response);
 
 
@@ -109,6 +113,9 @@ public class SpnegoAuthenticator implements SsoAuthenticator {
                     final SpnegoPrincipal principal;
                     final SpnegoPrincipal principal;
                     try {
                     try {
                         principal = getAuthenticator().authenticate(request, spnegoResponse);
                         principal = getAuthenticator().authenticate(request, spnegoResponse);
+                        if (logger.isDebugEnabled()) {
+                            logger.debug("principal: {}", principal);
+                        }
                     } catch (final Exception e) {
                     } catch (final Exception e) {
                         final String msg = "HTTP Authorization Header=" + request.getHeader(Constants.AUTHZ_HEADER);
                         final String msg = "HTTP Authorization Header=" + request.getHeader(Constants.AUTHZ_HEADER);
                         if (logger.isDebugEnabled()) {
                         if (logger.isDebugEnabled()) {
@@ -118,7 +125,11 @@ public class SpnegoAuthenticator implements SsoAuthenticator {
                     }
                     }
 
 
                     // context/auth loop not yet complete
                     // context/auth loop not yet complete
-                    if (spnegoResponse.isStatusSet()) {
+                    final boolean status = spnegoResponse.isStatusSet();
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("isStatusSet: {}", status);
+                    }
+                    if (status) {
                         return new ActionResponseCredential(() -> {
                         return new ActionResponseCredential(() -> {
                             throw new RequestLoggingFilter.RequestClientErrorException("Your request is not authorized.",
                             throw new RequestLoggingFilter.RequestClientErrorException("Your request is not authorized.",
                                     "401 Unauthorized", HttpServletResponse.SC_UNAUTHORIZED);
                                     "401 Unauthorized", HttpServletResponse.SC_UNAUTHORIZED);
@@ -139,6 +150,9 @@ public class SpnegoAuthenticator implements SsoAuthenticator {
                     }
                     }
 
 
                     final String[] username = principal.getName().split("@", 2);
                     final String[] username = principal.getName().split("@", 2);
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("username: {}", Arrays.toString(username));
+                    }
                     return new SpnegoCredential(username[0]);
                     return new SpnegoCredential(username[0]);
                 }).orElseGet(() -> null);
                 }).orElseGet(() -> null);