5

同じTomcatインスタンスにデプロイされた2つの異なるWebアプリケーションを使用しています。Webアプリケーションの1つともう1つはRESTサービスです。ユーザーがWebアプリケーションにログインしてRESTサービスを呼び出す場合、RESTはWebアプリケーションを使用してログインしたユーザーで認証する必要があります。tomcatにSSOを実装するにはどうすればよいですか>誰かがそれを実装している場合は、mwを助けてください。

更新: 最初のWebアプリケーションにSpringSecurityとJ2EEPreAuthenticationメカニズムを実装しました。このアプリケーションは、DOJO(JavaScript Framework)を使用して2番目のアプリケーション(RESTサービス)を呼び出します。

更新: 私は解決策を見つけました。以下の私の答えを読んでください。

4

2 に答える 2

6

従来の Web アプリケーションと、RESTful Web サービスのような非 Web ベースのアプリケーションとの間で SSO を実装できます。この例は、Web アプリケーションと RESTful Web サービス間の SSO を実装するためのサンプル コードを示しています。spring-security.xmlファイル内の構成は次のとおりです。

<security:http create-session="never" use-expressions="true" 
                   auto-config="false" 
                   entry-point-ref="preAuthenticatedProcessingFilterEntryPoint" >

        <security:intercept-url pattern="/**" access="permitAll"/>
        <security:intercept-url pattern="/admin/**" access="hasRole('tomcat')"/>
        <security:intercept-url pattern="/**" access="hasRole('tomcat')"/>
        <security:custom-filter position="PRE_AUTH_FILTER" ref="preAuthFilter"/>
        <!-- Required for Tomcat, will prompt for username / password twice otherwise -->
        <security:session-management session-fixation-protection="none"/>
    </security:http>

    <bean id="preAuthenticatedProcessingFilterEntryPoint"
                class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"/>

    <bean id="preAuthFilter"
                class="org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter">
        <property name="authenticationManager" ref="appControlAuthenticationManager"/>
        <property name="authenticationDetailsSource"
                        ref="j2eeBasedPreAuthenticatedWebAuthenticationDetailsSource"/>
    </bean> 

    <security:authentication-manager alias="appControlAuthenticationManager">
        <security:authentication-provider ref="preAuthenticatedAuthenticationProvider"/>
    </security:authentication-manager>

    <bean id="preAuthenticatedAuthenticationProvider"
                class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
        <property name="preAuthenticatedUserDetailsService" ref="inMemoryAuthenticationUserDetailsService"/>
    </bean>

    <bean id="j2eeBasedPreAuthenticatedWebAuthenticationDetailsSource"
                class="org.springframework.security.web.authentication.preauth.j2ee.J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource">
        <property name="mappableRolesRetriever" ref="webXmlMappableAttributesRetriever"/>
        <property name="userRoles2GrantedAuthoritiesMapper" ref="simpleAttributes2GrantedAuthoritiesMapper"/>
    </bean>

    <bean id="webXmlMappableAttributesRetriever"
                class="org.springframework.security.web.authentication.preauth.j2ee.WebXmlMappableAttributesRetriever"/>

    <bean id="simpleAttributes2GrantedAuthoritiesMapper"
                class="org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper">
        <property name="attributePrefix" value=""/>
    </bean>

    <bean id="inMemoryAuthenticationUserDetailsService"
                class="com.org.InMemoryAuthenticationUserDetailsService"/> 

上記のコードは Web アプリケーションにあります。また、REST プロジェクトの spring security xml ファイルにも同じコードを含めることができます。web.xml次のコードをファイルに追加します。

<security-constraint>
        <web-resource-collection>
            <web-resource-name>Wildcard means whole app requires authentication</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>tomcat</role-name>
        </auth-constraint>

        <user-data-constraint>
            <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/error.jsp</form-error-page>
        </form-login-config>
    </login-config>

上記のコードは、通常の Web アプリケーションにのみ含める必要があります。次に、Tomcat のserver.xmlファイルで SSO バルブを有効にします。Tomcat は Cookie ベースの SSO ログインを使用します。セッション ID は Cookie に保存されます。ブラウザで Cookie が無効になっている場合、SSO は機能しません。

この説明がお役に立てば幸いです。

于 2012-06-08T09:48:00.453 に答える
1

Tomcat はすぐに使用できる SSO 機能 (構成あり) を提供しますが、独自の認証メカニズムで動作します。Tomcat のコンテナー管理の SSO とアプリケーション管理 (この場合は Spring) の認証メカニズムを組み合わせることができるとは思えません。

Spring の SSO 機能が存在する場合は、それを調べる必要があります。

于 2012-06-07T18:59:03.723 に答える