Hi,
The last version of dropwizard-pac4j v7.0.0 is based on pac4j v5.x, not pac4j v6.x and I haven't tested it with pac4j v6.
To give you some feedback:
** In this scenario, I noticed that the requests coming in with bearer token (other than the initial /callback during oidc login) are authenticated without actually validating the bearer token.
-> The OIDC login process has saved the authenticated user and the JWT authn checks if there is an already authenticated user before performing the authn. So after an OIDC login process, the JWT authn will never really be performed.
So it's a matter of session, do you re-use the one used for the OIDC login process to perform the bearer calls?
Otherwise, you could block that in pac4j with setLoadProfilesFromSession(false).
I can add a DirectBearerAuthClient:
@Bean
public Config config() {
// configuration of the authentication via the OpenID Connect protocol
final var config = new OidcConfiguration()
.setDiscoveryURI("https://casserverpac4j.herokuapp.com/oidc/.well-known/openid-configuration")
.setClientId("myclient")
.setSecret("mysecret")
.setAllowUnsignedIdTokens(true);
final var oidcClient = new OidcClient(config);
final var bearerClient = new DirectBearerAuthClient(new JwtAuthenticator(new SecretSignatureConfiguration("whatever")));
final var clients = new Clients(baseUri + "/callback", oidcClient, bearerClient);
return new Config(clients);
}
And I update the security config (notice the shallow copy of the config and the setLoadProfilesFromSession(false) on a new DefaultSecurityLogic():
@Override
public void addInterceptors(final InterceptorRegistry registry) {
// the /protected/** URLs require the OIDC authentication
addSecurity(registry, "OidcClient").addPathPatterns("/protected/**");
final var newConfig = config().withSecurityLogic(new DefaultSecurityLogic().setLoadProfilesFromSession(false));
addSecurityWithConfig(registry, newConfig, "DirectBearerAuthClient").addPathPatterns("/rest/**");
}
I'm not sure this is feasible with dropwizard-pac4j though...
** the JwtAuthenticator should validate the exp claim. If not, please submit a PR with a test demonstrating the bug.
Thanks.
Best regards,
Jérôme