0

I'm having a similar issue here: Configuring jdbcRealm in context.xml

Example configuration - My realm is nested in the context because I want it to be specific to the web application.

<Context>
    <Realm className="org.apache.catalina.realm.JDBCRealm" debug="9"
           connectionName="username"
           connectionPassword="password"
           connectionURL="url"
           driverName="com.ibm.db2.jcc.DB2Driver"
           roleNameCol="PERMISSION"
           userCredCol="PASSWORD"
           userNameCol="USERID"
           userRoleTable="ROLESTABLE"
           userTable="USERSTABLE"/>
</Context>

The solution was to put the driver jar into tomcat/lib folder. If I put the db2 driver jar in that folder it works.

However, I would like to load the jar from the application/WEB-INF/lib so that I don't have to make changes to the Tomcat installation. The jar is there, but the authenticator can't seem to locate it.

Thanks!

Community
  • 1
  • 1
Alex
  • 1
  • 1
  • Is there an urgent reason not to put the jar in `tomcat/lib`, other than not wanting to change the Tomcat installation? Usually indeed you would not want to throw any jar in there, but for JDBC drivers it is common practice, even advised to do so: http://stackoverflow.com/questions/6981564/why-must-the-jdbc-driver-be-put-in-tomcat-home-lib-folder – Richard Osseweyer Nov 06 '15 at 08:10
  • 1
    We wanted to be able to deploy our application without having to configure tomcat. This makes it easier for our developers to QA on their local machines. We also don't want to replace the driver jar on every single tomcat every time there is an update. – Alex Nov 10 '15 at 17:35

1 Answers1

0

After tinkering around, I found a solution. The DB is resourced and the realm references that resource instead of specifying the JDBCRealm itself. The following context.xml goes in the META-INF folder of the web app.

<Context>
    <Resource name="jdbc/DBNAME"
          auth="Container"
          type="javax.sql.DataSource"
          factory="org.apache.commons.dbcp.BasicDataSourceFactory"
          maxActive="25"
          maxWait="30000"
          username="USERNAME"
          password="PASSWORD"
          driverClassName="DRIVER"
          url="URL"
          removeAbandoned="true"
          logAbandoned="true"
          validationQuery="select * from test"
          testOnBorrow="true"
          testWhileIdle="true"
          timeBetweenEvictionRunsMillis="1800000"
        />
    <Realm className="org.apache.catalina.realm.DataSourceRealm"
       dataSourceName="jdbc/DBNAME"
       localDataSource="true"
       roleNameCol="PERMISSION"
       userCredCol="PASSWORD"
       userNameCol="USERID"
       userRoleTable="ROLESTABLE"
       userTable="USERSTABLE"/>
</Context>

Thanks!

Alex
  • 1
  • 1