我试图让我的群组搜索正在运行,但我一直得到同样的异常
java.lang.NullPointerException
at com.sun.enterprise.security.auth.realm.ldap.LDAPRealm.groupSearch(LDAPRealm.java:705)
at com.sun.enterprise.security.auth.realm.ldap.LDAPRealm.findAndBind(LDAPRealm.java:497)
at com.sun.enterprise.security.auth.login.LDAPLoginModule.authenticate(LDAPLoginModule.java:108)
at com.sun.enterprise.security.auth.login.PasswordLoginModule.authenticateUser(PasswordLoginModule.java:117)
at com.sun.appserv.security.AppservPasswordLoginModule.login(AppservPasswordLoginModule.java:148)
仅在网络上的帖子中出现相同的问题并且没有修复。
这是domain.xml
<auth-realm name="EpsLdapRealm" classname="com.sun.enterprise.security.auth.realm.ldap.LDAPRealm">
<property name="directory" value="ldap://myldap:389"></property>
<property name="base-dn" value="ou=Users,o=xxx"></property>
<property name="jaas-context" value="ldapRealm"></property>
<property name="search-bind-dn" value="cn=saepsman,ou=Users,ou=e-Directory,ou=Services,o=xxx"></property>
<property name="search-bind-password" value="xxxxx"></property>
<property name="search-filter" value="(&(objectClass=user)(uid=%s))"></property>
<property description="null" name="assign-groups" value="USER"></property>
<property name="group-search-filter" value="(&(objectClass=groupOfNames)(member=%d))"></property>
<property name="group-base-dn" value="ou=AccessControl,o=xxx"></property>
</auth-realm>
身份验证工作正常,但组分配不起作用。当我删除group-search-filter时,我没有收到任何错误,但也没有分配任何组。
我想映射的小组是 CN = CUG-EPSManager-管理员,OU = AccessControl的,邻= XXX
我在glassfish-web.xml中执行以下映射
<security-role-mapping>
<role-name>ADMIN</role-name>
<group-name>cug-EPSManager-Administrators</group-name>
</security-role-mapping>
我也用过
-Djava.naming.referral=follow
编辑: 我还得到以下日志消息,指示search-bin-dn和密码正常。我还可以使用Softerra LDAP Browser中的凭据浏览LDAP树。
Error during LDAP search with filter [(&(objectClass=groupOfNames)(member=cn=cdamen,ou=Users,o=xxx))].|#]
当我查看LDAPRealm源代码时,我看到它在以下语句中失败
int sz = grpAttr.size();
这对我来说,这意味着找到了一些组,但没有组属性。但是当我向Softerra询问时,很奇怪......
/**
* Search for group membership using the given connection.
*
*/
private List groupSearch(DirContext ctx, String baseDN,
String filter, String target)
{
List groupList = new ArrayList();
try {
String[] targets = new String[1];
targets[0] = target;
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes(targets);
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration e = ctx.search(baseDN,
filter.replaceAll(Matcher.quoteReplacement("\\"), Matcher.quoteReplacement("\\\\")), ctls);
while(e.hasMore()) {
SearchResult res = (SearchResult)e.next();
Attribute grpAttr = res.getAttributes().get(target);
int sz = grpAttr.size();
for (int i=0; i<sz; i++) {
String s = (String)grpAttr.get(i);
groupList.add(s);
}
}
} catch (Exception e) {
_logger.log(Level.WARNING, "ldaprealm.searcherror", filter);
_logger.log(Level.WARNING, "security.exception", e);
}
return groupList;
}
希望有人知道解决方案。 科恩