Upto Spring 4 password can be stored as a plain text in inmemory process.
But from Spring 5 password must be encoded
from Spring 5 we have to use {noop}
or we can use NoOpPasswordEncoder instance, we can pass NoOpPasswordEncoder instance to passwordEncoder() method calling on inMemoryAuthentication().
Alternatively we can user PasswordEncoderFactories to create encoded password
But from Spring 5 password must be encoded
from Spring 5 we have to use {noop}
@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("user").password("{noop}password").roles("USER"); } }
or we can use NoOpPasswordEncoder instance, we can pass NoOpPasswordEncoder instance to passwordEncoder() method calling on inMemoryAuthentication().
@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .passwordEncoder(NoOpPasswordEncoder.getInstance()) .withUser("user").password("password").roles("USER"); } }
Alternatively we can user PasswordEncoderFactories to create encoded password
@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder(); auth.inMemoryAuthentication() .withUser("user") .password(encoder.encode("password")) .roles("USER"); } }
Post a Comment
Post a Comment