我正在尝试在我的 Spring ldap 上下文源上配置 baseDN,但它不断抛出异常:
配置如下:
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg index="0" value="${ldap_server}"/>
<beans:constructor-arg index="1" value="${ldap_searchbase}"/>
</beans:bean>
我的 ldap_searchbase 里面有一个空格,我查看了 Spring 代码:这导致了问题:
public DefaultSpringSecurityContextSource(String providerUrl) {
Assert.hasLength(providerUrl, "An LDAP connection URL must be supplied.");
StringTokenizer st = new StringTokenizer(providerUrl);
ArrayList<String> urls = new ArrayList<String>();
// Work out rootDn from the first URL and check that the other URLs (if any) match
while (st.hasMoreTokens()) {
String url = st.nextToken();
String urlRootDn = LdapUtils.parseRootDnFromUrl(url);
urls.add(url.substring(0, url.lastIndexOf(urlRootDn)));
logger.info(" URL '" + url + "', root DN is '" + urlRootDn + "'");
if (rootDn == null) {
rootDn = urlRootDn;
} else if (!rootDn.equals(urlRootDn)) {
throw new IllegalArgumentException("Root DNs must be the same when using multiple URLs");
}
}
我收到“使用多个 URL 时根 DN 必须相同”错误,并且我注意到字符串标记器由空格标记,因此它正在压缩我的 baseDN 并使其成为单独的 LDAP 服务器 URL。是什么赋予了?我在这里做错了什么?
如果我这样配置,我会遇到同样的问题(显然):
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg index="0" value="${ldap_server}/${ldap_searchbase}"/>
</beans:bean>