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