Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 7845372
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/java/winstone/accesslog/SimpleAccessLogger.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))},
Expand All @@ -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},
Expand Down

0 comments on commit 7845372

Please sign in to comment.