我正在尝试为我的 Web 应用程序(JSF 2.1 + 休眠)设置容器管理安全 Realm 。我注意到 Tomcat 7 一次只能使用一种类型的 Realm 。
要在 netbeans (7.0) 中使用 Tomcat,我必须创建一个管理脚本角色帐户。除了与 Tomcat 管理器一起工作外,我还需要另一个角色。这对我来说是个大问题,因为我用于 JDBCRealm 的表是来自存储用户和角色的实际表的 View ,我不想将这两个角色存储在我的程序使用的同一个数据库中。
有没有办法让 JDBCRealm 和 UserDBRealm 一起工作?那将是一种解脱。
这是来自 server.config 的代码:
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost:3306/realm?user=login&password=pass"
userTable="users"
userNameCol="user_name"
userCredCol="user_pass"
userRoleTable="user_roles"
roleNameCol="role_name" />
tomcat 只使用他在文件中找到的最后一个。他们分开工作很好
最佳答案
Realm implementation that contains one or more realms. Authentication is attempted for each realm in the order they were configured. If any realm authenticates the user then the authentication succeeds. When combining realms usernames should be unique across all combined realms.
也许您已经在使用 LockOutRealm
(doc、javadoc),它是 CombinedRealm
的子类,并且在 Tomcat 的默认配置中。
关于security - Tomcat 7.11 JDBCRealm 和 UserDatabaseRealm 不能一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8053552/