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

Stian Thorgersen stian at redhat.com
Thu Oct 9 06:59:22 EDT 2014


Did you follow the steps in the documentation? Including creating a security-domain?

----- Original Message -----
> From: "Alexander Chriztopher" <alexander.chriztopher at gmail.com>
> To: "Stian Thorgersen" <stian at redhat.com>
> Cc: keycloak-user at lists.jboss.org
> Sent: Thursday, 9 October, 2014 12:28:47 PM
> Subject: Re: [keycloak-user] How to get current user in my application
> 
> Added : @SecurityDomain("keycloak") without any success ! Still getting a
> NullPointerException.
> 
> The security is now working effectively by adding the @SecurityDomain
> annotation as i had to add the annotation : @PermitAll on my methods to be
> able to access my methods.
> 
> Are my imports the right ones ? :
> 
> *import* javax.ws.rs.core.Context;
> 
> *import* javax.ws.rs.core.SecurityContext;
> 
> On Thu, Oct 9, 2014 at 10:54 AM, Stian Thorgersen <stian at redhat.com> wrote:
> 
> > See
> > http://docs.jboss.org/keycloak/docs/1.0.2.Final/userguide/html/ch07.html#jboss-adapter,
> > try adding @SecurityDomain("keycloak").
> >
> > ----- Original Message -----
> > > From: "Alexander Chriztopher" <alexander.chriztopher at gmail.com>
> > > To: keycloak-user at lists.jboss.org
> > > Sent: Wednesday, 8 October, 2014 12:28:09 PM
> > > Subject: [keycloak-user] How to get current user in my application
> > >
> > > 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.
> > >
> > > _______________________________________________
> > > keycloak-user mailing list
> > > keycloak-user at lists.jboss.org
> > > https://lists.jboss.org/mailman/listinfo/keycloak-user
> >
> 


More information about the keycloak-user mailing list