Wildfly 26.1.1 + keycloak 18 + OIDC sessionContext.getCallerPrincipal() returns anonymous

Viewed 242

We are moving to Wildfly 26 from v.22. Using Keycloak v18 for authentication.

I switched from keycloak adapter to openid-connect/OIDC following http://www.mastertheboss.com/jbossas/jboss-security/secure-wildfly-applications-with-openid-connect/

After login I get org.wildfly.security.http.oidc.OidcSecurityContext as http request attribute and I can see an authenticated user name and the roles.

But when I inject @Resource SessionContext in Stateless bean, sessionContext.getCallerPrincipal() is returned as org.wildfly.security.auth.principal.AnonymousPrincipal. Keycloak adapter used to return a KeycloakPrincipal with full info.

Any other configuration needed to propagate security to EJB level?

Might be similar to Wildfly 26.1.0 final + elytron-oidc-client + wont propagate user to EJB + user become anonymous but I have everyting in a single WAR - just a servlet and a Stateless bean

Thanks

1 Answers

As long as the EJB is part of the same deployment, the identity will be propagated. However, the EJB does need to be secured (i.e., it needs to have a security annotation).

Related