spring - 通过 Active Directory LDAP 使用 Spring-Security 进行身份验证

标签 spring spring-security active-directory ldap spring-ldap

我无法使用真实的事件目录进行身份验证,让我更好地解释一下我尝试使用 spring.io 提出的示例进行身份验证,没有问题,内部服务启动没有任何问题。 引用 https://spring.io/guides/gs/authenticating-ldap/

我试图通过插入我的事件目录的配置来修改下面的代码,但没有成功。您能否指导我或向我展示一个真实的案例,在不使用示例中的内部服务的情况下建立真正的连接?网上查了一下,发现和官方的例子差不多,没有实际案例

@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userDnPatterns("uid={0},ou=people")
                .groupSearchBase("ou=groups")
                .contextSource()
                    .url("ldap://localhost:8389/dc=springframework,dc=org")
                    .and()
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
    }

错误显示: LDAP处理过程中出现未分类异常;嵌套异常是 javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0907C2, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580

最佳答案

是的,通过 LDAP 进行身份验证太麻烦了。为了能够对 AD 执行身份验证,您需要使用 ActiveDirectoryLdapAuthenticationProvider。 这是工作示例:

@Override
protected void configure(AuthenticationManagerBuilder auth) {
    ActiveDirectoryLdapAuthenticationProvider adProvider =
            new ActiveDirectoryLdapAuthenticationProvider("domain.com", "ldap://localhost:8389");
    adProvider.setConvertSubErrorCodesToExceptions(true);
    adProvider.setUseAuthenticationRequestCredentials(true);
    auth.authenticationProvider(adProvider);
}

为了节省您的时间,请阅读以下内容,这非常重要: AD authentication doc

关于spring - 通过 Active Directory LDAP 使用 Spring-Security 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58464421/

相关文章:

java.lang.NoClassDefFoundError : kotlin/jvm/internal/Intrinsics in Spring Boot App

java - 哪个 Spring 框架提供 REST 服务?

Spring Rest 服务 - 我尝试登录时 CSRF token 无效

java - 从 Spring MVC Controller 的安全上下文中获取 UserDetails 对象

grails - Spring Security URL 映射 Grails

c# - 生产环境中出现 DirectoryServicesComException,但本地计算机上没有 C# ASP.net

阿拉伯语的 Java 日期时间

java - Spring Security 自定义 RememberMeAuthenticationFilter 没有被解雇

c# - 如何获得下划线对象?

.net - UserPrincipal.FindByIdentity坚持 "There is no such object on the server."