Java HTTP头中的Spring OAuth2访问令牌
我正试图实现SpringOAuth2设置,授权服务器在应用程序中独立运行,资源服务器在单独的应用程序中运行 我将从一开始就说,由于当前的系统限制,我不得不使用较旧版本的Spring/Spring Security,直到我们可以计划系统升级: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
- 弹簧:3.1.1弹簧
- 保安:3.2.7
- Spring OAuth:1.0.5
<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请求不应再次要求身份验证。。。但只是为了提供访问令牌。对吗?我是说。。。对安全资源的请求应仅包括访问令牌。。