首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用spring-data-ldap认证ladp用户?

如何使用spring-data-ldap认证ladp用户?
EN

Stack Overflow用户
提问于 2019-07-10 00:12:38
回答 1查看 193关注 0票数 0

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

谢谢

EN

回答 1

Stack Overflow用户

发布于 2019-07-10 20:11:50

下面是我在工作中获得代码,这些代码使用LDAP作为身份验证提供者来提供spring安全性的配置。也许它会给你一些关于如何让它工作的洞察。我添加了一些注释来描述实现的一些关键点。这是我的扩展WebSecurityConfigurerAdapter的配置类中的代码。

代码语言:javascript
复制
@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身份验证提供程序为您提供了支持。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56956734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档