【问题标题】:Spring Security Java Config for LDAPLDAP 的 Spring Security Java 配置
【发布时间】:2014-12-30 11:42:13
【问题描述】:

如何设置 Spring Security LDAP 配置的 URL? 有很多基于 xml 的示例,但我找不到一个 java config 示例来复制下面的 xml 行。我假设它是在下面的 java 代码块中配置的,该代码块取自使用嵌入式 ldap 的 spring 指南,但是我们如何设置外部 url?

<ldap-server id="ldapServer" url="ldap://example.com:PORT/dc=example,dc=com" />
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
    auth.ldapAuthentication()
            .userDnPatterns("uid={0},ou=people")
            .groupSearchBase("ou=groups")
            .contextSource()
                .ldif("classpath:test-server.ldif");
}

【问题讨论】:

    标签: spring spring-security ldap


    【解决方案1】:

    您只需使用LdapAuthenticationProviderConfigurer.ContextSourceBuilderurl() 方法

    所以你可以简单地扩展你的代码如下:

    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth.ldapAuthentication()
                .userDnPatterns("uid={0},ou=people")
                .groupSearchBase("ou=groups")
                .contextSource()
                    .ldif("classpath:test-server.ldif")
                    .url("ldap://example.com:PORT/dc=example,dc=com");
    }
    

    【讨论】:

    • 给出使用 .ldif() 的例子对任何人来说都是毫无用处的。每个教程都依赖它,它不能解决任何人的问题。
    猜你喜欢
    • 1970-01-01
    • 2012-06-04
    • 2014-04-01
    • 2017-07-17
    • 2016-04-13
    • 2018-07-24
    • 2017-01-21
    • 1970-01-01
    • 2014-05-15
    相关资源
    最近更新 更多