瀏覽代碼

Log all cause exception when authc fails (#111534)

In RealmsAuthenticator, if a realm fails to authenticate the token, log
the whole chain of exception causes.
Tim Vernum 1 年之前
父節點
當前提交
f02be0779f

+ 10 - 1
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/RealmsAuthenticator.java

@@ -284,7 +284,16 @@ public class RealmsAuthenticator implements Authenticator {
     ) {
         messages.forEach((realm, tuple) -> {
             final String message = tuple.v1();
-            final String cause = tuple.v2() == null ? "" : " (Caused by " + tuple.v2() + ")";
+            Throwable ex = tuple.v2();
+            var cause = new StringBuilder();
+            while (ex != null) {
+                cause.append(cause.isEmpty() ? " (" : "; ");
+                cause.append("Caused by ").append(ex);
+                ex = ex.getCause();
+            }
+            if (cause.isEmpty() == false) {
+                cause.append(')');
+            }
             logger.warn("Authentication to realm {} failed - {}{}", realm.name(), message, cause);
         });
         if (context.getUnlicensedRealms().isEmpty() == false) {