Why following basic security configurations do not apply inMemoryAuthentication() clause?
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.httpBasic()
.and()
.authorizeRequests()
.anyRequest().authenticated();
super.configure(http);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("username").password("password");
super.configure(auth);
}
}
After the application initialization, there is still only default user
generated by Spring itself, there is no such user like username
.
In spring boot 2.x, you will have to implement your own UserDetailsService, as described here and here
Example:
Do not call super method from
void configure(AuthenticationManagerBuilder auth)
. It setsdisableLocalConfigureAuthenticationBldr
flag totrue
that leads to yourAuthenticationManagerBuilder
being ignored. Finally yourvoid configure(AuthenticationManagerBuilder auth)
method should look like this: