Open
Description
GlassFish Version (and build number)
8
JDK version
21
OS
N/A
Database
No response
Problem Description
MicroProfile JWT mechanism in GlassFish is implemented via Jakarta Security auth mechanism, JWTAuthenticationMechanism.
This issue is to request support for injecting this mechanism. I suggest 2 options, I think both could be supported:
- Using the
@Named
qualifier, so that the mechanism can be injected via the standard API, although it's not type safe:
@Inject @Named("jwtAuthenticationMechanism")
HttpAuthenticationMechanism jwtAuth;
- Using a new qualifier and annotation literal, exposed via a custom API:
@Inject @JwtAuthenticationMechanism
HttpAuthenticationMechanism jwtAuth;
GlassFish 8 and Jakarta EE 11 come with a new feature - HttpAuthenticationMechanismHandler. This allows delegating to available mechanisms using custom rules. If it's possible to inject the built-in JWTAuthenticationMechanism, it would be possible to create a handler that uses JWT authentication for REST endpoints, and another authentication, e.g. form-based or OIDC, for web pages.
Steps to reproduce
This could be possible to implement a custom handler that decides whether to use form or jwt auth:
@ApplicationScoped
class CustomAuthenticationMechanismHandler implements HttpAuthenticationMechanismHandler {
@Inject @FormAuthenticationMechanism
HttpAuthenticationMechanism formAuth;
@Inject @JwtAuthenticationMechanism
HttpAuthenticationMechanism jwtAuth;
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext context) throws AuthenticationException {
if (isRestRequest(request)) {
return jwtAuth.validateRequest(request, response, context);
} else {
return formAuth.validateRequest(request, response, context);
}
}
};
Impact of Issue
No response