December 2019
Intermediate to advanced
314 pages
6h 51m
English
Before moving on to the next authentication schema, it's worth noting that you can determine the principal name and roles at runtime by injecting the SecurityIdentity interface that represents the currently logged-in user. In this short excerpt, we will learn how to retrieve and log the user that's connected, the name/surname they used to register, and the set of roles they are entitled to:
@Inject SecurityIdentity securityContext;@Inject CustomerRepository customerRepository;@GET@RolesAllowed("user")public List<Customer> getAll() { LOGGER.info("Connected with User "+securityContext.getPrincipal().getName()); Iterator<String> roles = securityContext.getRoles().iterator(); while (roles.hasNext()) ...
Read now
Unlock full access