Я хотел бы предоставить доступ к / привет URL пользователям, которые имеют роль «ADMIN». У меня есть такая конфигурация безопасности. С URL-адреса "/ authenticate" я получаю токен jwt.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/authenticate").permitAll()
//.antMatchers("/hello").hasRole("ADMIN")
.anyRequest().authenticated().
and().
exceptionHandling().and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
Я пытался добавить аннотацию @PreAuthorize в мой контроллер, но он не работает, у всех пользователей есть доступ к этому URL.
@GetMapping("/hello")
@PreAuthorize("hasRole('ADMIN')")
public String test(){
return "Hello";
}