Get all users and roles in Java webapp
Question:
>Is there a general role for user and concept servlet containers? > If so, is there a container independent way to access these users and roles? > If not, is there any way to access the Tomcat realm user & role?
Background:
I want to get all users and their roles from the Java webapp context (servlet container), or better, query users and their roles directly
I see a project like Apache directory. If you know the connection string, you can let it perform this operation for LDAP However, I hope I don't understand the technology of providing users and roles
Specifically, I am on Tomcat and want to access users in the simplest scenario & A) Tomcat users Role in XML b) any other configured domain in the context However, I am really looking for a solution that is not specific to Tomcat and its domain
Solution
In Tomcat (or any other conytainer) (using std.servlet API), it is impossible to directly access the user role (without using Tomcat / third-party specific mechanism) Getuserprincipal & isuserinrole are two methods. It is not directly possible to access the role list
Since the API does not provide such access, I guess you will have to rely on other container or technology - specific mechanisms
As you pointed out, if the configured realm is a JNDI realm and the realm store is implemented through LDAP, you can write servlet filters and get roles from LDAP and set them on the session or local thread