[keycloak-user] @Inject KeycloakPrincipal in EJB container

Vagelis Savvas vagelis.savvas at gmail.com
Sat Oct 26 14:40:08 EDT 2019


Dear community,
as the subject says, how can the org.keycloak.KeycloakPrincipal be 
@Inject-ed in say a @Stateless bean?
I tried injecting a java.security.Principal but I couldn't get a 
KeycloakPrincipal out of it.
I also tried creating a CDI @Producer (annotated with @RequestScoped) 
producing the KeycloakPrincipal
but that didn't work either because KeycloakPrincipal can't be proxied.

(That's mostly for convenience since @Resource SessionContext ctx and 
then ctx.getCallerPrincipal()
answers the KeycloakPrincipal but I wouldn't want to do that explicitly 
in every business method)

This is on 17.0.1 Wildfly with the Elytron Keycloak adapter.

Cheers,
Vagelis



More information about the keycloak-user mailing list