【发布时间】:2015-08-26 18:14:18
【问题描述】:
您好,我必须在我的项目中集成 spring security oauth2。所以我添加了配置相关的部分并且它工作正常。但问题是令牌的第一个请求转到 "/oauth/token" ,我想将其更改为 "api/v1/token" 。
我搜索并找到了一些解决方案,例如在oauth:authorization-server 中添加token-endpoint-url,还添加了将覆盖ClientCredentialsTokenEndpointFilter 的自定义过滤器类并将url 传递给构造函数。但这些都不起作用。
我收到以下错误请求“api/v1/token”-
在 SecurityContext 中找不到 Authentication 对象
我的配置主要是基于xml的。 Spring-security.xml 文件-
<http pattern="/api/v1/token" create-session="stateless"
authentication-manager-ref="authenticationManager"
xmlns="http://www.springframework.org/schema/security" >
<intercept-url pattern="/api/v1/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint"/>
<custom-filter ref="customClientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<http pattern="/test/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/test/**" access="ROLE_USER" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<beans:bean id="oauthAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
</beans:bean>
<beans:bean id="oauthAccessDeniedHandler"
class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler">
</beans:bean>
<beans:bean id="clientAuthenticationEntryPoint"
class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<beans:property name="realmName" value="springsec/client" />
<beans:property name="typeName" value="Basic" />
</beans:bean>
<beans:bean id="customClientCredentialsTokenEndpointFilter"
class="com.walletdoc.oauth.web.security.CustomClientCredentialsTokenEndpointFilter">
<beans:property name="authenticationManager" ref="authenticationManager" />
</beans:bean>
<authentication-manager alias="authenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<beans:bean id="clientDetails" class="com.walletdoc.oauth.web.security.SpringSecurityClientService">
<beans:property name="id" value="mysupplycompany" />
<beans:property name="secretKey" value="mycompanykey" />
<beans:property name="authorities" value="ROLE_CLIENT" />
</beans:bean>
<beans:bean id="clientDetailsUserService"
class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<beans:constructor-arg ref="clientDetails"/>
</beans:bean>
<authentication-manager id="userAuthenticationManager"
xmlns="http://www.springframework.org/schema/security">
<authentication-provider ref="customUserAuthenticationProvider">
</authentication-provider>
</authentication-manager>
<beans:bean id="customUserAuthenticationProvider"
class="com.walletdoc.oauth.web.security.ClientAuthenticationProvider">
</beans:bean>
<oauth:authorization-server
client-details-service-ref="clientDetails" token-services-ref="tokenServices" token-endpoint-url="/api/v1/token">
<oauth:authorization-code />
<oauth:implicit/>
<oauth:refresh-token/>
<oauth:client-credentials />
<oauth:password authentication-manager-ref="userAuthenticationManager" />
</oauth:authorization-server>
<oauth:resource-server id="resourceServerFilter"
resource-id="springsec" token-services-ref="tokenServices" />
<beans:bean id="tokenStore"
class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore" />
<beans:bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<beans:property name="tokenStore" ref="tokenStore" />
<beans:property name="supportRefreshToken" value="true" />
<beans:property name="accessTokenValiditySeconds" value="3600"></beans:property>
<beans:property name="clientDetailsService" ref="clientDetails" />
</beans:bean>
从过去 2 天开始,我一直在尝试解决此问题,因此我们将不胜感激。
【问题讨论】:
标签: java spring-security-oauth2