0
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
    org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:236)
    org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:196)
    org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$LazyPasswordEncoder.matches(WebSecurityConfigurerAdapter.java:593)

My code was working fine, now i have changed the spring security version from 4.0 to 5.0, and its not working

kakabali
  • 3,824
  • 2
  • 29
  • 58
Noorus Khan
  • 1,342
  • 3
  • 15
  • 33

2 Answers2

10

for Java based, make these changes in your code and update it as

@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
    BCryptPasswordEncoder encoder = passwordEncoder();
    auth.inMemoryAuthentication().withUser("admin").password(encoder.encode("admin")).roles("ADMIN");
}

@Bean
public BCryptPasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

or,

 @Bean
public static NoOpPasswordEncoder passwordEncoder() {
 return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
}

for XML configuration,

<bean id ="passwordEncoder" class = "org.springframework.security.crypto.NoOpPasswordEncoder" factory-method = "getInstance" />
Noorus Khan
  • 1,342
  • 3
  • 15
  • 33
0

Please read through the link here for the updates you need to do for this:-

https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-format.

You may need to add bean for the password encoder in your class, that will again depend on your requirements

For example you can use the NoOpPasswordEncoder in your configuration class like below:-

@Bean
public NoOpPasswordEncoder noopPasswordEncoder(){
    return new NoOpPasswordEncoder();
}

And for XML based Configuration like below:-

<bean id ="passwordEncoder" class = "org.springframework.security.crypto.NoOpPasswordEncoder" factory-method = "getInstance" />
kakabali
  • 3,824
  • 2
  • 29
  • 58