我尝试基于官方教程Sparklr2 2/Tonr2 2实现我自己的示例。一切看起来都很好,但是当我从web.xml中删除Tonr2实现中的spring安全过滤器时,我有例外:
没有为当前请求建立重定向URI。
我不明白我应该使用什么URL。下面是我的代码,用于客户端实现:
<!--apply the oauth client context -->
<oauth:client id="oauth2ClientFilter" />
<!--define an oauth 2 resource for sparklr -->
<oauth:resource id="provider" type="authorization_code" client-id="client" client-secret="secret"
access-token-uri="http://localhost:8080/provider/oauth/token" user-authorization-uri="http://localhost:8080/provider/oauth/authorize" scope="read,write" />
<beans:bean id="clientController" class="com.aouth.client.ClientController">
<beans:property name="trustedClientRestTemplate">
<oauth:rest-template resource="provider" />
</beans:property>
</beans:bean>对于提供者:
<http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic />
</http>
<authentication-manager id="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security">
<authentication-provider user-service-ref="clientDetailsUserService" />
</authentication-manager>
<bean id="clientDetailsUserService" class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetails" />
</bean>
<!-- The OAuth2 protected resources are separated out into their own block so we can deal with authorization and error handling
separately. This isn't mandatory, but it makes it easier to control the behaviour. -->
<http pattern="/secured" create-session="never" access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="false" />
<intercept-url pattern="/secured" access="ROLE_USER,SCOPE_READ" />
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<http-basic />
</http>
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased" xmlns="http://www.springframework.org/schema/beans">
<constructor-arg>
<list>
<bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter" />
<bean class="org.springframework.security.access.vote.RoleVoter" />
<bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
</list>
</constructor-arg>
</bean>
<oauth:resource-server id="resourceServerFilter" resource-id="resource" token-services-ref="tokenServices" />
<bean id="tokenServices" class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="tokenStore" />
<property name="supportRefreshToken" value="true" />
<property name="clientDetailsService" ref="clientDetails"/>
</bean>
<bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore" />
<http auto-config="true" xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/test" access="ROLE_USER" />
<intercept-url pattern="/" access="IS_AUTHENTICATED_ANONYMOUSLY" />
</http>
<authentication-manager alias="authenticationManager" xmlns="http://www.springframework.org/schema/security">
<authentication-provider>
<user-service>
<user name="pr" password="pr" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
<oauth:authorization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices" >
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<oauth:password />
</oauth:authorization-server>
<oauth:client-details-service id="clientDetails">
<oauth:client client-id="client" resource-ids="resource" authorized-grant-types="authorization_code, implicit"
authorities="ROLE_CLIENT" scope="read,write" secret="secret" />
</oauth:client-details-service>我只想让我的客户在没有弹簧保安的情况下工作。当我需要我的受保护资源时,我只想在提供者端登录。
发布于 2013-01-25 15:57:24
您在这里粘贴的第二个XML是用于oauth-provider和protected-resource,的spring的XML,在您的示例中,它们运行在同一个webapp应用程序中。(当然,如果你愿意的话,你可以把它们分开)。
客户端(第一个粘贴-XML)是一个不同的故事。如果我对您的理解正确,您希望您的客户端在没有spring帮助的情况下运行(是一个常规的webapp,而不是spring-security-oauth-client and应用程序)。
您必须了解oAuth是如何工作的:客户机试图访问受保护的资源;如果它没有访问令牌,那么它将被重定向到oAuth(它显示登录页面并提供令牌)。按标准,对访问令牌的请求必须包含“重定向-uri”param,因此在成功登录后,oAuth提供者知道将客户端重定向到何处。oAuth客户端为您做这件事,如果您从您的web.xml中删除了"oauth“,那么现在您必须自己实现它。
谢谢你的回答。但我仍然不明白spring安全性如何影响我的oAuth客户端。我是否可以使用客户端spring(Spring)而没有spring-安全性?
当您用XML编写这一行时:
< oauth:client id="oauth2ClientFilter" />这意味着您使用,它是一个专门为oauth服务的包,构建在spring安全基础上。如果您深入研究,它会在处理与客户端相关的OAuth2ClientContextFilter内容的链中添加一个特殊过滤器( oAuth )。其中之一是发送请求与所有参数(“重定向-uri”是其中之一)。
如果你决定不使用spring-security-oauth,那么-你必须自己实现这个逻辑.
希望这能帮上忙!
https://stackoverflow.com/questions/14522634
复制相似问题