I was wondering if it would be possible to retrieve the complete list of security roles defined in a web.xml file in the java code? And if so how to do it?
I am aware of the ‘isUserInRole’ method but I also want to handle cases where a role is requested but not defined (or spelled differently) in the web.xml file.
As far as I know, there’s no way do do this within the Servlet API. However, you can parse web.xml directly and extract the values yourself. I used dom4j below, but you can use whatever XML processing stuff you like: