[keycloak-user] How to get current user in my application

Alexander Chriztopher alexander.chriztopher at gmail.com
Wed Oct 8 06:28:09 EDT 2014


Hi,

Am using Keycloak with my JEE 7 application deployed on Wildfly.

I would like to get a handle on the currently authenticated user by doing
this :

*import* javax.ejb.LocalBean;

*import* javax.faces.bean.SessionScoped;

*import* javax.inject.Named;

*import* javax.ws.rs.core.Context;

*import* javax.ws.rs.core.SecurityContext;

*import* org.keycloak.KeycloakPrincipal;

@LocalBean

@Named

@SessionScoped

*public* *class* SessionController {

 @Context

*private* SecurityContext securityContext;

 *public* *void* method() {

KeycloakPrincipal *principal* = (KeycloakPrincipal)securityContext.
*getUserPrincipal*();

}

}

Unfortunately i get a NullPointerException on the call to securityContext.

Am i doing things right ? Shouldn't i get a security context this way ?

Thanks for any help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20141008/e8a81f68/attachment.html 


More information about the keycloak-user mailing list