spring - 使用 Spring 进行 LDAP 身份验证 - 获取 PartialResultException
问题描述
我正在关注这篇关于使用 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]
根据我阅读的其他文章,我需要设置要关注的推荐,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);
解决方案
您应该创建自己的 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())
推荐阅读
- pandas - 在 pandas 数据框中查找模式,按行重新排序,并重置索引
- javascript - 带有星号 * 和下划线 _ 的 Markdown 正则表达式
- math - “n + loglog(n^2)”的大 O 是多少?
- databricks - databricks.koalas 没有用于十分位的属性“qcut”
- reactjs - doc内数组中的firestore更新值
- python - 在 Visio 2016 (.vsdx) 中使用“查找和替换”功能或使用 python 中的代码编辑文本
- android - 带有 FirebaseMessaging 的 Flutter 推送通知 ^8.0.0-dev.14
- webserver - 具有简单 Flask 身份验证的静态网站的 Nginx 配置
- kubernetes - 无法附加或挂载卷:未挂载的卷
- node.js - 像“ORDER BY”和“GROUP BY”这样的子句是否容易在 SQLite 中注入?