【发布时间】:2016-07-15 02:05:43
【问题描述】:
我有一个HttpSecurity,如下所示:
http
.exceptionHandling().and()
.anonymous().and()
.servletApi().and()
.headers().cacheControl().and().and()
.authorizeRequests()
// Need authentication sur POST
.antMatchers(HttpMethod.POST).authenticated()
// Allow anonymous resource requests
.anyRequest().permitAll().and()
// Custom Token based authentication based on the header previously given to the client
.addFilterBefore(new StatelessAuthenticationFilter(tokenAuthenticationService),
UsernamePasswordAuthenticationFilter.class)
// Filtre pour gérer la clef d'api
.addFilterBefore(new ApiKeyFilter(), StatelessAuthenticationFilter.class)
// Filtre pour ajouter les headers nécessaires à la consommation par les différents clients
.addFilterBefore(new CorsFilter(), ApiKeyFilter.class);
问题是我需要能够在/user 上POST 而不会得到403 Forbidden 的响应。所以我想添加一个规则来允许/user 和POST 上的匿名请求。
我用过这个antMatcher:
.antMatchers(HttpMethod.POST, "/user").anonymous()
但问题是我不知道在哪里添加这个,我在.antMatchers(HttpMethod.POST, "/user").anonymous() 之前和之后尝试过,但似乎它被忽略了,因为我仍然得到一个403。
【问题讨论】:
标签: java spring spring-security