Skip to content
Permalink
Browse files
[JENKINS-37625] Don’t get the request.remoteUser if it’s a deferred a…
…uthentication (`org.eclipse.jetty.server.Authentication.Deferred`) to prevent "IllegalStateException: Response is committed"

```
java.lang.IllegalStateException: Response is committed
	at org.eclipse.jetty.server.Request.getSession(Request.java:1400)
	at org.eclipse.jetty.security.authentication.FormAuthenticator.validateRequest(FormAuthenticator.java:260)
	at org.eclipse.jetty.security.authentication.DeferredAuthentication.authenticate(DeferredAuthentication.java:68)
	at org.eclipse.jetty.server.Request.getUserPrincipal(Request.java:1479)
	at org.eclipse.jetty.server.Request.getRemoteUser(Request.java:1087)
	at winstone.accesslog.SimpleAccessLogger.log(SimpleAccessLogger.java:89)
	at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:113)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.Server.handle(Server.java:499)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
	at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
	at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
```
  • Loading branch information
cyrille-leclerc committed Jan 13, 2017
1 parent e5be823 commit 3a1b4fd46de4ab1629b92ff709f8a8d4d1593013
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 3a1b4fd

Please sign in to comment.