Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HTTP头中的Spring OAuth2访问令牌_Java_Spring_Oauth_Spring Security_Spring Security Oauth2 - Fatal编程技术网

Java HTTP头中的Spring OAuth2访问令牌

Java HTTP头中的Spring OAuth2访问令牌,java,spring,oauth,spring-security,spring-security-oauth2,Java,Spring,Oauth,Spring Security,Spring Security Oauth2,我正试图实现SpringOAuth2设置,授权服务器在应用程序中独立运行,资源服务器在单独的应用程序中运行 我将从一开始就说,由于当前的系统限制,我不得不使用较旧版本的Spring/Spring Security,直到我们可以计划系统升级: 弹簧:3.1.1弹簧 保安:3.2.7 Spring OAuth:1.0.5 我的一切工作正常,但是,当我从resource server请求受限资源时,我必须提供access_令牌作为查询参数 我更愿意将其作为HTTP头提供。在SpringSecuri

我正试图实现SpringOAuth2设置,授权服务器在应用程序中独立运行,资源服务器在单独的应用程序中运行

我将从一开始就说,由于当前的系统限制,我不得不使用较旧版本的Spring/Spring Security,直到我们可以计划系统升级:

  • 弹簧:3.1.1弹簧
  • 保安:3.2.7
  • Spring OAuth:1.0.5
我的一切工作正常,但是,当我从resource server请求受限资源时,我必须提供access_令牌作为查询参数

我更愿意将其作为HTTP头提供。在SpringSecurityOAuth中是否有内置的功能来实现这一点

资源服务器配置

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
    xmlns:sec="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.2.xsd
    http://www.springframework.org/schema/security/oauth2
    http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <!-- Resource Server Filter -->
    <oauth:resource-server id="resourceServerFilter" resource-id="someResourceId" token-services-ref="tokenServices"/>
    <!-- END Resource Server Filter -->

    <!-- Protected resources -->
    <http pattern="/rest/BasicService/**" create-session="stateless" xmlns="http://www.springframework.org/schema/security" entry-point-ref="oauthAuthenticationEntryPoint">  
        <anonymous enabled="false"/>
        <intercept-url pattern="/rest/BasicService/**" access="ROLE_USER"/>
        <custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER"/>
        <access-denied-handler ref="oauthAccessDeniedHandler"/> 
    </http>   
    <!-- END Protected resources -->

    <!-- Authentication -->
    <sec:authentication-manager xmlns="http://www.springframework.org/schema/security" /> 
    <bean id="oauthAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint" xmlns="http://www.springframework.org/schema/beans"/>
    <bean id="oauthAccessDeniedHandler" class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler"/>
    <!-- END Authentication -->         

    <!-- Token Store -->    
    <bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.JdbcTokenStore">
        <constructor-arg ref="myJdbcTokenStore" />
    </bean>

    <bean id="myJdbcTokenStore" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/someJNDIDatabaseName"/>
    </bean>

    <bean id="tokenServices" class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
        <property name="tokenStore" ref="tokenStore"/>
    </bean>
    <!-- END Token Store -->

</beans>

正如prtk_shah在评论中提到的,需要将令牌类型添加到授权标头中


授权:Bearer

如果您正在使用spring boot magic,那么您只需要将
authenticationScheme
设置为
标题
。任务完成

security:
  oauth2:
    client:
      ...
      authenticationScheme: header

像这样添加授权头:::授权:承载者啊,我尝试了一个授权头。但是我忘了检查令牌类型。我的理解是,对安全API位置的GET请求不应再次要求身份验证。。。但只是为了提供访问令牌。对吗?我是说。。。对安全资源的请求应仅包括访问令牌。。