Witam,
Chciałbym zabezpieczyć REST API ze względu na role, czyli żeby do adresu localhost:8080/api/*** miał dostęp tylko użytkownik z rolą ADMIN.
http.authorizeRequests().antMatchers("/api/").authenticated().and() to zabezpiecza api, ale wystarczy że użytkownik jest zalogowany bez względu na role.
//.authorizeRequests().antMatchers("/api/").hasAnyAuthority(Role.ADMIN.name()); tutaj znowu jeśli loguję się nawet na użytkownika z rolą ADMIN dostaję złe uprawnienia.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/api/**").authenticated().and()
//.authorizeRequests().antMatchers("/api/**").hasAnyAuthority(Role.ADMIN.name());
http.csrf().disable();
http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint);
http.formLogin().successHandler(authenticationSuccessHandler);
http.formLogin().failureHandler(authenticationFailureHandler);
//http.formLogin().loginPage("login.html");
}