我正在尝试在 JBoss 6.1 Final 中使用自定义主体类。来自 the JBoss documentation看来我必须添加行
<principalClass="es.caib.gesma.browseldap.LdapPrincipal"/>
进入login-config.xml文件,但不清楚具体在哪里。我已经在应用程序策略定义中的几个位置进行了尝试,但它总是会导致抛出异常。
我尝试过的地方(一次一个)是:
<application-policy name="GesManPolicy">
<----- Here
<authentication>
<----- Here
<login-module code="es.caib.gesma.browseldap.BrowseLdapLoginModule" flag="required">
<----- And here
<module-option name="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</module-option>
...
我每次遇到的异常是
10:17:05,359 WARN [XMLLoginConfigImpl] End loadConfig, failed to load config: vfs:/C:/desarrollo/jboss-6.1.0.Final/server/default/conf/login-config.xml:
org.jboss.security.auth.login.ParseException: Encountered " <ANY> "<?xml "" at line 1, column 1. Was expecting one of:
<EOF>
<IDENTIFIER> ...
at org.jboss.security.auth.login.SunConfigParser.generateParseException(SunConfigParser.java:415) [:3.0.0.CR2]
at org.jboss.security.auth.login.SunConfigParser.jj_consume_token(SunConfigParser.java:352) [:3.0.0.CR2]
at org.jboss.security.auth.login.SunConfigParser.config(SunConfigParser.java:99)
....
知道我应该在哪里/如何设置自定义主体吗?
提前致谢。
最佳答案
最后,JBoss 文档是错误的。使用模块的module-option
(这是否意味着主体不是由容器传递给模块,而是由模块创建?)它可以工作。
<module-option name="principalClass">es.caib.gesma.browseldap.LdapPrincipal</module-option>
如果您检查此项,您将遇到的下一个麻烦是使用该对象(而不是 SimplePrincipal 副本)获取 JBoss 容器。为此,您的模块必须将主体对象添加到 RolesSets
中,如下所示:
protected Group[] getRoleSets() throws LoginException {
SimpleGroup callerPrincipal = new SimpleGroup("CallerPrincipal");
callerPrincipal.addMember(this.getIdentity()); <--- YOUR PRINCIPAL OBJECT
Group[] roleSets = { userRoles , callerPrincipal };
return roleSets;
}
关于java - 如何设置自定义主体类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10781570/