クラス CasAuthenticationFilter

  • 実装されたすべてのインターフェース:
    javax.servlet.Filterorg.springframework.beans.factory.Awareorg.springframework.beans.factory.BeanNameAwareorg.springframework.beans.factory.DisposableBeanorg.springframework.beans.factory.InitializingBeanorg.springframework.context.ApplicationEventPublisherAwareorg.springframework.context.EnvironmentAwareorg.springframework.context.MessageSourceAwareorg.springframework.core.env.EnvironmentCapableorg.springframework.web.context.ServletContextAware

    public class CasAuthenticationFilter
    extends AbstractAuthenticationProcessingFilter
    CAS サービスチケットを処理し、代理許可チケットを取得して、代理チケットを処理します。

    サービスチケット

    サービスチケットは、不透明なチケット文字列で構成されています。CAS を使用して正常に認証され、service への HTTP リダイレクトを受信すると、ユーザーのブラウザーによってこのフィルターに到達します。不透明なチケット文字列は、ticket リクエストパラメーターに表示されます。

    このフィルターは service URL を監視して、サービスチケットを受信して処理できるようにします。デフォルトでは、このフィルターは URL /login/cas を処理します。この URL を処理するとき、ServiceProperties.getService() の値は ticket を検証するときにサービスとして使用されます。これは、ServiceProperties.getService() filterProcessesUrl と同じ値を指定することが重要であることを意味します。

    サービスチケットの処理には、principal に CAS_STATEFUL_IDENTIFIER を使用し、credentials として不透明なチケット文字列を使用する UsernamePasswordAuthenticationToken を作成することが含まれます。

    プロキシ付与チケットの取得

    指定した場合、フィルターは proxyReceptorUrl もモニターできます。フィルターは、CAS サーバーがフィルターに PGT を提供できるように、この URL に一致するリクエストに応答します。フィルターがプロキシレセプタリクエストに応答するには、proxyReceptorUrl に加えて null 以外の proxyGrantingTicketStorage を提供する必要があることに注意してください。TicketValidator と CasAuthenticationFilter の間で共有 ProxyGrantingTicketStorage を構成することにより、CasAuthenticationFilter に CAS のプロキシ要件を処理させることができます。

    プロキシチケット

    フィルターは、任意の URL に存在するチケットを処理できます。これは、プロキシチケットを処理する場合に役立ちます。プロキシチケットが処理されるためには、ServiceProperties.isAuthenticateAllArtifacts() は true を返す必要があります。さらに、リクエストがすでに認証されている場合、認証は行われません。最後に、AuthenticationDetailsSource.buildDetails(Object)ServiceAuthenticationDetails を返す必要があります。これは、ServiceAuthenticationDetailsSource を使用して実行できます。この場合、ServiceAuthenticationDetails.getServiceUrl() がサービス URL に使用されます。

    プロキシチケットの処理には、principal に CAS_STATELESS_IDENTIFIER を使用し、credentials として不透明なチケット文字列を使用する UsernamePasswordAuthenticationToken を作成することが含まれます。プロキシチケットが正常に認証されると、FilterChain は続行され、authenticationSuccessHandler は使用されません。

    AuthenticationManager に関する注記

    構成された AuthenticationManager は、この特別な principal 名を含む UsernamePasswordAuthenticationToken を認識し、CAS サーバーでの検証によって処理できるプロバイダーを提供することが期待されています。さらに、チケットを検証するときに、ServiceAuthenticationDetails.getServiceUrl() の結果をサービスとして使用できる必要があります。

    構成例

    サービスチケット、プロキシ付与チケットの取得、プロキシチケットをサポートする構成例を以下に示します。

     <b:bean id="serviceProperties"
         class="org.springframework.security.cas.ServiceProperties"
         p:service="https://service.example.com/cas-sample/login/cas"
         p:authenticateAllArtifacts="true"/>
     <b:bean id="casEntryPoint"
         class="org.springframework.security.cas.web.CasAuthenticationEntryPoint"
         p:serviceProperties-ref="serviceProperties" p:loginUrl="https://login.example.org/cas/login" />
     <b:bean id="casFilter"
         class="org.springframework.security.cas.web.CasAuthenticationFilter"
         p:authenticationManager-ref="authManager"
         p:serviceProperties-ref="serviceProperties"
         p:proxyGrantingTicketStorage-ref="pgtStorage"
         p:proxyReceptorUrl="/login/cas/proxyreceptor">
         <b:property name="authenticationDetailsSource">
             <b:bean class="org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource"/>
         </b:property>
         <b:property name="authenticationFailureHandler">
             <b:bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"
                 p:defaultFailureUrl="/casfailed.jsp"/>
         </b:property>
     </b:bean>
     <!--
         NOTE: In a real application you should not use an in memory implementation. You will also want
               to ensure to clean up expired tickets by calling ProxyGrantingTicketStorage.cleanup()
      -->
     <b:bean id="pgtStorage" class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl"/>
     <b:bean id="casAuthProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider"
         p:serviceProperties-ref="serviceProperties"
         p:key="casAuthProviderKey">
         <b:property name="authenticationUserDetailsService">
             <b:bean
                 class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
                 <b:constructor-arg ref="userService" />
             </b:bean>
         </b:property>
         <b:property name="ticketValidator">
             <b:bean
                 class="org.jasig.cas.client.validation.Cas20ProxyTicketValidator"
                 p:acceptAnyProxy="true"
                 p:proxyCallbackUrl="https://service.example.com/cas-sample/login/cas/proxyreceptor"
                 p:proxyGrantingTicketStorage-ref="pgtStorage">
                 <b:constructor-arg value="https://login.example.org/cas" />
             </b:bean>
         </b:property>
         <b:property name="statelessTicketCache">
             <b:bean class="org.springframework.security.cas.authentication.EhCacheBasedTicketCache">
                 <b:property name="cache">
                     <b:bean class="net.sf.ehcache.Cache"
                       init-method="initialise"
                       destroy-method="dispose">
                         <b:constructor-arg value="casTickets"/>
                         <b:constructor-arg value="50"/>
                         <b:constructor-arg value="true"/>
                         <b:constructor-arg value="false"/>
                         <b:constructor-arg value="3600"/>
                         <b:constructor-arg value="900"/>
                     </b:bean>
                 </b:property>
             </b:bean>
         </b:property>
     </b:bean>
     
    • フィールドの詳細

      • CAS_STATEFUL_IDENTIFIER

        public static final java.lang.String CAS_STATEFUL_IDENTIFIER
        Web ブラウザーなどのステートフルユーザーエージェントに対する CAS リクエストを識別するために使用されます。
        関連事項:
        定数フィールド値
      • CAS_STATELESS_IDENTIFIER

        public static final java.lang.String CAS_STATELESS_IDENTIFIER
        リモーティングプロトコルクライアント(Hessian、Burlap、SOAP など)などのステートレスユーザーエージェントの CAS リクエストを識別するために使用されます。HttpSession がない場合、すべてのリクエストで新しい認証が試行されるため、より積極的なキャッシュ戦略が使用されます。
        関連事項:
        定数フィールド値
    • コンストラクターの詳細

      • CasAuthenticationFilter

        public CasAuthenticationFilter()
    • メソッドの詳細

      • successfulAuthentication

        protected final void successfulAuthentication​(javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response,
                                                      javax.servlet.FilterChain chain,
                                                      Authentication authResult)
                                               throws java.io.IOException,
                                                      javax.servlet.ServletException
        クラスからコピーされた説明: AbstractAuthenticationProcessingFilter
        認証成功のデフォルトの動作。
        1. SecurityContextHolder で成功した Authentication オブジェクトを設定します
        2. ログインの成功を構成済みの RememberMeServices に通知します
        3. 構成された ApplicationEventPublisher を介して InteractiveAuthenticationSuccessEvent を起動します
        4. 追加の動作を AuthenticationSuccessHandler に委譲します。
        認証が成功した後、サブクラスはこのメソッドをオーバーライドして FilterChain を続行できます。
        オーバーライド:
        クラス AbstractAuthenticationProcessingFiltersuccessfulAuthentication 
        authResult - attemptAuthentication メソッドから返されたオブジェクト。
        例外:
        java.io.IOException
        javax.servlet.ServletException
      • attemptAuthentication

        public Authentication attemptAuthentication​(javax.servlet.http.HttpServletRequest request,
                                                    javax.servlet.http.HttpServletResponse response)
                                             throws AuthenticationException,
                                                    java.io.IOException
        クラスからコピーされた説明: AbstractAuthenticationProcessingFilter
        実際の認証を実行します。

        実装では、次のいずれかを実行する必要があります。

        1. 認証されたユーザーの移入された認証トークンを返し、認証の成功を示します
        2. 認証プロセスがまだ進行中であることを示す null を返します。戻る前に、実装はプロセスを完了するために必要な追加作業を実行する必要があります。
        3. 認証プロセスが失敗した場合、 AuthenticationException をスローします
        次で指定:
        クラス AbstractAuthenticationProcessingFilterattemptAuthentication 
        パラメーター:
        request - パラメーターの抽出元および認証の実行元
        response - レスポンス。実装がマルチステージ認証プロセス(OpenID など)の一部としてリダイレクトを行う必要がある場合に必要になる場合があります。
        戻り値:
        認証されたユーザートークン。認証が不完全な場合は null
        例外:
        AuthenticationException - 認証が失敗した場合。
        java.io.IOException
      • obtainArtifact

        protected java.lang.String obtainArtifact​(javax.servlet.http.HttpServletRequest request)
        存在する場合は、HttpServletRequest からアーティファクト(CAS チケット)を取得します。
        パラメーター:
        request -
        戻り値:
        HttpServletRequest からのアーティファクトが存在する場合、それ以外の場合は null
      • requiresAuthentication

        protected boolean requiresAuthentication​(javax.servlet.http.HttpServletRequest request,
                                                 javax.servlet.http.HttpServletResponse response)
        プロキシ機能を提供するためにオーバーライドされます。
        オーバーライド:
        クラス AbstractAuthenticationProcessingFilterrequiresAuthentication 
        戻り値:
        フィルターが認証を試行する必要がある場合は true、そうでない場合は false
      • setProxyReceptorUrl

        public final void setProxyReceptorUrl​(java.lang.String proxyReceptorUrl)
      • setProxyGrantingTicketStorage

        public final void setProxyGrantingTicketStorage​(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage proxyGrantingTicketStorage)
      • setServiceProperties

        public final void setServiceProperties​(ServiceProperties serviceProperties)