Java 如何为LDAPs上下文源指定到数据源的连接?
我正在使用SpringMVC和针对active directory的LDAP身份验证。我现在拥有的东西可以工作,但我的contextSource属性:url、managerDN和managerPassword是硬编码的。我想将这些属性作为资源移动到我的server.xml中,并使用数据源指定这些连接设置。我的想法是managerDN可以像用户名一样使用,然后其余的就可以工作了。唯一的问题是contextSource没有任何用于此的方法。contextSource是从contextSourceBuilder创建的对象。有人知道怎么做吗Java 如何为LDAPs上下文源指定到数据源的连接?,java,spring,ldap,datasource,Java,Spring,Ldap,Datasource,我正在使用SpringMVC和针对active directory的LDAP身份验证。我现在拥有的东西可以工作,但我的contextSource属性:url、managerDN和managerPassword是硬编码的。我想将这些属性作为资源移动到我的server.xml中,并使用数据源指定这些连接设置。我的想法是managerDN可以像用户名一样使用,然后其余的就可以工作了。唯一的问题是contextSource没有任何用于此的方法。contextSource是从contextSourceBu
@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userSearchFilter("sAMAccountName={0}")
.userSearchBase("OU=Accounts")
.groupSearchFilter("member={0}")
.groupSearchBase("OU=Groups")
.contextSource()
.url("ldap://myurl:portNum")
.managerDn("stuff")
.managerPassword("things");
}
}
只需在*.properties文件中设置它,让Spring加载它,然后使用:
@Value(${ldap.manager})
String managerDn;
@Value(${ldap.manager.password})
String managerPassword;
[...]
.managerDn(managerDn)
.managerPassword(managerPassword);
或:
使用org.springframework.security.ldap.DefaultSpringSecurityContextSource
在setters中设置user/passoword并将其设置为
.contextSource(youFancySpringContext);