
Spring OAuth2的ResourceServerConfiguration匹配了所有资源路径
coding三月 04, 20161mins
Spring Security Spring OAuth 经验总结
问题H2
通过继承ResourceServerConfigurerAdapter来配置ResourceServer的资源权限时,虽然使用了HttpSecurity#requestMatchers方法来匹配特定的资源,但是其他未匹配的资源依然会被匹配保护。
github上同样的问题。
原因H2
这在使用spring-security-oauth的2.0.9之前的版本配合Spring Security 4时会出现这个问题。原因是Spring Security 4.x版本稍微修改了request matchers的规则。多次调用HttpSecurity#requestMatchers不会覆盖之前的调用。 2.0.9做了如下修改
bash
if (endpoints != null) {// Assume we are in an Authorization Server- requests.requestMatchers(new NotOAuthRequestMatcher(endpoints- .oauth2EndpointHandlerMapping()));+ http.requestMatcher(new NotOAuthRequestMatcher(endpoints.oauth2EndpointHandlerMapping()));}
解决H2
Spring Security 4需要使用Spring Security OAuth 2.0.9及以上的版本,如果使用Spring Boot,则需要使用1.3.3级以上版本,1.3.2依赖的依然是Spring Security OAuth 2.0.8版本。
评论
新的评论
上一篇
Spring Boot Auto Configuration和HATEOAS、Data REST
Spring Boot集成HATEOAS JacksonAutoConfiguration 会注册Primary ObjectMapper,这个ObjectMapper通过 spring.jackson.* 来配置。 JacksonAutoConfiguration 配置完后…
下一篇
如何高效的使用postman
POSTMAN目前在我们团队中一直作为一个调用API的测试工具,但是由于我们的一直深入的使用它,导致使用的过程中存在不少很低效的问题。POSTMAN本身提供很多强大的功能,用好了它完全可以成为开发过程中比不可少的开发工具。 将POSTMAN作为API文档 我认为一个非常完善的R…
