Issue #1614 made authentication extensible in request log (#2004)

Issue #1614 made authentication extensible in request log (#2004)
Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2017-12-02 10:00:39 +01:00 committed by GitHub
parent 2067eac701
commit 15c0f79593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 2 deletions

View File

@ -127,8 +127,9 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement
buf.append(addr); buf.append(addr);
buf.append(" - "); buf.append(" - ");
Authentication authentication = request.getAuthentication();
append(buf,(authentication instanceof Authentication.User)?((Authentication.User)authentication).getUserIdentity().getUserPrincipal().getName():null); String auth = getAuthentication(request);
append(buf,auth==null?"-":auth);
buf.append(" ["); buf.append(" [");
if (_logDateCache != null) if (_logDateCache != null)
@ -221,6 +222,23 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement
} }
} }
/**
* Extract the user authentication
* @param request The request to extract from
* @return The string to log for authenticated user.
*/
protected String getAuthentication(Request request)
{
Authentication authentication = request.getAuthentication();
if (authentication instanceof Authentication.User)
return ((Authentication.User)authentication).getUserIdentity().getUserPrincipal().getName();
// TODO extract the user name if it is Authentication.Deferred and return as '?username'
return null;
}
/** /**
* Writes extended request and response information to the output stream. * Writes extended request and response information to the output stream.
* *