spring-security 在WebSecurityConfigurerAdapter被弃用后,如何重写此内容

zyfwsgd6  于 2022-11-11  发布在  Spring
关注(0)|答案(1)|浏览(187)

我是Spring的新手,正在学习如何从youtube tutorial中使用JWT,在那个教程中,他们用这个过时的抽象类扩展了安全配置。我看了文档,他们现在正在使用Bean,但我不知道如何用Bean复制这个确切的代码,如果我能得到一些帮助,我将非常感激。

import lombok.RequiredArgsConstructor;
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.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final UserDetailsService userDetailsService;
    private final BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
    }
}
xytpbqjk

xytpbqjk1#

看一看,我觉得herehere的信息已经足够了

相关问题