How to define Tomcat security Realms per webapp
Asked Answered
C

1

12

When using JAAS JDBCRealms with Tomcat, I usually define the realm in server.xml. But now I am looking for a simpler solution, where I don't have to configure the Tomcat container when deploying the application.

If possible, I would like to keep all the JAAS configuration in web.xml and just define the realm per application/webapp.

One thread mentions that he did this by defining the realm in META-INF/context.xml of the webapp.. but I could not get it working (Why is Tomcat manager using my LoginModule?).

Please help me find the correct location in the .war to define a org.apache.catalina.realm.JDBCRealm that is then used for that webapp.

Curtice answered 3/12, 2010 at 11:28 Comment(1)
Maybe I found the solution: Only if a context file does not exist for the application in the $CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase. from tomcat.apache.org/tomcat-6.0-doc/config/context.htmlCurtice
E
13

To define your own JDBCRealm, create a META-INF/context.xml in your own web application.

Configure your JDBCRealm according to the specification based on your Tomcat Server versions:

These links shows you exactly how to configure JDBCRealm.

Endodermis answered 3/12, 2010 at 11:52 Comment(1)
Arrg! I just saw that a custom realm implementation must be accessible in CATALINA_HOME, not only from the JARs of my web app. This sucks. I don't understand the point of being able to define custom / per Webapp Realm if it has to be deployed on the whole Tomcat installation anyway.Farmer

© 2022 - 2024 — McMap. All rights reserved.