如何在不使用WebSecurityConfigurerAdapter
的情况下替换代码
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public UserDetailsService userDetailsService() {
return new UserDetailsServiceImpl();
}
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService());
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin().permitAll()
.and()
.logout().permitAll();
}
}
我试了很多,但我不能解决它。请帮帮我!
我有一些更新要告诉你
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.
authorizeHttpRequests()
.anyRequest()
.authenticated()
.and()
.httpBasic();
return http.build();
}
}