我尝试根据官方教程实现我自己的示例Sparklr2/Tonr2。一切看起来都不错,但是当我从web.xml
in my Tonr2实现,弹簧安全过滤器我有例外:
尚未为当前请求建立重定向 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>
我只是希望我的客户在没有 Spring Security 的情况下工作。当我需要受保护的资源时,我只想在提供者端登录。
您粘贴到此处的第二个 XML 是 spring 的 XMLoauth 提供者和受保护资源,在您的情况下,它在同一个网络应用程序中运行。 (当然,如果您愿意,您可以将它们分开)。
客户端(第一个粘贴的 XML)是一个不同的故事。如果我理解正确的话,您希望您的客户端在没有 Spring 帮助的情况下运行(成为常规 web 应用程序,而不是 spring-security-oauth-client web 应用程序)。
您必须了解 oAuth 的工作原理:客户端尝试访问受保护的资源;如果它没有访问令牌,则会被重定向到 oAuth 提供程序(显示登录页面并提供令牌)。按标准,访问令牌的请求必须包含“redirect-uri”参数,因此成功登录后,oAuth-provider 知道将客户端重定向到哪里。 oAuth 客户端会为您完成此操作,如果您从 web.xml 中删除“oauth 客户端”,您现在必须自己实现此操作。
感谢您的回答。但我还是不明白春天是怎样的
安全性影响我的 oAuth 客户端。我可以用于客户端吗
spring-oauth (spring-mvc) 没有 spring-security?
当您在 XML 中写入以下行时:
< oauth:client id="oauth2ClientFilter" />
这意味着您使用 spring-security-oauth,这是一个专门用于 oauth 的包,基于 spring-security 构建。如果您深入研究,它会在处理与客户端相关的 oAuth 内容的链中放置一个特殊的过滤器 (OAuth2ClientContextFilter)。其中之一是发送带有所有参数的请求(“redirect-uri”就是其中之一)。
如果您决定不使用 spring-security-oauth,那么 - 您将必须自己实现此逻辑......
希望有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)