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.