我遵循this article来设置Spring的LDAP身份验证
现在,我可以登录到该应用程序,但出现此异常:
Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException:
Unprocessed Continuation Reference(s); remaining name 'DC=XEROX,DC=AD,DC=XEROX,DC=com'
Caused by: javax.naming.PartialResultException: Unprocessed Continuation Reference(s)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2917) ~[na:1.8.0_144]
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2891) ~[na:1.8.0_144]
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1846) ~[na:1.8.0_144]
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1769) ~[na:1.8.0_144]
根据其他articles I read,我需要将引用设置为遵循setReferral(“ follow”);
但是我不确定将此代码添加到哪里:
String completeUrl = new StringBuffer(this.url).append(":")
.append(this.port)
.append("/")
.append(this.contextRoot)
.toString();
auth.ldapAuthentication()
.userSearchFilter(userSearchFilter)
.userDnPatterns(userDnPatterns)
.contextSource()
.url(completeUrl)
.managerDn(managerDn)
.managerPassword(managerPassword);
答案 0 :(得分:0)
您应该创建自己的contextSource,例如:
@Bean("internalLdapContextSource")
public LdapContextSource getLdapContextSource() {
String ldapUrl = env.getProperty("ldap.server");
String managerDn = env.getProperty("ldap.manager.distinguished.name");
String managerPassword = env.getProperty("ldap.manager.password");
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl(ldapUrl);
contextSource.setUserDn(managerDn);
contextSource.setPassword(managerPassword);
Map<String, Object> baseEnvironmentProperties = new HashMap<>();
baseEnvironmentProperties.put("java.naming.referral", "follow");
contextSource.setBaseEnvironmentProperties(baseEnvironmentProperties);
return contextSource;
}
您可以使用示例中所示的 setBaseEnvironmentProperties 方法或 setReferral (两种方法都可以)。
最终使用 .contextSource(getLdapContextSource())