<div dir="ltr">Great ! Works nicely !<div><br></div><div>Thank you Bill.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 31, 2014 at 8:10 PM, Bill Burke <span dir="ltr">&lt;<a href="mailto:bburke@redhat.com" target="_blank">bburke@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You should be able to typecast Principal to KeycloakPrincipal.<br>
<div><div class="h5"><br>
On 10/31/2014 2:27 PM, Alexander Chriztopher wrote:<br>
&gt; Hi All,<br>
&gt;<br>
&gt; Am trying to get the name and surname of the currently connected user by<br>
&gt; doing this :<br>
&gt;<br>
&gt; import java.io.Serializable;<br>
&gt; import java.security.Principal;<br>
&gt;<br>
&gt; import javax.annotation.Resource;<br>
&gt; import javax.annotation.security.RolesAllowed;<br>
&gt; import javax.ejb.EJBContext;<br>
&gt; import javax.ejb.LocalBean;<br>
&gt; import javax.ejb.Stateless;<br>
&gt;<br>
&gt; import org.jboss.ejb3.annotation.SecurityDomain;<br>
&gt;<br>
&gt;<br>
&gt; @Stateless(name=&quot;myEJB&quot;)<br>
&gt; @LocalBean<br>
&gt; @SecurityDomain(&quot;keycloak&quot;)<br>
&gt; public class MyEJB implements Serializable {<br>
&gt;<br>
&gt;      private static final long serialVersionUID = 1L;<br>
&gt;<br>
&gt;      @Resource<br>
&gt;      private EJBContext ejbContext;<br>
&gt;      @RolesAllowed(&quot;ADMIN&quot;)<br>
&gt;      public void test() {<br>
&gt;          Principal principal = ejbContext.getCallerPrincipal();<br>
&gt;          System.out.println(&quot;principal.getName() = &quot; + principal.getName());<br>
&gt;      }<br>
&gt; }<br>
&gt;<br>
&gt; This works nicely as i get a 403 if my currently connected user does<br>
&gt; have the role : ADMIN.<br>
&gt;<br>
&gt; My question is : does keycloak propagate the username or any other<br>
&gt; information that would help me get the first name and last name of the<br>
&gt; currently connected user ? Unfortunately, principal.getName() returns a<br>
&gt; string like this : edd42240-85bf-4724-8d79-5374338506b7 which i don&#39;t<br>
&gt; know the interpretation !<br>
&gt;<br>
&gt; Thanks for any help.<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; keycloak-user mailing list<br>
&gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt;<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Bill Burke<br>
JBoss, a division of Red Hat<br>
<a href="http://bill.burkecentral.com" target="_blank">http://bill.burkecentral.com</a><br>
_______________________________________________<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" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</font></span></blockquote></div><br></div>