クラス CasAuthenticationFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
-
- org.springframework.security.cas.web.CasAuthenticationFilter
- 実装されたすべてのインターフェース:
javax.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
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>
フィールドサマリー
フィールド 修飾子と型 フィールド 説明 static java.lang.String
CAS_STATEFUL_IDENTIFIER
Web ブラウザーなどのステートフルユーザーエージェントに対する CAS リクエストを識別するために使用されます。static java.lang.String
CAS_STATELESS_IDENTIFIER
リモーティングプロトコルクライアントなどのステートレスユーザーエージェントの CAS リクエストを識別するために使用されます(例:クラス org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter から継承されたフィールド
authenticationDetailsSource, eventPublisher, messages
コンストラクターのサマリー
コンストラクター コンストラクター 説明 CasAuthenticationFilter()
メソッドのサマリー
すべてのメソッド インスタンスメソッド 具象メソッド 修飾子と型 メソッド 説明 Authentication
attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
実際の認証を実行します。protected java.lang.String
obtainArtifact(javax.servlet.http.HttpServletRequest request)
存在する場合は、HttpServletRequest
からアーティファクト(CAS チケット)を取得します。protected boolean
requiresAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
プロキシ機能を提供するためにオーバーライドされます。void
setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler)
AuthenticationFailureHandler
をラップして、プロキシチケット認証の失敗とサービスチケットの失敗の処理を区別します。void
setProxyAuthenticationFailureHandler(AuthenticationFailureHandler proxyFailureHandler)
プロキシリクエストのAuthenticationFailureHandler
を設定します。void
setProxyGrantingTicketStorage(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage proxyGrantingTicketStorage)
void
setProxyReceptorUrl(java.lang.String proxyReceptorUrl)
void
setServiceProperties(ServiceProperties serviceProperties)
protected void
successfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.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
フィールドの詳細
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
がない場合、すべてのリクエストで新しい認証が試行されるため、より積極的なキャッシュ戦略が使用されます。- 関連事項:
- 定数フィールド値
メソッドの詳細
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
認証成功のデフォルトの動作。SecurityContextHolder
で成功した Authentication オブジェクトを設定します- ログインの成功を構成済みの RememberMeServices に通知します
- 構成された ApplicationEventPublisher を介して
InteractiveAuthenticationSuccessEvent
を起動します - 追加の動作を
AuthenticationSuccessHandler
に委譲します。
FilterChain
を続行できます。- オーバーライド:
- クラス
AbstractAuthenticationProcessingFilter
のsuccessfulAuthentication
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
実際の認証を実行します。実装では、次のいずれかを実行する必要があります。
- 認証されたユーザーの移入された認証トークンを返し、認証の成功を示します
- 認証プロセスがまだ進行中であることを示す null を返します。戻る前に、実装はプロセスを完了するために必要な追加作業を実行する必要があります。
- 認証プロセスが失敗した場合、 AuthenticationException をスローします
- 次で指定:
- クラス
AbstractAuthenticationProcessingFilter
のattemptAuthentication
- パラメーター:
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)
プロキシ機能を提供するためにオーバーライドされます。- オーバーライド:
- クラス
AbstractAuthenticationProcessingFilter
のrequiresAuthentication
- 戻り値:
- フィルターが認証を試行する必要がある場合は
true
、そうでない場合はfalse
。
setProxyAuthenticationFailureHandler
public final void setProxyAuthenticationFailureHandler(AuthenticationFailureHandler proxyFailureHandler)
プロキシリクエストのAuthenticationFailureHandler
を設定します。- パラメーター:
proxyFailureHandler
-
setAuthenticationFailureHandler
public final void setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler)
AuthenticationFailureHandler
をラップして、プロキシチケット認証の失敗とサービスチケットの失敗の処理を区別します。
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)