I have a problem similar to PreAuthorize Annotations do not work with knitwear . I created a configuration class for Spring Security and authentication works, but authorization does not work.
Here is my code
SpringSecurityConfig.java
@Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) @Order(1) @ComponentScan({"com.foo.rest.resources.Template"}) public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { private final UserService userService; private final TokenAuthenticationService tokenAuthenticationService; public SpringSecurityConfig() { super(true); this.userService = new UserService(); tokenAuthenticationService = new TokenAuthenticationService("tooManySecrets", userService); } @Override protected void configure(HttpSecurity http) throws Exception { http .exceptionHandling().and() .anonymous().and() .servletApi().and() .headers().cacheControl().and() .authorizeRequests()
and Template.java
@Component @Path("/template") @Produces(MediaType.APPLICATION_JSON) public class Template { @GET @Secured("ROLE_EDITOR") public User getTemplate() { return new Template(); } }
My assumption is that authentication is processed in the filter chain, but it does not return after reaching the authorization tag. Any idea how to make this work?
source share