解決springboot統合security報There is no PasswordEncoder mapped for the id“null”
1667 ワード
1、springboot(バージョン2.1.6.RELEASE)を使用してsecurity(バージョン2.1.6)を統合し、次のエラー解決策が発生した.
2、Spring Security 5.0より前に、デフォルト値のPasswordEncoderがNoOpPasswordEncoderである場合、純粋なテキストパスワードが必要です.Spring Security 5では、デフォルト値はDelegatingPasswordEncoderで、パスワード格納フォーマットが必要です.passwordにパスワード格納フォーマットを追加すればいいです.純粋なテキストであれば{noop}を追加すればいいです.
初心者はスプレーしないでください.ミスがあったら教えてください.
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");
}
初心者はスプレーしないでください.ミスがあったら教えてください.