Hi, I am attempting to implement the OIDC client in an application which utilizes the
RolesAllowed annotation to secure EJBs, and this does not seem to recognize the roles configured on the Keycloak JWT. I am wondering if there is a way to configure Elytron and/or Keycloak so that the token's roles can be checked by this annotation, or if this is a feature which would need to be added to Wildfly. Here are some more details:
standalone.xml configuration snippet:
<subsystem xmlns="urn:wildfly:elytron-oidc-client:1.0">
<secure-deployment name="DEPLOYMENT_NAME.war">
<bearer-only>true</bearer-only>
<client-id>account</client-id>
<principal-attribute>preferred_username</principal-attribute>
<provider-url>http://localhost:8080/realms/test-realm</provider-url>
<ssl-required>external</ssl-required>
<use-resource-role-mappings>true</use-resource-role-mappings> </secure-deployment>
</subsystem>
JWT snippet:
"realm_access": {
"roles": [
"READ",
"default-roles-test-realm",
"offline_access",
"uma_authorization"
]
},
"resource_access": {
"account": {
"roles": [
"manage-account",
"manage-account-links",
"view-profile"
]
}
},
"Roles": [
"READ",
"default-roles-test-realm",
"offline_access",
"uma_authorization"
],
"preferred_username": "test",
The DEPLOYMENT_NAME in the config above contains a servlet which references an EJB that is in a separate war/ear, so we are using identity propagation, which seems to be working to an extent:
- In the servlet itself, HttpServletRequest.isUserInRole works (i.e. it returns true when the JWT includes the correct role)
- However, in the EJB, using @RolesAllowed blocks access for the same JWT and role ("Invocation on method ... is not allowed")
- When the annotation is removed, from within the context of the EJB method, SessionContext.isCallerInRole does not work (i.e. it returns false even when HttpServletRequest.isUserInRole returns true in the servlet)
- However, SessionContext.getCallerPrincipal does work in the EJB, so the context is at least partially aware of the propagated identity
In this case, securing the EJB using something other than @RolesAllowed would be very difficult, so I am hoping for a solution that would involve updating only the OIDC config and/or the token claims, which we have full control over. Any insight on this?