Skip to content

Commit

Permalink
Jetty 12.0.x custom request log #8819 (#9896)
Browse files Browse the repository at this point in the history
* Resolve #8819 CustomRequestLog improvement

Resolves #8819 CustomRequestLog improvements:
 + only add extra detail if the log is a CustomRequestLog
 + add extra detail as a record
 + get authentication state directly from request attribute

* protect against null core request

* protect against null core request

* Use nanotime for logged latency
  • Loading branch information
gregw authored Jun 13, 2023
1 parent 85407aa commit d3e88a9
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* cycles. Authentication might not yet be checked or it might be checked
* and failed, checked and deferred or succeeded.
*/
public interface AuthenticationState
public interface AuthenticationState extends Request.AuthenticationState
{
/**
* Get the authentication state of a request
Expand All @@ -41,8 +41,8 @@ public interface AuthenticationState
*/
static AuthenticationState getAuthenticationState(Request request)
{
Object auth = request.getAttribute(AuthenticationState.class.getName());
return auth instanceof AuthenticationState authenticationState ? authenticationState : null;
Request.AuthenticationState state = Request.getAuthenticationState(request);
return state instanceof AuthenticationState authenticationState ? authenticationState : null;
}

/**
Expand All @@ -52,7 +52,7 @@ static AuthenticationState getAuthenticationState(Request request)
*/
static void setAuthenticationState(Request request, AuthenticationState authenticationState)
{
request.setAttribute(AuthenticationState.class.getName(), authenticationState);
Request.setAuthenticationState(request, authenticationState);
}

/**
Expand Down Expand Up @@ -193,6 +193,15 @@ interface Succeeded extends AuthenticationState
*/
UserIdentity getUserIdentity();

@Override
default Principal getUserPrincipal()
{
UserIdentity user = getUserIdentity();
if (user != null)
return user.getUserPrincipal();
return null;
}

/**
* @param role The role to check.
* @return True if the user is in the passed role
Expand Down
Loading

0 comments on commit d3e88a9

Please sign in to comment.