Запретить пользователю без прав доступа метод контроллера в Spring Security - PullRequest
0 голосов
/ 28 марта 2019

У меня есть этот класс безопасности:

@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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...