I have a question. I have the following configuration
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery(
"select username,password, enabled from user where username=?")
.authoritiesByUsernameQuery(
"select username, role from user inner join role on user.role_id = role.id where username=?").passwordEncoder(passwordencoder());
}
@Bean(name="passwordEncoder")
public Md5PasswordEncoder passwordencoder(){
return new Md5PasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
http.addFilterBefore(filter,CsrfFilter.class);
http.
formLogin()
.loginPage("/login")
.defaultSuccessUrl("/add-ticket")
.failureUrl("/");
http
.authorizeRequests()
.antMatchers("/add-ticket").hasRole("ADMIN");
}
}
And the question is How does Spring security understand what the user role is? I mean, it saves some information in session after authorization or what? For example, it saves username in session and every request it takes the role from DB by username? I didn't understand this point. Can you help?