【发布时间】:2019-11-29 10:51:50
【问题描述】:
我正在尝试学习 spring 并创建一个网站,其中将通过登录页面关闭身份验证,并将 angular 传递给需要使用 ldap 进行身份验证的 spring。我想我会从 Spring 网站开始并浏览那里的指南,但它似乎使用了不推荐使用的代码并且它有一个错误。
我已经浏览了几个 stackoverflow 主题和谷歌搜索,但我没有找到我需要的东西。
src/main/java/hello/WebSecurityConfig.java
package hello;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}
@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");
}
}
问题是 ".passwordEncoder(new LdapShaPasswordEncoder()) .passwordAttribute("userPassword")" LdapShaPasswordEncoder 已被弃用,因此它要么是 .passwordEncoder 采用的,要么是由 LdapShaPasswordEncoder 返回的 PasswordEncoder。我已经尝试了使用 BCryptPasswordEncoder 在stack 上找到的 BCrypt 示例,但我仍然从 .passwordEncoder 收到错误,它不是正确的 PasswordEncoder org.springframework.security.authentication.encoding.PasswordEncoder vs org.springframework.security.crypto.password .PasswordEncoder
【问题讨论】:
标签: spring-security ldap