2016-05-08 20 views
0

私はSpring Securityの専門家ではありません。 私は1つのanglejsアプリケーションを持っています。これにはOAuth2ベースの認証と承認があります。 もう1つのアプリを追加する必要がありますが、両方のアプリでユーザーとパスワードを同じにする必要があります。 だから私は1つのssoサーバーと2つのリソースサーバーが必要です。 私は現代の春のブーツでそれを実装したいと思います。 現在、私はgrant_type = passwordを使用して/ oauth/tokenに対してユーザーを認証しています ユーザーを認証できるようにするSSOサーバーとリソースサーバーのサンプルがあるかと思います。http://sso.host/oauth/token?username=someuser&password=somepass&grant_type=password ..私はアクセストークンとリフレッシュトークンを成功認証の結果。 とアクセストークンは、リフレッシュトークンは、私は私のアプリはすべてのURLにリダイレクトする必要はありませんhttp://sso.host/oauth/token?grant_type=refreshSpringブートOAuth2 SSO

でaccess_tokensを取得するには良いでしょうしながら、http://resource.host/rest/someresource に対して使用するのが良いでしょう。.. 私は、ログインする必要はありませんフォーム、ちょうどjsonの応答。ここで

は私の現在のspting-セキュリティoauth.xml configです:

<?xml version="1.0" encoding="UTF-8" ?> 

http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security-3.2.xsd http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd「>

<authorization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices" xmlns="http://www.springframework.org/schema/security/oauth2"> 
    <refresh-token /> 
    <client-credentials /> 
    <password authentication-manager-ref="userAuthenticationManager" disabled="false"/> 
</authorization-server> 

<authentication-manager id="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security"> 
    <authentication-provider user-service-ref="clientDetailsUserService" /> 
</authentication-manager> 

<authentication-manager alias="userAuthenticationManager" xmlns="http://www.springframework.org/schema/security"> 
    <authentication-provider> 
     <user-service> 
      <user name="username" password="password" authorities="ROLE_USER" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 

<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 entry-point-ref="clientAuthenticationEntryPoint" /> 
    <custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" /> 
    <access-denied-handler ref="oauthAccessDeniedHandler" /> 
</http> 

<oauth:resource-server id="resourceServerFilter" resource-id="rest_server" token-services-ref="tokenServices" /> 

<oauth:client-details-service id="clientDetails"> 
    <oauth:client client-id="the_client" secret="" scope="read,write" authorized-grant-types="password,refresh_token,client_credentials" authorities="ROLE_USER"/> 
</oauth:client-details-service> 


<http pattern="/rest/**" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint" access-decision-manager-ref="accessDecisionManager" xmlns="http://www.springframework.org/schema/security"> 
    <anonymous enabled="false" /> 

    <intercept-url pattern="/rest/**" access="ROLE_USER" /> 
    <custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" /> 
    <access-denied-handler ref="oauthAccessDeniedHandler" /> 
</http> 

<bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore" /> 

<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" /> 
    <property name="accessTokenValiditySeconds" value="300" /> 
    <property name="refreshTokenValiditySeconds" value="3600" /> 
</bean> 

<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"> 
    <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> 

<bean id="oauthAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"> 
    <property name="realmName" value="test" /> 
</bean> 

<bean id="clientAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"> 
    <property name="realmName" value="theRealm/client" /> 
    <property name="typeName" value="Basic" /> 
</bean> 

<bean id="clientCredentialsTokenEndpointFilter" class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter"> 
    <property name="authenticationManager" ref="clientAuthenticationManager" /> 
</bean> 

<bean id="clientDetailsUserService" class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService"> 
    <constructor-arg ref="clientDetails" /> 
</bean> 

<bean id="oauthAccessDeniedHandler" class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" /> 

<sec:global-method-security pre-post-annotations="enabled" proxy-target-class="true"> 
    <sec:expression-handler ref="oauthExpressionHandler" /> 
</sec:global-method-security> 

<oauth:expression-handler id="oauthExpressionHandler" /> 
<oauth:web-expression-handler id="oauthWebExpressionHandler" /> 


答えて

0

私はあなたが自然にパスワードの許可タイプでSSOを行うことができるとは思いません。あなたはおそらく認証コードの流れに最も適しています。 Oauth2 ssoは、両方のクライアントアプリケーションが認証サーバー上の認証されたセッションをチェックし、すでにログインしている場合は、2番目のアプリケーションが資格情報を再度提供する必要がないために発生します。 https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-vは、anglejsとspring bootの良い例です。

つまり、SSOが必要な場合は、初回ログイン時に承認サーバーにリダイレクトする必要があると思います。

関連する問題