【问题标题】:How to enable /oauth/check_token with Spring Security Oauth2 using XML如何使用 XML 使用 Spring Security Oauth2 启用 /oauth/check_token
【发布时间】:2015-04-22 04:32:43
【问题描述】:

我已经使用 spring-security 3.2.* 和 javaconfig 成功启用了“/oauth/check_token”端点,但目前我仅限于 spring-security 3.1.4,然后我被困在 XML 配置中。 '/oauth/token' 端点正在按我的意愿工作,但我无法启用 check_token 端点,也找不到任何(非 javaconfig)文档来解释该怎么做。

Vanila 授权服务器配置:

<oauth:authorization-server 
        client-details-service-ref="client-service" 
        token-services-ref="tokenServices" >
    <oauth:refresh-token disabled="false" />
    <oauth:client-credentials disabled="false" />
    <oauth:password authentication-manager-ref="userAuthenticationManager"  />       
</oauth:authorization-server>

http 安全配置:

<sec:http 
        auto-config="true"
        pattern="/oauth/token" 
        create-session="stateless"
        authentication-manager-ref="clientAuthenticationManager">
    <sec:intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
    <sec:anonymous enabled="false"/>
    <sec:http-basic entry-point-ref="clientAuthenticationEntryPoint" />
</sec:http>

我尝试添加以下 http 配置但没有成功。

<sec:http 
        auto-config="true"
        pattern="/oauth/check_token" 
        create-session="stateless"
        authentication-manager-ref="clientAuthenticationManager">
    <sec:intercept-url pattern="/oauth/check_token" access="IS_AUTHENTICATED_FULLY" />
    <sec:anonymous enabled="false"/>
    <sec:http-basic entry-point-ref="clientAuthenticationEntryPoint" />
</sec:http>

请有任何建议。一个可行的例子会很棒。

最好的 ./克里斯托弗

【问题讨论】:

  • 最后一个 sn-p 有利于保护端点。要将其公开给 HTTP 客户端,您还需要创建一个 CheckTokenEndpoint 类型的 bean。

标签: spring spring-security spring-security-oauth2


【解决方案1】:

您需要创建一个 CheckTokenEndpoint (org.springframework.security.oauth2.provider.endpoint.CheckTokenEndpoint) 类型的 bean。

【讨论】:

    【解决方案2】:

    使用最新版本的spring oauth2:

    <dependency>
      <groupId>org.springframework.security.oauth</groupId>
      <artifactId>spring-security-oauth2</artifactId>
      <version>2.0.10.RELEASE</version>
    </dependency>
    

    确保在spring security oauth文件配置中使用了正确版本的xsd:

    http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
    

    在元素authorization-server中插入选项check-token-enabled="true"

    <oauth:authorization-server ... check-token-enabled="true">
    ... 
    </oauth:authorization-server>
    

    【讨论】:

      猜你喜欢
      • 2016-02-23
      • 2015-01-01
      • 2020-09-05
      • 2021-12-12
      • 2016-09-29
      • 2020-01-16
      • 2016-02-29
      • 2018-07-23
      • 1970-01-01
      相关资源
      最近更新 更多