クラス CasAuthenticationFilter
- 実装されたすべてのインターフェース:
jakarta.servlet.Filter
、org.springframework.beans.factory.Aware
、org.springframework.beans.factory.BeanNameAware
、org.springframework.beans.factory.DisposableBean
、org.springframework.beans.factory.InitializingBean
、org.springframework.context.ApplicationEventPublisherAware
、org.springframework.context.EnvironmentAware
、org.springframework.context.MessageSourceAware
、org.springframework.core.env.EnvironmentCapable
、org.springframework.web.context.ServletContextAware
サービスチケット
サービスチケットは、不透明なチケット文字列で構成されます。ユーザーのブラウザーが 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>
フィールドサマリー
クラス org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter から継承されたフィールド
authenticationDetailsSource, eventPublisher, messages
クラス org.springframework.web.filter.GenericFilterBean から継承されたフィールド
logger
コンストラクターのサマリー
コンストラクターメソッドのサマリー
修飾子と型メソッド説明attemptAuthentication
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) 実際の認証を実行します。protected StringSE
obtainArtifact
(jakarta.servlet.http.HttpServletRequest request) 存在する場合は、HttpServletRequest
からアーティファクト(CAS チケット)を取得します。protected boolean
requiresAuthentication
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) プロキシ機能を提供するためにオーバーライドされます。final void
setAuthenticationFailureHandler
(AuthenticationFailureHandler failureHandler) AuthenticationFailureHandler
をラップして、プロキシチケット認証の失敗とサービスチケットの失敗の処理を区別します。final void
setProxyAuthenticationFailureHandler
(AuthenticationFailureHandler proxyFailureHandler) プロキシリクエストのAuthenticationFailureHandler
を設定します。final void
setProxyGrantingTicketStorage
(org.apereo.cas.client.proxy.ProxyGrantingTicketStorage proxyGrantingTicketStorage) final void
setProxyReceptorUrl
(StringSE proxyReceptorUrl) final void
setRedirectStrategy
(RedirectStrategy redirectStrategy) 保存されているリクエストがある場合、保存されているリクエストにリダイレクトするために使用されるRedirectStrategy
を設定します。final void
setRequestCache
(RequestCache requestCache) ゲートウェイ認証が失敗したシナリオで保存されたリクエストを取得するために使用されるRequestCache
。void
setSecurityContextHolderStrategy
(SecurityContextHolderStrategy securityContextHolderStrategy) 使用するSecurityContextHolderStrategy
を設定します。void
setSecurityContextRepository
(SecurityContextRepository securityContextRepository) 認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。final void
setServiceProperties
(ServiceProperties serviceProperties) protected final void
successfulAuthentication
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain, Authentication authResult) 認証成功のデフォルトの動作。クラス org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter から継承されたメソッド
afterPropertiesSet, doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSessionAuthenticationStrategy, unsuccessfulAuthentication
クラス org.springframework.web.filter.GenericFilterBean から継承されたメソッド
addRequiredProperty, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
コンストラクターの詳細
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
認証成功のデフォルトの動作。SecurityContextHolder
で成功した Authentication オブジェクトを設定します- ログインの成功を構成済みの RememberMeServices に通知します
- 構成された ApplicationEventPublisher を介して
InteractiveAuthenticationSuccessEvent
を起動します - 追加の動作を
AuthenticationSuccessHandler
に委譲します。
FilterChain
を続行できます。- オーバーライド:
- クラス
AbstractAuthenticationProcessingFilter
のsuccessfulAuthentication
authResult
- attemptAuthentication メソッドから返されたオブジェクト。- 例外:
IOExceptionSE
jakarta.servlet.ServletException
attemptAuthentication
public Authentication attemptAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws AuthenticationException, IOExceptionSE クラスからコピーされた説明:AbstractAuthenticationProcessingFilter
実際の認証を実行します。実装では、次のいずれかを実行する必要があります。
- 認証されたユーザーの移入された認証トークンを返し、認証の成功を示します
- 認証プロセスがまだ進行中であることを示す null を返します。戻る前に、実装はプロセスを完了するために必要な追加作業を実行する必要があります。
- 認証プロセスが失敗した場合、 AuthenticationException をスローします
- 次で指定:
- クラス
AbstractAuthenticationProcessingFilter
のattemptAuthentication
- パラメーター:
request
- パラメーターの抽出元および認証の実行元response
- レスポンス。これは、実装が多段階認証プロセス (OIDC など) の一部としてリダイレクトを行う必要がある場合に必要になる場合があります。- 戻り値:
- 認証されたユーザートークン。認証が不完全な場合は null
- 例外:
AuthenticationException
- 認証が失敗した場合。IOExceptionSE
obtainArtifact
存在する場合は、HttpServletRequest
からアーティファクト(CAS チケット)を取得します。- パラメーター:
request
-- 戻り値:
HttpServletRequest
からのアーティファクトが存在する場合、それ以外の場合は null
requiresAuthentication
protected boolean requiresAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) プロキシ機能を提供するためにオーバーライドされます。- オーバーライド:
- クラス
AbstractAuthenticationProcessingFilter
のrequiresAuthentication
- 戻り値:
- フィルターが認証を試行する必要がある場合は
true
、そうでない場合はfalse
。
setProxyAuthenticationFailureHandler
public final void setProxyAuthenticationFailureHandler(AuthenticationFailureHandler proxyFailureHandler) プロキシリクエストのAuthenticationFailureHandler
を設定します。- パラメーター:
proxyFailureHandler
-
setAuthenticationFailureHandler
AuthenticationFailureHandler
をラップして、プロキシチケット認証の失敗とサービスチケットの失敗の処理を区別します。setProxyReceptorUrl
setProxyGrantingTicketStorage
public final void setProxyGrantingTicketStorage(org.apereo.cas.client.proxy.ProxyGrantingTicketStorage proxyGrantingTicketStorage) setServiceProperties
setSecurityContextRepository
クラスからコピーされた説明:AbstractAuthenticationProcessingFilter
認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。デフォルトのアクションは、SecurityContext
を保存しないことです。- オーバーライド:
- クラス
AbstractAuthenticationProcessingFilter
のsetSecurityContextRepository
- パラメーター:
securityContextRepository
- 使用するSecurityContextRepository
。null にはできません。
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) クラスからコピーされた説明:AbstractAuthenticationProcessingFilter
使用するSecurityContextHolderStrategy
を設定します。デフォルトのアクションは、SecurityContextHolder
に格納されているSecurityContextHolderStrategy
を使用することです。setRedirectStrategy
保存されたリクエストがある場合、保存されたリクエストにリダイレクトするために使用されるRedirectStrategy
を設定します。デフォルトはDefaultRedirectStrategy
です。- パラメーター:
redirectStrategy
- 使用するリダイレクト戦略- 導入:
- 6.3
setRequestCache
ゲートウェイ認証が失敗したシナリオで保存されたリクエストを取得するために使用されるRequestCache
。- パラメーター:
requestCache
- 使用するリクエストキャッシュ- 導入:
- 6.3