У меня есть этот класс безопасности:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("{noop}user").authorities("READ");
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and().httpBasic()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
И мой метод управления:
@PostMapping
@PreAuthorize("hasAnyAuthority('WRITE')")
public ResponseEntity registerEmployee...
Использование пользователя user
Я исключен, чтобы быть заблокированным для доступа registerEmployee
, но яЯ все еще могу потреблять его, даже когда user
не имеет WRITE
полномочий, только READ