1、使用springboot(版本2.1.6.RELEASE)整合security(版本2.1.6),出现下面错误的解决方案:
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
at org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:244) ~[spring-security-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:198) ~[spring-security-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$LazyPasswordEncoder.matches(WebSecurityConfigurerAdapter.java:594) ~[spring-security-config-5.1.5.RELEASE.jar:5.1.5.RELEASE]
2、在Spring Security 5.0之前,默认值PasswordEncoder是NoOpPasswordEncoder需要纯文本密码。在Spring Security 5中,默认值为DelegatingPasswordEncoder,这需要密码存储格式。
在password中加入密码存储格式即可,如果是纯文本,添加{noop}即可
//定义认证规则
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//super.configure(auth);
auth.inMemoryAuthentication()
.withUser("zhangsan").password("{noop}123456").roles("VIP1","VIP2")
.and()
.withUser("lisi").password("{noop}123456").roles("VIP2","VIP3")
.and()
.withUser("wangwu").password("{noop}123456").roles("VIP1","VIP3");
}
新手勿喷,如有失误还请指教