【问题标题】:Spring security - implement oauth with existing FilterChainProxySpring security - 使用现有的 FilterChainProxy 实现 oauth
【发布时间】:2015-02-27 18:41:19
【问题描述】:

我们已有使用 Spring security 3.1 构建的 Web 应用程序,Wink(用于休息) 我们现在需要为几个资源添加 oauth2(client_credentials 流),我查看了许多示例,所有示例都使用 Http 命名空间配置以及 spring dispatcher servlet(我们目前还没有)

问题是 http 命名空间正在创建一个我们已经在应用程序中拥有的 springSecurityFilterChain,所以首先我重命名了现有过滤器,以便默认值可以与旧过滤器共存。 但这不起作用,它要么是现有的用于请求的链,要么是新的链。 我已经尝试过以下方法
1. 通过提供空配置位置(在 web.xml 中)禁用调度程序 servlet 上下文 2. 尝试在 application-context.xml 中进行 oauth 配置(对现有 FilterChainProxy 的权利)
3. 通过将过滤器设置为 none 来允许现有链中的 /oauth/token(以便新的可以接管)
4. 尝试在现有链中声明 oauth 过滤器,但没有获得正确的 clientAuthentication


我真的不知道还能尝试什么 - 所以问题是:是否可以在同一个 webapp 中声明两者?或者是否可以以旧方式声明 oauth2 配置。

谢谢 什洛米

【问题讨论】:

    标签: spring spring-mvc oauth spring-security


    【解决方案1】:

    我最终设法做到了,让 API(受 oauth 保护)将 url 与应用程序的其余部分完全分开。 因此 Http 命名空间正在创建 springSecurityFilterChain bean,而其他命名空间只是具有不同的 bean 名称。每个人都通过 web.xml 中的 DelegatingProxy 进行委派

    我需要将 API URL 前缀放在其他链中,并允许所有请求通过,让 oauth 安全链来处理安全性。 (即过滤链模式=“/api/**”过滤器=“无)

    关于 spring oauth2 绑定到 spring MVC 这么紧我认为不是一个好的实现。 调度程序 servlet 的映射不能用于 /*,但必须类似于 /auth/*

    所以需要一个从 ClientCredentialsTokenEndpointFilter 继承的特殊过滤器,它具有像 super("/auth/oauth/token") 这样的特殊路径。

    它也不能是 /api/* 因为这是我们的 rest 框架 (wink RestServlet) 映射的真实 API URI 所以我们有这样的东西

    http://server:port/context/auth/oauth/token
    http://server:port/context/api/someresource (protected with oauth2)
    http://server:port/context/rest/someresource (old rest for application)
    

    史洛米

    【讨论】:

      猜你喜欢
      • 2020-03-16
      • 2013-07-28
      • 2013-08-29
      • 2016-03-13
      • 2011-04-17
      • 1970-01-01
      • 2014-11-18
      • 2011-03-17
      • 1970-01-01
      相关资源
      最近更新 更多