<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"><<a href="mailto:bburke@redhat.com" target="_blank">bburke@redhat.com</a>></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>
> Hi All,<br>
><br>
> Am trying to get the name and surname of the currently connected user by<br>
> doing this :<br>
><br>
> import java.io.Serializable;<br>
> import java.security.Principal;<br>
><br>
> import javax.annotation.Resource;<br>
> import javax.annotation.security.RolesAllowed;<br>
> import javax.ejb.EJBContext;<br>
> import javax.ejb.LocalBean;<br>
> import javax.ejb.Stateless;<br>
><br>
> import org.jboss.ejb3.annotation.SecurityDomain;<br>
><br>
><br>
> @Stateless(name="myEJB")<br>
> @LocalBean<br>
> @SecurityDomain("keycloak")<br>
> public class MyEJB implements Serializable {<br>
><br>
> private static final long serialVersionUID = 1L;<br>
><br>
> @Resource<br>
> private EJBContext ejbContext;<br>
> @RolesAllowed("ADMIN")<br>
> public void test() {<br>
> Principal principal = ejbContext.getCallerPrincipal();<br>
> System.out.println("principal.getName() = " + principal.getName());<br>
> }<br>
> }<br>
><br>
> This works nicely as i get a 403 if my currently connected user does<br>
> have the role : ADMIN.<br>
><br>
> My question is : does keycloak propagate the username or any other<br>
> information that would help me get the first name and last name of the<br>
> currently connected user ? Unfortunately, principal.getName() returns a<br>
> string like this : edd42240-85bf-4724-8d79-5374338506b7 which i don't<br>
> know the interpretation !<br>
><br>
> Thanks for any help.<br>
><br>
><br>
</div></div>> _______________________________________________<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>
><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>