7

私は公式チュートリアルSparklr2/Tonr2に基づいて自分の例を実装しようとしています。すべてが良さそうに見えますがweb.xmlTonr2実装で削除すると、スプリングセキュリティフィルターに例外があります。

現在のリクエストに対してリダイレクト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>

クライアントに春のセキュリティなしで動作させたいだけです。また、保護されたリソースが必要な場合は、プロバイダー側​​でのみログインしたいと思います。

4

1 に答える 1

10

ここに貼り付けた2番目のXMLは、oauth-providerprotected-resourceのSpringのXMLであり、この場合は同じWebアプリケーションで実行されます。(もちろん、必要に応じて、それらを分離することができます)。

クライアント(最初に貼り付けられたXML)は別の話です。私があなたを正しく理解しているなら、あなたはあなたのクライアントがSpringの助けなしに実行されることを望みます(通常のwebappであり、spring-security-oauth-client webappではありません)。

oAuthがどのように機能するかを理解する必要があります。クライアントは保護されたリソースにアクセスしようとします。アクセストークンがない場合は、oAuthプロバイダーにリダイレクトされます(ログインページが表示され、トークンが提供されます)。標準では、アクセストークンのリクエストには「redirect-uri」パラメータが含まれている必要があるため、ログインが成功すると、oAuthプロバイダーはクライアントのリダイレクト先を認識します。oAuthクライアントがそれを行います。web.xmlから「oauthクライアント」を削除した場合は、これを自分で実装する必要があります。

ご回答有難うございます。しかし、春のセキュリティが私のoAuthクライアントにどのように影響するかはまだわかりません。また、spring-securityなしでクライアント側のspring-oauth(spring-mvc)に使用できますか?

XMLでこの行を書くとき:

< oauth:client id="oauth2ClientFilter" />

これは、spring-securityに基づいて構築されたoauth専用のパッケージであるspring-security-oauthを使用することを意味します。掘り下げると、クライアントに関連するoAuth関連のものを処理する特別なフィルター(OAuth2ClientContextFilter)がチェーンに配置されます。それらの1つは、すべてのパラメーターを使用して要求を送信しています( "redirect-uri"はそれらの1つです)。

spring-security-oauthを使用しないことにした場合は、このロジックを自分で実装する必要があります...

お役に立てば幸いです。

于 2013-01-25T15:57:24.443 に答える