我正在尝试在 Tomcat 7.0.32 中嵌套 Realms(此处用伪 XML 编写):
<CombinedRealm>
<LockoutRealm>
<DataSourceRealm/>
</LockoutRealm>
<UserDatabaseRealm/>
</CombinedRealm>
这似乎行不通 - 是否可以在 Tomcat 中嵌套多于两层的 Realm ?我在日志中收到警告:
No rules found matching 'Server/Service/Engine/Realm/Realm/Realm'.
背后的想法是 Web 服务有一些不能被锁定的关键用户(例如作为 DOS)和一些普通用户,这些用户的密码可能较弱,lockoutRealm 应该处于 Activity 状态。我敢肯定其他人也遇到过这种情况。
如果有其他方法可以实现此目的(例如 LockoutRealm 的白名单),请告诉我。
还需要单点登录。
我想用永不锁定的帐户列表扩展现有的 LockoutRealm 代码是一种选择,但我不太热衷于编写自己的 Realm,我宁愿不在该级别上向 Tomcat 添加自定义代码,因为这会使其他人的设置复杂化,并且每次 Tomcat 更新都可能会中断等。
感谢您的帮助!
这是我的测试配置的 server.xml 的相关部分:
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.CombinedRealm">
<!-- Lockout realm for the DB users -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- PRIMARY: DataSourceRealm with user DB -->
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/authority"
userTable="user" userNameCol="username"
userCredCol="password" digest="SHA"
userRoleTable="user_role" roleNameCol="rolename" />
</Realm>
<!-- FALLBACK:
This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
最佳答案
Apache commons-digester 用于解析配置文件,所以我怀疑这个特定用例根本出乎意料。
Tomcat 的 org.apache.catalina.startup.RealmRuleSet.addRuleInstances
似乎被操纵为只为 Realm
配置深入 2 级。似乎很简单,可以在其中添加另一层。
我必须查看如何配置摘要器以了解是否可以支持任意级别,或者是否必须手动配置某些子集。
随时前往 Tomcat users' list请求这样的改变。
关于java - Tomcat 7嵌套CombinedRealm、LockoutRealm和DataSourceRealm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13274696/