【问题标题】:LDAP authentication with AD LDP from Spring Boot application从 Spring Boot 应用程序使用 AD LDP 进行 LDAP 身份验证
【发布时间】:2018-05-14 07:32:13
【问题描述】:

我正在尝试在 Sprint Boot 应用程序中实现 LDAP 身份验证。在测试环境中,我安装了一个用于进行身份验证的 Active Directory LDP 服务。我在 AD 实例中创建了一个用户,启用了该帐户并设置了密码。然后,我尝试使用 Spring 登录表单中的此帐户进行身份验证。

当我尝试使用 AD 登录时,我收到一条错误消息:

您的登录尝试不成功,请重试。

原因:凭据错误

由于我是 AD 和 Spring 的新手,很可能我配置错误(或两者都配置错误!)。

您对我如何进一步诊断此问题有什么建议吗?或者有什么我可能遗漏的明显内容?

我的 Spring Boot 代码(我尝试了许多不同的变体,这是一个例子):

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .anyRequest().fullyAuthenticated()
                .and()
            .formLogin();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
    }

    @Bean
    public AuthenticationManager authenticationManager() {
        return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
    }

    @Bean
    public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
        ActiveDirectoryLdapAuthenticationProvider provider = 
                new ActiveDirectoryLdapAuthenticationProvider("foo.bar", "ldap://servername:389");
        provider.setConvertSubErrorCodesToExceptions(true);
        provider.setUseAuthenticationRequestCredentials(true);
        return provider;
    }
}

【问题讨论】:

    标签: spring authentication spring-boot active-directory ldap


    【解决方案1】:

    事实证明,我的 Java 实现没有任何问题。问题似乎与 AD LDP 配置有关。我尝试连接到另一个已知良好的 AD LDP 实例,并且身份验证第一次成功。

    我将把它标记为答案,因为我不再对这个问题的解决方案感兴趣并希望关闭它......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 2018-04-15
      • 2016-04-30
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 2020-07-06
      相关资源
      最近更新 更多