Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为LDAPs上下文源指定到数据源的连接?_Java_Spring_Ldap_Datasource - Fatal编程技术网

Java 如何为LDAPs上下文源指定到数据源的连接?

Java 如何为LDAPs上下文源指定到数据源的连接?,java,spring,ldap,datasource,Java,Spring,Ldap,Datasource,我正在使用SpringMVC和针对active directory的LDAP身份验证。我现在拥有的东西可以工作,但我的contextSource属性:url、managerDN和managerPassword是硬编码的。我想将这些属性作为资源移动到我的server.xml中,并使用数据源指定这些连接设置。我的想法是managerDN可以像用户名一样使用,然后其余的就可以工作了。唯一的问题是contextSource没有任何用于此的方法。contextSource是从contextSourceBu

我正在使用SpringMVC和针对active directory的LDAP身份验证。我现在拥有的东西可以工作,但我的contextSource属性:url、managerDN和managerPassword是硬编码的。我想将这些属性作为资源移动到我的server.xml中,并使用数据源指定这些连接设置。我的想法是managerDN可以像用户名一样使用,然后其余的就可以工作了。唯一的问题是contextSource没有任何用于此的方法。contextSource是从contextSourceBuilder创建的对象。有人知道怎么做吗

@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);