[keycloak-user] Retrieving Logged In User Information.

PAA KOJO KONDUAH AMOS pkkamos at gmail.com
Fri Feb 5 06:26:24 EST 2016


Hello Tero, I have found my answer. Thanks to the Lead from a friend @Edem_Morny. You see, I am using JSF(PrimeFaces) and so @Context HttpServletRequest didn’t work for me. Rather this worked. So rather than passing the HttpServletRequest using the @Context annotation, I obtain same via the FacesContext.

FacesContext context = FacesContext.getCurrentInstance();
KeycloakSecurityContext session = (KeycloakSecurityContext) ((HttpServletRequest) context.getExternalContext()
				.getRequest()).getAttribute(KeycloakSecurityContext.class.getName());


So this works for me now. Thanks greatly for your time.

Sent from Mail for Windows 10

From: Tero Ahonen
Sent: Friday, February 5, 2016 11:07 AM
To: PAA KOJO KONDUAH AMOS
Cc: Stian Thorgersen; keycloak-user at lists.jboss.org
Subject: Re: [keycloak-user] Retrieving Logged In User Information.

What request.getRemoteUser() returns? 

.t
On 05 Feb 2016, at 12:45 PM, PAA KOJO KONDUAH AMOS <pkkamos at gmail.com> wrote:

Hi, This is my auth-constraint definition in my web.xml
 
<security-constraint>
                           <web-resource-collection>
                                         <web-resource-name>keyconnect</web-resource-name>
                                         <url-pattern>/*</url-pattern>
                           </web-resource-collection>
                           <auth-constraint>
                                         <role-name>customer</role-name>
                           </auth-constraint>
                           <user-data-constraint>
                                         <transport-guarantee>CONFIDENTIAL</transport-guarantee>
                           </user-data-constraint>
              </security-constraint>
 
So, this is fine. Works well for me. I just want to after a successful login….retrieve the User who logged in.
 
Sent from Mail for Windows 10
 
From: Tero Ahonen
Sent: Friday, February 5, 2016 10:37 AM
To: PAA KOJO KONDUAH AMOS
Cc: Stian Thorgersen; keycloak-user at lists.jboss.org
Subject: Re: [keycloak-user] Retrieving Logged In User Information.
 
Hi,
 
Do u have auth-contraint in web.xml? 
 
<auth-constraint>
  <role-name>somerolehere</role-name>
</auth-constraint>
 
If there is not required role then no auth is needed.
 
.t
 
On 05 Feb 2016, at 12:29 PM, PAA KOJO KONDUAH AMOS <pkkamos at gmail.com> wrote:
 
Hello Stian, my reponse in blue below.
 
Did you actually add @SecurityDomain("keycloak")?
 
YES.
 
Does the request require authentication (does it have a security-constraint in web.xml)? 
 
 
YES; The request say http://ip:port/context/index.html will be routed to Keycloak for the rquester to login. On successful log-in the requester is redirected back to the index.html. It is at this point I want to retrieve or know who the User is.
 
 
Sent from Mail for Windows 10
 
From: Stian Thorgersen
Sent: Friday, February 5, 2016 9:53 AM
To: PAA KOJO KONDUAH AMOS
Cc: keycloak-user at lists.jboss.org
Subject: Re: [keycloak-user] Retrieving Logged In User Information.
 
Did you actually add @SecurityDomain("keycloak")?
 
Does the request require authentication (does it have a security-constraint in web.xml)? 
 
On 5 February 2016 at 10:41, PAA KOJO KONDUAH AMOS <pkkamos at gmail.com> wrote:
Hello, I am trying to retrieve information about the User logged into the webapp via keycloak. I have seen around information on using the following;
 
@SecurityDomain("keycloak")
 
@Context
SecurityContext sc;
 
And 
KeycloakPrincipal principal = (KeycloakPrincipal) sc.getUserPrincipal();
 
 
 
But the above line is returning a NullPointerException.
 
I must say, I have already done the required configuration; as in enabling the Keycloak Subsystem within my app server's server configuration: standalone.xml.
Please any lead on how to retrieve the logged in User via KeyCloak?
 
 
Sent from Mail for Windows 10
 

_______________________________________________
keycloak-user mailing list
keycloak-user at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/keycloak-user
 
 
_______________________________________________
keycloak-user mailing list
keycloak-user at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/keycloak-user


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160205/bcb1c9e5/attachment-0001.html 


More information about the keycloak-user mailing list