11

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.

Community
  • 1
  • 1
alfonx
  • 6,936
  • 2
  • 49
  • 58
  • 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 http://tomcat.apache.org/tomcat-6.0-doc/config/context.html – alfonx Dec 03 '10 at 11:42

1 Answers1

12

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.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • 7
    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. – Raphael Jolivet Mar 16 '11 at 16:50