Based on other postings on SO and the web, it would appear that there is no built-in mechanism in a Servlet 3+ container to retrieve the roles from a logged in user, but rather only to check if a user is in a role: request.isUserInRole(String)
But is there any way to retrieve the security-role list as defined for the application?
I find it strange that a LoginModule must persist the principal's credentials but there is nothing defined/related to a principal's roles. At some point, when you call isInRole()
, the container must be able to check the list of the user's assigned roles. Is that information not exposed anywhere?
I cannot seem to find any mechanism which allows me to retrieve the defined roles from my deployment descriptor (or via annotations). I'm targeting Wildfly 10/Undertow, but ideally looking for a container agnostic solution.
Is this even feasible? Is there any easy way to programatically retrieve the security-role
s defined in my application (either as defined in my descriptor or via @DeclareRoles annotations)?