最近在了解spring security的时候发现了一个问题,就是我自己配置了一个加密过后,我自己登录的时候还会出现密码不正确的问题,但是我直接在我虚拟化的用户上直接加密却又可以登录
@Configuration
//WebSecurityConfigurerAdapter自定义的security策略
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//链式编程
@Override
//授权
protected void configure(HttpSecurity http) throws Exception {
//super.configure(http);
//请求授权规则
http.authorizeRequests()
.antMatchers("/success").permitAll()
.antMatchers("/vip1").hasRole("vip1");
//没有权限自动跳转到登陆页(自带登录页)
http.formLogin();
}
@Override
//认证权限AuthenticationManagerBuilder 自定义的认证策略
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//super.configure(auth);
// //inMemoryAuthentication配置一个虚拟化用户名密码
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder())
//withUser用户名,password密码,roles角色
.withUser("jiang").password(new BCryptPasswordEncoder().encode("123")).roles("vip1");
}
这样的话就不会出现密码错误,但是
@Configuration
//WebSecurityConfigurerAdapter自定义的security策略
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//链式编程
@Override
//授权
protected void configure(HttpSecurity http) throws Exception {
//super.configure(http);
//请求授权规则
http.authorizeRequests()
.antMatchers("/success").permitAll()
.antMatchers("/vip1").hasRole("vip1");
//没有权限自动跳转到登陆页(自带登录页)
http.formLogin();
}
@Override
//认证权限AuthenticationManagerBuilder 自定义的认证策略
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//super.configure(auth);
// //inMemoryAuthentication配置一个虚拟化用户名密码
auth.inMemoryAuthentication()
//withUser用户名,password密码,roles角色
.withUser("jiang").password("123").roles("vip1");
}
// //配置密码加密 从spring5开始就强制要求密码加密
@Bean
PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
直接配置一个@Bean却不行
想问问怎么回事