简体   繁体   English

需要帮助在Tomcat中设置多个领域

[英]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. 我正在尝试在tomcat中设置两个领域,并且由于某种原因它不会让我。 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. 我想使用标准的UserDatabaseRealm(conf / tomcat-users.xml)来执行管理工作(比如部署webapps),但我想要一个自定义域来为特定的webapp进行身份验证。

So, I tried putting this in the context of my webapp: 所以,我尝试将其放在我的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: 这只是server.xml中的一个副本,其中包含一些更改:

  • The name is changed to CustomDatabase from UserDatabase. 该名称从UserDatabase更改为CustomDatabase。

  • 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. 我尝试使用GlobalNamingResources标记包装资源以及是否存在相同的错误。

  • I've tried changing the auth attribute of the Resource to both Container and Application and get the same error. 我已经尝试将Resource的auth属性更改为Container和Application并获得相同的错误。

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. 谷歌的所有帮助主要是人们弄乱他们的主要领域(我的很好)不试图配置第二个领域。

You may use org.apache.catalina.realm.CombinedRealm . 您可以使用org.apache.catalina.realm.CombinedRealm From the Tomcat documentation : 从Tomcat 文档

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

So, I don't have a real answer, but I'll explain what I did. 所以,我没有真正的答案,但我会解释我做了什么。

I wasn't able to get the second UserDatabaseRealm working, but I really just needed two realms for testing, and it didn't matter the type (eventually, the second realm would be LDAP). 我无法使第二个UserDatabaseRealm工作,但我真的只需要两个领域进行测试,并且它与类型无关(最终,第二个领域将是LDAP)。

So I was looking at the available realms and chose a MemoryRealm for my secondary test realm and it worked just as it should have. 所以我正在查看可用的领域,并为我的辅助测试领域选择了一个MemoryRealm,它的工作原理应该如此。 I then made it a LDAP realm and that also worked fine. 然后我把它变成了一个LDAP领域,并且工作正常。

So, sorry to those that actually need two UserDatabaseRealms, I don't have a solution for you. 所以,对于那些实际需要两个UserDatabaseRealms的人,很抱歉,我没有适合您的解决方案。

NOTE: It's strange that the UserDatabaseRealm uses JNDI and the JNDIRealm is used for LDAP (and from what I can tell, JDNI isn't involved). 注意:奇怪的是UserDatabaseRealm使用JNDI而JNDIRealm用于LDAP(从我可以看出,JDNI不参与)。 I'm sure this is just some legacy naming problem, but it's confusing. 我确信这只是一些传统的命名问题,但它令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 需要帮助来建立信任库的权限链(在Tomcat中) - Need help setting up a truststore's chain of authority (in Tomcat) 需要帮助设置ActiveDirectoryLdapAuthenticationProvider的属性 - Need help setting up properties for ActiveDirectoryLdapAuthenticationProvider 多个领域 - Multiple realms 需要帮助从头开始设置具有多个 .java 文件的 intellij java 项目 - Need help setting up intellij java project with multiple .java files from scratch 需要帮助来设置具有网格和可点击项的GUI - Need help setting up GUI featuring grid and clickable items 需要帮助第一次使用java在eclipse上设置SQLite - need help setting up SQLite on eclipse with java for the first time 在Fragment中设置代码时需要帮助(Android开发) - Need help in setting up code in Fragment (Android Development) 需要一些帮助来在Java上为Cassandra设置Spark - Need some help on setting up spark for cassandra on java 需要一些帮助来设置JavaFX应用程序中的线程 - Need some help setting up threading in a javafx app 需要帮助来设置application.properties /休眠和弹簧类 - Need help setting up application.properties / hibernate and spring classes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM