クラス CasAuthenticationFilter

java.lang.ObjectSE
org.springframework.web.filter.GenericFilterBean
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
org.springframework.security.cas.web.CasAuthenticationFilter
実装されたすべてのインターフェース:
jakarta.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 を処理する際、ticket を検証するときに、ServiceProperties.getService() の値が service として使用されます。つまり、ServiceProperties.getService()filterProcessesUrl と同じ値を指定することが重要です。

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

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

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

プロキシチケット

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

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

AuthenticationManager に関する注記

構成された AuthenticationManager は、この特別な principal 名を含む CasServiceTicketAuthenticationToken を認識し、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.apereo.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.apereo.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>
 
  • コンストラクターの詳細

    • CasAuthenticationFilter

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

    • successfulAuthentication

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

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

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

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

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

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

      public final void setProxyAuthenticationFailureHandler(AuthenticationFailureHandler proxyFailureHandler)
      プロキシリクエストの AuthenticationFailureHandler を設定します。
      パラメーター:
      proxyFailureHandler -
    • setAuthenticationFailureHandler

      public final void setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler)
      AuthenticationFailureHandler をラップして、プロキシチケット認証の失敗とサービスチケットの失敗の処理を区別します。
      オーバーライド:
      クラス AbstractAuthenticationProcessingFiltersetAuthenticationFailureHandler 
    • setProxyReceptorUrl

      public final void setProxyReceptorUrl(StringSE proxyReceptorUrl)
    • setProxyGrantingTicketStorage

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

      public final void setServiceProperties(ServiceProperties serviceProperties)
    • setSecurityContextRepository

      public void setSecurityContextRepository(SecurityContextRepository securityContextRepository)
      クラスからコピーされた説明: AbstractAuthenticationProcessingFilter
      認証が成功したときに SecurityContext を保存するように SecurityContextRepository を設定します。デフォルトのアクションは、SecurityContext を保存しないことです。
      オーバーライド:
      クラス AbstractAuthenticationProcessingFiltersetSecurityContextRepository 
      パラメーター:
      securityContextRepository - 使用する SecurityContextRepository。null にはできません。
    • setSecurityContextHolderStrategy

      public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
      クラスからコピーされた説明: AbstractAuthenticationProcessingFilter
      使用する SecurityContextHolderStrategy を設定します。デフォルトのアクションは、SecurityContextHolder に格納されている SecurityContextHolderStrategy を使用することです。
      オーバーライド:
      クラス AbstractAuthenticationProcessingFiltersetSecurityContextHolderStrategy 
    • setRedirectStrategy

      public final void setRedirectStrategy(RedirectStrategy redirectStrategy)
      保存されたリクエストがある場合、保存されたリクエストにリダイレクトするために使用される RedirectStrategy を設定します。デフォルトは DefaultRedirectStrategy です。
      パラメーター:
      redirectStrategy - 使用するリダイレクト戦略
      導入:
      6.3
    • setRequestCache

      public final void setRequestCache(RequestCache requestCache)
      ゲートウェイ認証が失敗したシナリオで保存されたリクエストを取得するために使用される RequestCache
      パラメーター:
      requestCache - 使用するリクエストキャッシュ
      導入:
      6.3