<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 5 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:Monaco;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hello Tero, I have found my answer. Thanks to the Lead from a friend <b>@Edem_Morny</b>. 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.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b><span style='color:#44546A'>FacesContext context = FacesContext.getCurrentInstance();<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>KeycloakSecurityContext session = (KeycloakSecurityContext) ((HttpServletRequest) context.getExternalContext()<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'> .getRequest()).getAttribute(KeycloakSecurityContext.class.getName());</span></b></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>So this works for me now. Thanks greatly for your time.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986">Mail</a> for Windows 10</p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='border:none;padding:0in'><b>From: </b><a href="mailto:Tero.Ahonen@cybercom.com">Tero Ahonen</a><br><b>Sent: </b>Friday, February 5, 2016 11:07 AM<br><b>To: </b><a href="mailto:pkkamos@gmail.com">PAA KOJO KONDUAH AMOS</a><br><b>Cc: </b><a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br><b>Subject: </b>Re: [keycloak-user] Retrieving Logged In User Information.</p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>What request.getRemoteUser() returns? </span><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p></o:p></span></p><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>.t<o:p></o:p></span></p><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>On 05 Feb 2016, at 12:45 PM, PAA KOJO KONDUAH AMOS <<a href="mailto:pkkamos@gmail.com">pkkamos@gmail.com</a>> wrote:<o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><div><div><p class=MsoNormal>Hi, This is my auth-constraint definition in my web.xml<o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'><security-constraint></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> <web-resource-collection></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> <web-resource-name>keyconnect</web-resource-name></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> <url-pattern>/*</url-pattern></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> </web-resource-collection></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> <auth-constraint></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> <role-name>customer</role-name></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> </auth-constraint></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> <user-data-constraint></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> <transport-guarantee>CONFIDENTIAL</transport-guarantee></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> </user-data-constraint></span></b><o:p></o:p></p></div><div><p class=MsoNormal><b><span style='color:#44546A'> </security-constraint></span></b><o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>So, this is fine. Works well for me. I just want to after a successful login….retrieve the User who logged in.<o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal>Sent from<span class=apple-converted-space> </span><a href="https://go.microsoft.com/fwlink/?LinkId=550986"><span style='color:#954F72'>Mail</span></a><span class=apple-converted-space> </span>for Windows 10<o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><div><p class=MsoNormal><b>From:<span class=apple-converted-space> </span></b><a href="mailto:Tero.Ahonen@cybercom.com"><span style='color:#954F72'>Tero Ahonen</span></a><br><b>Sent:<span class=apple-converted-space> </span></b>Friday, February 5, 2016 10:37 AM<br><b>To:<span class=apple-converted-space> </span></b><a href="mailto:pkkamos@gmail.com"><span style='color:#954F72'>PAA KOJO KONDUAH AMOS</span></a><br><b>Cc:<span class=apple-converted-space> </span></b><a href="mailto:sthorger@redhat.com"><span style='color:#954F72'>Stian Thorgersen</span></a>;<span class=apple-converted-space> </span><a href="mailto:keycloak-user@lists.jboss.org"><span style='color:#954F72'>keycloak-user@lists.jboss.org</span></a><br><b>Subject:<span class=apple-converted-space> </span></b>Re: [keycloak-user] Retrieving Logged In User Information.<o:p></o:p></p></div></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Hi,</span><o:p></o:p></p></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Do u have auth-contraint in web.xml?<span class=apple-converted-space> </span></span><o:p></o:p></p></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#009193'><</span><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#4E9192'>auth-constraint</span><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#009193'>></span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif'> <span style='color:#009193'><</span><span style='color:#4E9192'>role-name</span><span style='color:#009193'>></span>somerolehere<span style='color:#009193'></</span><span style='color:#4E9192'>role-name</span><span style='color:#009193'>></span></span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#009193'></</span><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#4E9192'>auth-constraint</span><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#009193'>></span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#4E9192'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>If there is not required role then no auth is needed.</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>.t</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>On 05 Feb 2016, at 12:29 PM, PAA KOJO KONDUAH AMOS <<a href="mailto:pkkamos@gmail.com"><span style='color:#954F72'>pkkamos@gmail.com</span></a>> wrote:</span><o:p></o:p></p></div></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div><div><div><div><p class=MsoNormal>Hello Stian, my reponse in blue below.<o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Did you actually add @SecurityDomain("keycloak")?</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><b><span style='font-size:12.0pt;font-family:"Times New Roman",serif;color:#44546A'>YES.</span></b><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Does the request require authentication (does it have a security-constraint in web.xml)? </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal><b><span style='font-size:12.0pt;font-family:"Times New Roman",serif;color:#44546A'>YES</span></b><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>; The request say<span class=apple-converted-space> </span><a href="http://ip:port/context/index.html"><span style='color:#954F72'>http://ip:port/context/index.html</span></a><span class=apple-converted-space> </span>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.</span><o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><div><p class=MsoNormal>Sent from<span class=apple-converted-space> </span><a href="https://go.microsoft.com/fwlink/?LinkId=550986"><span style='color:#954F72'>Mail</span></a><span class=apple-converted-space> </span>for Windows 10<o:p></o:p></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><div><div><p class=MsoNormal><b>From:<span class=apple-converted-space> </span></b><a href="mailto:sthorger@redhat.com"><span style='color:#954F72'>Stian Thorgersen</span></a><br><b>Sent:<span class=apple-converted-space> </span></b>Friday, February 5, 2016 9:53 AM<br><b>To:<span class=apple-converted-space> </span></b><a href="mailto:pkkamos@gmail.com"><span style='color:#954F72'>PAA KOJO KONDUAH AMOS</span></a><br><b>Cc:<span class=apple-converted-space> </span></b><a href="mailto:keycloak-user@lists.jboss.org"><span style='color:#954F72'>keycloak-user@lists.jboss.org</span></a><br><b>Subject:<span class=apple-converted-space> </span></b>Re: [keycloak-user] Retrieving Logged In User Information.<o:p></o:p></p></div></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Did you actually add @SecurityDomain("keycloak")?</span><o:p></o:p></p></div></div><div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div></div><div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Does the request require authentication (does it have a security-constraint in web.xml)? </span><o:p></o:p></p></div></div></div></div><div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>On 5 February 2016 at 10:41, PAA KOJO KONDUAH AMOS <<a href="mailto:pkkamos@gmail.com" target="_blank"><span style='color:#954F72'>pkkamos@gmail.com</span></a>> wrote:</span><o:p></o:p></p></div></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'><div><div><div><div><p class=MsoNormal>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;<o:p></o:p></p></div></div><p class=MsoNormal> </p><pre><b><i><span style='color:#44546A'>@SecurityDomain("keycloak")</span></i></b></pre><div><p class=MsoNormal> <o:p></o:p></p></div><div><pre style='background:#EEEEEE;background-position:initial initial;background-repeat:initial initial'><b><i><span style='font-family:Consolas;color:#44546A;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE'>@Context</span></i></b><o:p></o:p></pre><pre style='background:#EEEEEE;background-position:initial initial;background-repeat:initial initial'><b><i><span style='font-family:Consolas;color:#44546A;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE'>SecurityContext sc;</span></i></b></pre></div><p class=MsoNormal> </p><div><div><p class=MsoNormal>And<span class=apple-converted-space> </span><o:p></o:p></p></div></div><pre><b><i><span style='color:#44546A'>KeycloakPrincipal principal = (KeycloakPrincipal) sc.getUserPrincipal();</span></i></b></pre><pre><b><i><span style='color:#44546A'> </span></i></b></pre><pre><b><i><span style='color:#44546A'> </span></i></b></pre><pre><b><i><span style='color:#44546A'> </span></i></b></pre><div><div><p class=MsoNormal><b>But the above line is returning a NullPointerException</b><b><span style='font-size:12.0pt'>.</span></b><o:p></o:p></p></div></div><pre><b><i> </i></b></pre><div><p class=MsoNormal><span style='font-size:12.0pt'>I must say, I have already done the required configuration; as in<span class=apple-converted-space> </span></span><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>enabling the Keycloak Subsystem within my app server's server configuration: </span><code><span style='font-size:10.0pt'>standalone.xml</span></code><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>.</span><o:p></o:p></p></div><div><div><p class=MsoNormal>Please any lead on how to retrieve the logged in User via KeyCloak?<o:p></o:p></p></div></div><p class=MsoNormal> </p><p class=MsoNormal> </p><div><div><p class=MsoNormal>Sent from<span class=apple-converted-space> </span><a href="https://go.microsoft.com/fwlink/?LinkId=550986" target="_blank"><span style='color:#954F72'>Mail</span></a><span class=apple-converted-space> </span>for Windows 10<o:p></o:p></p></div></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span></p></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><br>_______________________________________________<br>keycloak-user mailing list<br><a href="mailto:keycloak-user@lists.jboss.org"><span style='color:#954F72'>keycloak-user@lists.jboss.org</span></a><br><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank"><span style='color:#954F72'>https://lists.jboss.org/mailman/listinfo/keycloak-user</span></a></span><o:p></o:p></p></div></div></blockquote></div></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'> </span><o:p></o:p></p></div></div><div><div><p class=MsoNormal> <o:p></o:p></p></div></div><div><p class=MsoNormal><span style='font-size:9.0pt;font-family:"Helvetica",sans-serif'>_______________________________________________<br>keycloak-user mailing list<br><a href="mailto:keycloak-user@lists.jboss.org"><span style='color:#954F72'>keycloak-user@lists.jboss.org</span></a><br><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user"><span style='color:#954F72'>https://lists.jboss.org/mailman/listinfo/keycloak-user</span></a></span><o:p></o:p></p></div></div></blockquote></div></div></div></blockquote></div></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p> </o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>