1
votes

The DB is : MSSQL 2008 R2 OS= Windows Server 2008 R2

Global Resource in server.xml is:

<Resource name="data source name" auth="Container"  type="javax.sql.DataSource" username="myuser" password="abc@xyz"  driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://host:1433;databaseName=test1;selectMethod=cursor"  maxWait="30000" maxActive="32" maxIdle="4" initialSize="4"  timeBetweenEvictionRunsMillis="600000" minEvictableIdleTimeMilllis="600000" />
  </GlobalNamingResources>

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>

Are the resource values conflicting or is there any other issue ? I have also tried adding tomcat user file in Resource name tag but won't work either. I have also defined data source name in context.xml file.

The error log is:

Mar 12, 2014 5:19:53 PM org.apache.catalina.realm.UserDatabaseRealm startInternal SEVERE: Exception looking up UserDatabase under key UserDatabase javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context. Unable to find [UserDatabase]. at org.apache.naming.NamingContext.lookup(NamingContext.java:819) at org.apache.naming.NamingContext.lookup(NamingContext.java:167) at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:253) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201) at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Catalina.start(Catalina.java:689) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)

Mar 12, 2014 5:19:53 PM org.apache.catalina.realm.CombinedRealm startInternal SEVERE: Failed to start "org.apache.catalina.realm.UserDatabaseRealm/1.0" realm org.apache.catalina.LifecycleException: Failed to start component [Realm[UserDatabaseRealm]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201) at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Catalina.start(Catalina.java:689) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455) Caused by: org.apache.catalina.LifecycleException: No UserDatabase component found under key UserDatabase at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 17 more

1
I feel there is a problem with your resource name it should be only one wordankit
It is actually one word I intentionally replaced it when posting the question.user3410549
Could you share your context.xml? And, if you want to use MSSQL to authenticate users, use DataSource Database Realm.Shinichi Kai
Thanks. I have added a <ResourceLink global="data source name" name="data source name" /> in addition. No other entries.user3410549

1 Answers

1
votes

You have broken your server.xml. If you have a <Realm> pointing to "UserDatabase", then you need to have a <Resource> called "UserDatabase". Here is the default configuration:

<Resource name="UserDatabase" auth="Container"
          type="org.apache.catalina.UserDatabase"
          description="User database that can be updated and saved"
          factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
          pathname="conf/tomcat-users.xml" />

If you want to use your relational database for your <Realm>, then you need to change the configuration to point to that instead, and you need to use a DataSourceRealm instead.