I want to enable the use of "ROLE_ANONYMOUS" to allow anonymous access to some URLs in my application. And I used the configuration below.
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .requestCache()
            .requestCache(new NullRequestCache()).and()
        .anonymous().authorities("ROLE_ANONYMOUS").and()
        .exceptionHandling().and()
        .servletApi().and()
        .headers().cacheControl().and()
        .authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/profile/image").permitAll()
            .antMatchers("/favicon.ico").permitAll()
            .antMatchers("/resources/**").permitAll()
            
            
            .anyRequest().authenticated();
        
        
}
My controller looks like this:
@RestController
@RequestMapping(value="/login", produces="application/json")
public class LoginController {
    @Secured( value={"ROLE_ANONYMOUS"})
    @RequestMapping(method=RequestMethod.GET)
    public String get(){
        return "hello";
    }
}
But when I try to press "/ login", I get a 403 rejection error. Please help me, how can I enable anonymous anonymous access.
source
share