クラス 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() の値がサービスとして使用されます。つまり、ServiceProperties.getService()filterProcessesUrl と同じ値を指定することが重要です。

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

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

指定した場合、フィルターは 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 として 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()
  • メソッドの詳細