【问题标题】:How to authenticate ladp user using spring-data-ldap?如何使用 spring-data-ldap 对 ldap 用户进行身份验证?
【发布时间】:2019-07-10 20:11:49
【问题描述】:

我能够使用 spring data ldap 模块创建用户,当我尝试使用用户 ID 和密码进行身份验证时,它给出了错误。我的猜测是当创建用户时 ladp 正在对密码执行一些加密并将其保存在 ldap 树中。我怎么知道 ldao 正在使用哪个加密。我已经看到了一些如何使用 spring-security-ldap 对用户进行身份验证的示例,我需要有关 spring-data-ldap 的帮助。 任何想法将不胜感激。

谢谢

【问题讨论】:

  • 在哪种情况下您要手动验证用户身份?如果您正确配置了 spring security 的配置,它将为您管理所有工作。您还可以发布您遇到的错误吗?
  • 我刚刚从 github 关注了这篇文章,我有这里提到的完全相同的配置。 github.com/eugenp/tutorials/tree/master/spring-ldap
  • 你能发布你得到的错误吗?然后我会尝试复制你的场景。
  • [LDAP:错误代码 49 - NDS 错误:身份验证失败 (-669)];嵌套异常是 javax.naming.AuthenticationException: [LDAP: error code 49 - NDS error: failed authentication (-669)]",
  • 我想我需要添加一个身份验证提供程序(如 ldapauthenticationprovider)来对用户进行身份验证。不确定..

标签: spring spring-boot spring-data-jpa spring-data spring-security-ldap


【解决方案1】:

这是我从工作中获得的代码,它使用 LDAP 作为身份验证提供程序提供了 Spring Security 配置。也许它会给你一些关于如何使它工作的见解。我添加了一些 cmets 来描述实现的一些关键点。这是我的配置类中扩展 WebSecurityConfigurerAdapter 的代码。

@Override
protected void configure(HttpSecurity http) throws Exception {
        http.cors().and()                    
                .authorizeRequests()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login") // defines the login page
                .loginProcessingUrl("/userAuth") // defines the endpoint which the post with the login form must be sent to.
                .permitAll()
                .and()
                .logout()
                .permitAll()
}

@Override
public void configure(AuthenticationManagerBuilder auth) {
        auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider()); // defines LDAP as your authentication provider.
}

@Bean
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
        ActiveDirectoryLdapAuthenticationProvider authenticationProvider = new ActiveDirectoryLdapAuthenticationProvider(DOMAIN, URL, ROOT_DN); // instantiate and connects to your LDAP provider. DOMAIN, URL and ROOT_DN must be info you have from your LDAP.
        authenticationProvider.setConvertSubErrorCodesToExceptions(true);
        authenticationProvider.setUseAuthenticationRequestCredentials(true);

        return authenticationProvider;
}

通过这样的实现,来自/login 并发布到/userAuth 的任何登录表单都将在您的LDAP 服务器上进行身份验证。因此,您不必担心加密密码或任何其他问题。 LDAP 身份验证提供程序可以帮助您。

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 2020-07-05
    • 2011-08-21
    • 2018-08-09
    • 2012-08-23
    • 2012-07-18
    • 1970-01-01
    • 2015-11-22
    • 2011-04-16
    相关资源
    最近更新 更多