<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.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.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>Hi, This is my auth-constraint definition in my web.xml</p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><b><span style='color:#44546A'>&lt;security-constraint&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                           &lt;web-resource-collection&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                                         &lt;web-resource-name&gt;keyconnect&lt;/web-resource-name&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                                         &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                           &lt;/web-resource-collection&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                           &lt;auth-constraint&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                                         &lt;role-name&gt;customer&lt;/role-name&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                           &lt;/auth-constraint&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                           &lt;user-data-constraint&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                                         &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>                           &lt;/user-data-constraint&gt;<o:p></o:p></span></b></p><p class=MsoNormal><b><span style='color:#44546A'>              &lt;/security-constraint&gt;<o:p></o:p></span></b></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><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><p class=MsoNormal><o:p>&nbsp;</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>&nbsp;</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 10:37 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>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Hi,</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>&nbsp;</o:p></span></p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Do u have auth-contraint in web.xml? <o:p></o:p></span></p><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></p></div><div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#009193'>&lt;</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'>&gt;</span><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#4E9192'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif'>&nbsp;&nbsp;<span style='color:#009193'>&lt;</span><span style='color:#4E9192'>role-name</span><span style='color:#009193'>&gt;</span><span style='color:black'>somerolehere</span><span style='color:#009193'>&lt;/</span><span style='color:#4E9192'>role-name</span><span style='color:#009193'>&gt;</span><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#009193'>&lt;/</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'>&gt;</span><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#4E9192'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco",serif;color:#4E9192'><o:p>&nbsp;</o:p></span></p></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><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'><o:p>&nbsp;</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><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></p></div><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:29 PM, PAA KOJO KONDUAH AMOS &lt;<a href="mailto:pkkamos@gmail.com">pkkamos@gmail.com</a>&gt; 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>&nbsp;</o:p></span></p><div><div><p class=MsoNormal>Hello Stian, my reponse in blue below.<o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Did you actually add&nbsp;@SecurityDomain(&quot;keycloak&quot;)?</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>&nbsp;</span><o:p></o:p></p></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><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>&nbsp;</span><o:p></o:p></p></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)?&nbsp;</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>&nbsp;</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>&nbsp;</span><o:p></o:p></p></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>&nbsp;</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>&nbsp;</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><p class=MsoNormal>&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;<o:p></o:p></p></div><div><p class=MsoNormal>Sent from<span class=apple-converted-space>&nbsp;</span><a href="https://go.microsoft.com/fwlink/?LinkId=550986"><span style='color:#954F72'>Mail</span></a><span class=apple-converted-space>&nbsp;</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'>&nbsp;</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>&nbsp;</span></b><a href="mailto:sthorger@redhat.com"><span style='color:#954F72'>Stian Thorgersen</span></a><br><b>Sent:<span class=apple-converted-space>&nbsp;</span></b>Friday, February 5, 2016 9:53 AM<br><b>To:<span class=apple-converted-space>&nbsp;</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>&nbsp;</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>&nbsp;</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'>&nbsp;</span><o:p></o:p></p></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>Did you actually add&nbsp;@SecurityDomain(&quot;keycloak&quot;)?</span><o:p></o:p></p></div><div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>&nbsp;</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)?&nbsp;</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'>&nbsp;</span><o:p></o:p></p></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 &lt;<a href="mailto:pkkamos@gmail.com" target="_blank"><span style='color:#954F72'>pkkamos@gmail.com</span></a>&gt; wrote:</span><o:p></o:p></p></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><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><p class=MsoNormal>&nbsp;</p><pre><b><i><span style='color:#44546A'>@SecurityDomain(&quot;keycloak&quot;)</span></i></b></pre><p class=MsoNormal>&nbsp;<o:p></o:p></p><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>&nbsp;</p><div><p class=MsoNormal>And<span class=apple-converted-space>&nbsp;</span><o:p></o:p></p></div><pre><b><i><span style='color:#44546A'>KeycloakPrincipal principal = (KeycloakPrincipal) sc.getUserPrincipal();</span></i></b></pre><pre><b><i><span style='color:#44546A'>&nbsp;</span></i></b></pre><pre><b><i><span style='color:#44546A'>&nbsp;</span></i></b></pre><pre><b><i><span style='color:#44546A'>&nbsp;</span></i></b></pre><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><pre><b><i>&nbsp;</i></b></pre><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:12.0pt'>I must say, I have already done the required configuration; as in<span class=apple-converted-space>&nbsp;</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:&nbsp;</span><code><span style='font-size:10.0pt'>standalone.xml</span></code><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>.<o:p></o:p></span></p><div><p class=MsoNormal>Please any lead on how to retrieve the logged in User via KeyCloak?<o:p></o:p></p></div><p class=MsoNormal>&nbsp;</p><p class=MsoNormal>&nbsp;</p><div><p class=MsoNormal>Sent from<span class=apple-converted-space>&nbsp;</span><a href="https://go.microsoft.com/fwlink/?LinkId=550986" target="_blank"><span style='color:#954F72'>Mail</span></a><span class=apple-converted-space>&nbsp;</span>for Windows 10<o:p></o:p></p></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>&nbsp;</span></p></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></blockquote></div></div><div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'>&nbsp;</span><o:p></o:p></p></div><div><p class=MsoNormal>&nbsp;<o:p></o:p></p></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">keycloak-user@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></span><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p></o:p></span></p></div></blockquote></div></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman",serif'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>