I'm trying to protect a resource in tomcat so that only "valid users" (those with a valid login and password in the realm) can access it. They do not necessarily belong to a group in the realm. I have tried with many combinations of the <security-constraint>
directive without success. Any ideas?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
There are several realm implementation in tomcat - memory, database, JAAS and more. The easiest one to configure (though not the most secure) the memory one, which contains a single XML file, usually under conf/tomcat-users.xml:
The realm configuration is under the context, host or engine configurations, like this:
Then, in the web.xml you put the following definition:
The web.xml part is taken (with slight change) from one of our web apps.
Besides the auth-constraint you are adding to the security-constraint:
you need specify the security role in the web-app:
If we are using Tomcat 8.x , as the provided server.xml will come in a nested Realm element, please add 'allRolesMode="authOnly"' in the "outmost" Realm element and change aforementioned web.xml for testing. e.g.
Please read org.apache.catalina.realm.RealmBase.java for details.
Also, following settings in logging.properties are useful.