Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help setting up multiple Realms in Tomcat

I'm trying to set up two Realms in tomcat and it isn't letting me for some reason. I'd like to use the standard UserDatabaseRealm (conf/tomcat-users.xml) for doing admin things (like deploying webapps) but I'd like a custom realm for doing authentication for a specific webapp.

So, I tried putting this in the context of my webapp:

<Context>
  <GlobalNamingResources>
    <Resource name="CustomDatabase" auth="Container"
      type="org.apache.catalina.UserDatabase"
      description="User database that can be updated and saved"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
      pathname="/usr/java/apache-tomcat-6.0.35/conf/tomcat-users.xml" 
    />
  </GlobalNamingResources>
  <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
    resourceName="CustomDatabase"
   />
</Context>

Which is really just a copy of what is in server.xml with a couple changes:

  • The name is changed to CustomDatabase from UserDatabase.

  • The pathname is the absolute pathname (and the same I use for the main realm).

I always get this same error:

LifecycleException:  No UserDatabase component found under key CustomDatabase

And I don't know what it is telling me. What component is it talking about?

Along with the context above I've tried a couple other things, but it always gives the same error:

  • I've tried wrapping the Resource with the GlobalNamingResources tag and whether there or not same error.

  • I've tried changing the auth attribute of the Resource to both Container and Application and get the same error.

What am I missing? All the help from google is mostly people messing up their main realm (which mine is fine) not trying to configure a second realm.

like image 987
rjcarr Avatar asked Dec 09 '25 15:12

rjcarr


1 Answers

You may use org.apache.catalina.realm.CombinedRealm. From the Tomcat documentation:

<Realm className="org.apache.catalina.realm.CombinedRealm" >
  <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
         resourceName="UserDatabase"/>
  <Realm className="org.apache.catalina.realm.DataSourceRealm"
         dataSourceName="jdbc/authority"
         userTable="users" userNameCol="user_name" userCredCol="user_pass"
         userRoleTable="user_roles" roleNameCol="role_name"/>
</Realm>
like image 65
Peter Keller Avatar answered Dec 12 '25 09:12

Peter Keller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!