Skip to content
Permalink
Browse files
Merge pull request #31 from cyrille-leclerc/master
[JENKINS-37625] Don’t get the request.remoteUser if it’s a deferred authentication
  • Loading branch information
oleg-nenashev committed Jan 16, 2017
2 parents e5be823 + 3a1b4fd commit 784537203190576eb8523deab79cf035fe6da40a
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/java/winstone/accesslog/SimpleAccessLogger.java
@@ -6,6 +6,7 @@
*/
package winstone.accesslog;

import org.eclipse.jetty.server.Authentication;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.RequestLog;
import org.eclipse.jetty.server.Response;
@@ -86,6 +87,17 @@ public void log(Request request, Response response) {
synchronized (DF) {
date = DF.format(new Date());
}

// mimic https://github.com/eclipse/jetty.project/blob/jetty-9.4.0.v20161208/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java#L130
Authentication authentication = request.getAuthentication();
String remoteUser;
if (authentication instanceof Authentication.User) {
Authentication.User user = (Authentication.User) authentication;
remoteUser = user.getUserIdentity().getUserPrincipal().getName();
} else {
remoteUser = null;
}

String logLine = WinstoneResourceBundle.globalReplace(this.pattern, new String[][] {
{"###x-forwarded-for###", nvl(request.getHeader("X-Forwarded-For"))},
{"###x-forwarded-host###", nvl(request.getHeader("X-Forwarded-Host"))},
@@ -98,7 +110,7 @@ public void log(Request request, Response response) {
{"###dnt###", nvl(request.getHeader("DNT"))},
{"###via###", nvl(request.getHeader("Via"))},
{"###ip###", request.getRemoteHost()},
{"###user###", nvl(request.getRemoteUser())},
{"###user###", nvl(remoteUser)},
{"###time###", "[" + date + "]"},
{"###uriLine###", uriLine},
{"###status###", "" + status},

0 comments on commit 7845372

Please sign in to comment.