美文网首页我爱编程
记录一个小坑spring security oauth2的cli

记录一个小坑spring security oauth2的cli

作者: AlienJunX | 来源:发表于2018-05-23 11:42 被阅读985次

按照网上介绍的文章应该很好配置,但是发现配置完后,获取到token,再去调用受保护的api,发现传不传token都能调用,这就奇怪了。 原来使用的是springboot 1.5.x造成的,需要配置过滤器链顺序。

问题记录:
1、记得配置允许表单提交认证。

      @Override
        public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
            //允许表单认证
            oauthServer.allowFormAuthenticationForClients();
        }

2、springboot 1.3.x~1.5.x 需要配置过滤器链的顺序,不然就无需认证也能正常访问了。
resources 目录下新建application.yml 配置如下:

security:
  oauth2:
    resource:
      filter-order: 3

也有优雅的解决方式:@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
https://stackoverflow.com/questions/42822875/springboot-1-5-x-security-oauth2

springSecurity 的设计:一次请求,只会被 FilterProxyChain 中的最多一个过滤器链处理。

org.springframework.security.web.FilterChainProxy

    private List<Filter> getFilters(HttpServletRequest request) {
        for (SecurityFilterChain chain : filterChains) {
            if (chain.matches(request)) {
                return chain.getFilters();
            }
        }

        return null;
    }
QQ20180529-105206.png
特别感谢这篇文章:
https://github.com/lexburner/oauth2-demo

相关文章

网友评论

    本文标题:记录一个小坑spring security oauth2的cli

    本文链接:https://www.haomeiwen.com/subject/xhirbxtx.html