I am a newbie with spring security and I have created a basic auth for my spring boot application to try it out
I have created MYGlobalAuthenticationConfigurerAdapter like this:
@Value("${username}")
String username;
@Value("${password}")
String password;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService());
}
@Bean
public UserDetailsService userDetailsService() {
return new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return new User(username, password, true, true, true, true,
AuthorityUtils.createAuthorityList("USER"));
}
};
}
note that I load username and password from properties file and I validate against values
and MyWebSecurityConfigurerAdapter like this:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated().and().
httpBasic().and().
csrf().disable();
}
with a @EnableWebSecurity
annotation.
I try postman to connect to one of my web services with username and password every time I change username the request is validated even if the username is not the same as the one I put in my properties file