2013-01-25 17 views
6

公式のチュートリアルSparklr2/Tonr2に基づいて私自身の例を実装しようとしています。すべてがよさそうだが、私は私のTonr2実装、春のセキュリティフィルタにweb.xmlから削除すると、私は例外を持っている:春のセキュリティoauth 2簡単な例

ありませんが、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> 

は、私はちょうど私のクライアントは、春のセキュリティなしで仕事をしたいです。保護されたリソースが必要な場合は、プロバイダ側でのみログインしたいと考えています。あなたがここに貼り付け

+0

あなたはそれを完了できましたか?あなたがしたことを実証するコードがありますか?私は同じことを学ぼうとしています – daydreamer

答えて

10

あなたは第二XMLはのOAuthプロバイダとあなたのケースで同じWebアプリケーションで実行保護されたリソース、のための春のXMLです。 (あなたが望むのであれば、もちろんそれらを分けることができます)。

クライアント(1番目の貼り付け済みXML)は別の話です。私があなたを正しく理解していれば、あなたのクライアントはSpringの助けなしに(通常のwebappで、spring-security-oauth-client webappではなく)実行したいと思っています。

oAuthの仕組みを理解する必要があります。クライアントは保護されたリソースにアクセスしようとします。アクセストークンを持たない場合は、oAuth-provider(ログインページを表示しトークンを提供する)にリダイレクトされます。 By the standardの場合、アクセストークンの要求には "redirect-uri"パラメータが含まれていなければなりません。したがって、ログインに成功した後、oAuth-providerはクライアントのリダイレクト先を認識します。 oAuthクライアントはあなたのためにそれを行い、web.xmlから "oauth client"を削除した場合は、これを自分で実装する必要があります。

ご回答ありがとうございます。しかし、私はまだばね のセキュリティが私のoAuthクライアントにどのように影響するのか理解していません。そして私はクライアント側のために spring-oauth(spring-mvc)をspring-securityなしで使用できますか?

あなたがXMLでこの行を書く:

< oauth:client id="oauth2ClientFilter" /> 

それはあなたが春、セキュリティ上に構築されたOAuthのた​​めの専用パッケージです春・セキュリティのOAuthを、使用することを意味します。うんざりすると、クライアントに関連するoAuthを処理するチェーンに特別なフィルタ(OAuth2ClientContextFilter)が置かれます。そのうちの1人がすべてのパラメータでリクエストを送信しています(「redirect-uri」もその1つです)。

あなたは春・セキュリティのOAuthを使用しない場合、よく - あなたは自分でこのロジックを実装する必要があります...

希望に役立ちます!

+0

あなたの答えをありがとう。しかし、私はまだoAuthクライアントにどのように春のセキュリティの流入を理解していない。そして私はクライアント側のspring-oauth(spring-mvc)をspring-securityなしで使用できますか? – chaldaean

+2

おはようありがとう、あなたの答えは確かに私が理解するのを助けた。 – chaldaean

+0

@chaldaeanあなたはそれを訂正してsecurity.xmlファイル全体をデモすることができます – PRASANTHMV

関連する問題