Problem Description:
Use springboot, use spring security for permission management, use memory user authentication, but no response, error report:
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null”
Solutions
①Create mypasswordencoder class, implement passwordencoder, and annotate @ component
@Component
public class MyPasswordEncoder implements PasswordEncoder {
@Override
public String encode(CharSequence charSequence) {
return charSequence.toString();
}
@Override
public boolean matches(CharSequence charSequence, String s) {
return s.equals(charSequence.toString());
}
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//If the program reports an error There is no PasswordEncoder mapped for the id "null", comment the paragraph and add the following code
//or add a @Component annotation to MyPasswordEncoder class to make it a bean
auth.inMemoryAuthentication().withUser("admin").password("123456").authorities("ADMIN_ADD", "ADMIN_FIND");// customize the login user name and password and give some permissions
}
②:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//This one uses the anonymous internal class
auth.inMemoryAuthentication().passwordEncoder(new MyPasswordEncoder()).withUser("lxy").password("lxy").authorities("ADMIN_ADD","ADMIN_FIND");
}
Similar Posts:
- Problems of bad credentials, encoded password does not look like bcrypt in spring-cloud-oauth2 upgrade
- There is no PasswordEncoder mapped for the id “null” [How to Solve]
- [Solved] Using JDK dynamic agent to customize SPI Error: UndeclaredThrowableException
- [Solved] failure to inject AuthenticationManager directly Error
- Access permission problem caused by object. Clone() method
- [Solved] Java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
- Springboot2 oauth2 Error: Possible CSRF detected – state parameter was required but no state could
- [Solved] Exception in thread “main” javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- Java error: No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- HDFS: How to Operate API (Example)