6

While staring the Tomcat, I am getting the following error:

SEVERE: Exception looking up UserDatabase under key UserDatabase
javax.naming.NameNotFoundException: Name UserDatabase is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.catalina.realm.UserDatabaseRealm.start(UserDatabaseRealm.java:253)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1049)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Jul 6, 2012 4:32:25 PM org.apache.catalina.startup.Catalina start

SEVERE: Catalina.start: 
LifecycleException:  No UserDatabase component found under key UserDatabase
at org.apache.catalina.realm.UserDatabaseRealm.start(UserDatabaseRealm.java:261)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1049)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

I used the same dB configuration before in Server.xml and Tomcat was working fine, but since last 2 days when I change the server and install a new copy, it's throwing this error.

The GlobalNamingResources defined in server.xml are as follows:

<GlobalNamingResources>
<Resource name="jdbc/abcdOracle" auth="Container"
type="javax.sql.DataSource" 
maxActive="100" initialSize="5" maxWait="2000" 
username="xxxxxx" password="xxxxxx" 
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@xxxxxx.xxxxxx.net:1523:ABCDE"
validationQuery="select sysdate from dual" 
validationInterval="30000"
testWhileIdle="true" testOnBorrow="true" testOnReturn="false"
removeAbandoned="true" logAbandoned="true"
removeAbandonedTimeout="60" /> 
</GlobalNamingResources>

Anyone have any hint how to solve this issue. Thanks.

smcg
  • 3,195
  • 2
  • 30
  • 40
user1417746
  • 191
  • 2
  • 3
  • 11

8 Answers8

7

I've got this issue caused by XML syntax errors in my tomcat-users.xml. Though these erros are totally obvious, they took some time to be found out and fixed:

1. Invalid double quotes

  • Wrong: <role rolename=manager-script/>
  • Right: <role rolename="manager-script"/>

2. Missing close double quotes

  • Wrong: <user username="tomcat" password="tomcat" roles="manager-gui,manager-script/>
  • Right: <user username="tomcat" password="tomcat" roles="manager-gui,manager-script"/>

3. Missing close slash

  • Wrong: <role rolename="admin">
  • Right: <role rolename="admin"/>

4. Missing space between the attributes

  • Wrong: <user username="tomcat" password="tomcat"roles="manager-gui,manager-script"/>
  • Right: <user username="tomcat" password="tomcat" roles="manager-gui,manager-script"/>
Nikita Bosik
  • 851
  • 1
  • 14
  • 20
5

You have removed the tomcat-users.xml from $CATALINA_BASE/conf which is registered in JNDI as UserDatabase by default.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
5

I think you have removed below code from server.xml

<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" /> 

replace it

janakiram
  • 51
  • 2
3

Ensures that you have <?xml version="1.0" encoding="UTF-8"?>

  • 1
    Surprisingly, this was the issue for me. Installing the Tomcat 8.5 with the MSI installer on Windows 10, and the `tomcat-users.xml` was using encoding of `cp65001` instead `UTF-8`. – ku4eto Dec 17 '21 at 22:36
  • @ku4eto: Holy crap! After banging my head for hours, this was *exactly* the reason for my problems with freshly installed Tomcat 10.1 on Windows 10, as well! If it wasn't for your little comment here, that put me on the right track, I'd likely throw everything away from pure frustration, because it made zero sense for things not to be working! – aoven Jun 16 '23 at 16:54
2

Error in /var/log/tomcat6/catalina.out:

GRAVE: Catalina.start:
LifecycleException:  No UserDatabase component found under key UserDatabase

Verify the position of tomcat-users.xml:

# updatedb
# locate tomcat-users.xml
/etc/tomcat6/tomcat-users.xml

Open the /etc/tomcat6/server.xml and edit:

<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" /> 

by inserting a correct path to tomcat-users.xml file. In my case is:

pathname="tomcat-users.xml"
minja
  • 21
  • 1
1

This could also mean that you have an XML character in an attribute of your tomcat-users.xml file.

For example, I've seen this happen when I had a "<" character in the password field for a user in tomcat-users.xml

File excerpt:

/etc/tomcat6/tomcat-users.xml

<role rolename="manager"/>
<user username="admin" password="<password" roles="manager"/>
Brad Parks
  • 66,836
  • 64
  • 257
  • 336
1

In server.xml, the Resource element, or its parent GlobalNamingResources element isn't mandatory. You'll only have issues if you remove what the resources are accessing (e.g., tomcat-users.xml).

If you comment out the default GlobalNamingResources element, then make sure you scroll down in server.xml and remove the LockOutRealm as well. It uses the UserDatabase by default, specified in in the GlobalNamingResources.

Hal50000
  • 639
  • 1
  • 6
  • 16
0

In my case, after reviewing other solutions suggested before, I realized it was just a permissions issue. I just had to give ownership of the tomcat-users.xml file to the user running the tomcat process:

chown tomcat:tomcat $CATALINA_BASE/conf/tomcat-users.xml