gpt4 book ai didi

spring-security - Spring LDAP PasswordEncoder 已弃用的替代方案

转载 作者:行者123 更新时间:2023-12-04 15:42:50 26 4
gpt4 key购买 nike

我正在尝试学习 spring 并创建一个网站,其中身份验证将通过登录页面关闭,角度传递给 spring,需要使用 ldap 进行身份验证。我想我会从 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。我已经尝试了在 stack 上找到的 BCrypt 示例使用 BCryptPasswordEncoder 但我仍然从 .passwordEncoder 得到一个错误,它不是正确的 PasswordEncoder org.springframework.security.authentication.encoding.PasswordEncoder vs org.springframework.security.crypto.password.PasswordEncoder

最佳答案

@Override
protected 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 BCryptPasswordEncoder())
.passwordAttribute("userPassword");

}

关于spring-security - Spring LDAP PasswordEncoder 已弃用的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57129471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com