[英]Spring OAuth2 Access Token in HTTP Header
我试图在一个应用程序中使用Authorization Server实现Spring Oauth2设置,在单独的应用程序中实现Resource Server。
我将从一开始就说,由于当前的系统限制,我被迫使用旧版本的Spring / Spring Security,直到我们可以计划进行系统升级:
我有一切工作,但是,当我从资源服务器请求受限资源时,我必须提供access_token作为查询参数。
我更愿意将其作为HTTP标头提供。 Spring Security Oauth中是否有内置功能?
资源服务器配置
<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的评论中所提到的,需要将令牌类型添加到Authorization标头中。
授权:持票人
如果你正在使用spring boot magic,可以按照他们的例子 ,你只想将authenticationScheme
设置为header
。 任务完成。
security:
oauth2:
client:
...
authenticationScheme: header
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.