クラス AbstractAuthenticationProcessingFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
- 実装されたすべてのインターフェース:
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
- 既知の直属サブクラス
CasAuthenticationFilter
、OAuth2LoginAuthenticationFilter
、OpenIDAuthenticationFilter
、Saml2WebSsoAuthenticationFilter
、UsernamePasswordAuthenticationFilter
public abstract class AbstractAuthenticationProcessingFilter extends org.springframework.web.filter.GenericFilterBean implements org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.MessageSourceAware
ブラウザーベースの HTTP ベースの認証リクエストの抽象プロセッサー。認証プロセス
フィルターでは、authenticationManager プロパティを設定する必要があります。実装クラスによって作成された認証リクエストトークンを処理するには、AuthenticationManager が必要です。このフィルターは、リクエストをインターセプトし、リクエストが
setRequiresAuthenticationRequestMatcher(RequestMatcher)
と一致する場合、そのリクエストから認証を実行しようとします。認証は、
attemptAuthentication
メソッドによって実行されます。これは、サブクラスによって実装する必要があります。Authentication Success
認証が成功した場合、結果のAuthentication
オブジェクトは現在のスレッドのSecurityContext
に配置されます。これは、以前のフィルターによってすでに作成されていることが保証されています。その後、構成された
AuthenticationSuccessHandler
が呼び出され、ログインが成功した後、適切な宛先にリダイレクトされます。デフォルトの動作はSavedRequestAwareAuthenticationSuccessHandler
に実装されており、 ExceptionTranslationFilter によって設定されたすべての DefaultSavedRequest を利用し、そこに含まれる URL にユーザーをリダイレクトします。それ以外の場合は、webapp ルート "/" にリダイレクトされます。この動作をカスタマイズするには、このクラスの異なる構成のインスタンスを挿入するか、別の実装を使用します。詳細については、
successfulAuthentication(HttpServletRequest, HttpServletResponse, FilterChain, Authentication)
メソッドを参照してください。Authentication Failure
認証が失敗した場合、構成されたAuthenticationFailureHandler
に委譲して、失敗情報をクライアントに伝達できるようにします。デフォルトの実装はSimpleUrlAuthenticationFailureHandler
で、クライアントに 401 エラーコードを送信します。代替として、失敗 URL で構成することもできます。ここでも、必要な動作をここに挿入できます。Event Publication
認証が成功すると、InteractiveAuthenticationSuccessEvent
がアプリケーションコンテキストを介して公開されます。認証が失敗した場合、イベントは公開されません。これは通常、AuthenticationManager
-specific アプリケーションイベントを介して記録されるためです。Session Authentication
クラスにはオプションのSessionAuthenticationStrategy
があり、attemptAuthentication()
の呼び出しが成功した直後に呼び出されます。異なる実装can be injected
は、セッション固定攻撃の防止などを可能にするか、プリンシパルが同時に実行できるセッションの数を制御します。
フィールドサマリー
フィールド 修飾子と型 フィールド 説明 protected AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,?>
authenticationDetailsSource
protected org.springframework.context.ApplicationEventPublisher
eventPublisher
protected org.springframework.context.support.MessageSourceAccessor
messages
コンストラクターのサマリー
コンストラクター 修飾子 コンストラクター 説明 protected
AbstractAuthenticationProcessingFilter(java.lang.String defaultFilterProcessesUrl)
protected
AbstractAuthenticationProcessingFilter(java.lang.String defaultFilterProcessesUrl, AuthenticationManager authenticationManager)
デフォルトの filterProcessesUrl とAuthenticationManager
を持つ新しいインスタンスを作成しますprotected
AbstractAuthenticationProcessingFilter(RequestMatcher requiresAuthenticationRequestMatcher)
新しいインスタンスを作成しますprotected
AbstractAuthenticationProcessingFilter(RequestMatcher requiresAuthenticationRequestMatcher, AuthenticationManager authenticationManager)
RequestMatcher
とAuthenticationManager
で新しいインスタンスを作成します
メソッドのサマリー
すべてのメソッド インスタンスメソッド 抽象メソッド 具象メソッド 修飾子と型 メソッド 説明 void
afterPropertiesSet()
abstract Authentication
attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
実際の認証を実行します。void
doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
requiresAuthentication
メソッドを呼び出して、リクエストが認証用であり、このフィルターで処理する必要があるかどうかを判別します。protected boolean
getAllowSessionCreation()
protected AuthenticationManager
getAuthenticationManager()
protected AuthenticationFailureHandler
getFailureHandler()
RememberMeServices
getRememberMeServices()
protected AuthenticationSuccessHandler
getSuccessHandler()
protected boolean
requiresAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
このフィルターが現在の呼び出しのログインリクエストを処理しようとするかどうかを示します。void
setAllowSessionCreation(boolean allowSessionCreation)
void
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)
void
setAuthenticationDetailsSource(AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,?> authenticationDetailsSource)
void
setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler)
void
setAuthenticationManager(AuthenticationManager authenticationManager)
void
setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler)
成功した認証を処理するために使用される戦略を設定します。void
setContinueChainBeforeSuccessfulAuthentication(boolean continueChainBeforeSuccessfulAuthentication)
フィルターチェーンをsuccessfulAuthentication(HttpServletRequest, HttpServletResponse, FilterChain, Authentication)
に委譲する前に継続する必要があるかどうかを示します。これは、特定の環境(Tapestry アプリケーションなど)で役立つ場合があります。void
setFilterProcessesUrl(java.lang.String filterProcessesUrl)
認証が必要かどうかを決定する URL を設定しますvoid
setMessageSource(org.springframework.context.MessageSource messageSource)
void
setRememberMeServices(RememberMeServices rememberMeServices)
void
setRequiresAuthenticationRequestMatcher(RequestMatcher requestMatcher)
void
setSecurityContextRepository(SecurityContextRepository securityContextRepository)
認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。void
setSessionAuthenticationStrategy(SessionAuthenticationStrategy sessionStrategy)
認証リクエストが AuthenticationManager によって正常に処理された直後に呼び出されるセッション処理戦略。protected void
successfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, Authentication authResult)
認証成功のデフォルトの動作。protected void
unsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException failed)
失敗した認証のデフォルトの動作。
フィールドの詳細
eventPublisher
protected org.springframework.context.ApplicationEventPublisher eventPublisher
authenticationDetailsSource
protected AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,?> authenticationDetailsSource
messages
protected org.springframework.context.support.MessageSourceAccessor messages
コンストラクターの詳細
AbstractAuthenticationProcessingFilter
protected AbstractAuthenticationProcessingFilter(java.lang.String defaultFilterProcessesUrl)
- パラメーター:
defaultFilterProcessesUrl
- filterProcessesUrl のデフォルト値。
AbstractAuthenticationProcessingFilter
protected AbstractAuthenticationProcessingFilter(RequestMatcher requiresAuthenticationRequestMatcher)
新しいインスタンスを作成します- パラメーター:
requiresAuthenticationRequestMatcher
- 認証が必要かどうかを判断するために使用されるRequestMatcher
null にすることはできません。
AbstractAuthenticationProcessingFilter
protected AbstractAuthenticationProcessingFilter(java.lang.String defaultFilterProcessesUrl, AuthenticationManager authenticationManager)
デフォルトの filterProcessesUrl とAuthenticationManager
を持つ新しいインスタンスを作成します- パラメーター:
defaultFilterProcessesUrl
- filterProcessesUrl のデフォルト値。authenticationManager
-Authentication
オブジェクトの認証に使用されるAuthenticationManager
null にすることはできません。
AbstractAuthenticationProcessingFilter
protected AbstractAuthenticationProcessingFilter(RequestMatcher requiresAuthenticationRequestMatcher, AuthenticationManager authenticationManager)
RequestMatcher
とAuthenticationManager
で新しいインスタンスを作成します- パラメーター:
requiresAuthenticationRequestMatcher
- 認証が必要かどうかを判断するために使用されるRequestMatcher
null にすることはできません。authenticationManager
-Authentication
オブジェクトの認証に使用されるAuthenticationManager
null にすることはできません。
メソッドの詳細
afterPropertiesSet
public void afterPropertiesSet()
- 次で指定:
- インターフェース
org.springframework.beans.factory.InitializingBean
のafterPropertiesSet
- オーバーライド:
- クラス
org.springframework.web.filter.GenericFilterBean
のafterPropertiesSet
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
requiresAuthentication
メソッドを呼び出して、リクエストが認証用であり、このフィルターで処理する必要があるかどうかを判別します。認証リクエストの場合は、attemptAuthentication
が呼び出されて認証が実行されます。次に、3 つの結果が考えられます。- Authentication オブジェクトが返されます。構成された
SessionAuthenticationStrategy
が呼び出され(セッション固定攻撃から保護するために新しいセッションを作成するなど、セッション関連の動作を処理するため)、続いてsuccessfulAuthentication(HttpServletRequest, HttpServletResponse, FilterChain, Authentication)
メソッドが呼び出されます。 - 認証中に AuthenticationException が発生します。
unsuccessfulAuthentication
メソッドが呼び出されます - Null が返され、認証プロセスが不完全であることを示します。その後、サブクラスが認証プロセスを続行するために必要な作業(リダイレクトなど)を実行したと仮定すると、メソッドはすぐに戻ります。このメソッドは、返された Authentication オブジェクトが null でない場合、以降のリクエストを受信することを前提としています。
- 次で指定:
- インターフェース
javax.servlet.Filter
のdoFilter
- 例外:
java.io.IOException
javax.servlet.ServletException
- Authentication オブジェクトが返されます。構成された
requiresAuthentication
protected boolean requiresAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
このフィルターが現在の呼び出しのログインリクエストを処理しようとするかどうかを示します。filterProcessesUrl
プロパティと照合する前に、リクエスト URL の「パス」セクションからパラメーター(https://host/myapp/index.html;jsessionid=blah の jsessionid パラメーターなど)を取り除きます。サブクラスは、Tapestry 統合などの特別な要件のためにオーバーライドできます。
- 戻り値:
- フィルターが認証を試行する必要がある場合は
true
、そうでない場合はfalse
。
attemptAuthentication
public abstract Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws AuthenticationException, java.io.IOException, javax.servlet.ServletException
実際の認証を実行します。実装では、次のいずれかを実行する必要があります。
- 認証されたユーザーの移入された認証トークンを返し、認証の成功を示します
- 認証プロセスがまだ進行中であることを示す null を返します。戻る前に、実装はプロセスを完了するために必要な追加作業を実行する必要があります。
- 認証プロセスが失敗した場合、 AuthenticationException をスローします
- パラメーター:
request
- パラメーターの抽出元および認証の実行元response
- レスポンス。実装がマルチステージ認証プロセス(OpenID など)の一部としてリダイレクトを行う必要がある場合に必要になる場合があります。- 戻り値:
- 認証されたユーザートークン。認証が不完全な場合は null
- 例外:
AuthenticationException
- 認証が失敗した場合。java.io.IOException
javax.servlet.ServletException
successfulAuthentication
protected 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
認証成功のデフォルトの動作。SecurityContextHolder
で成功した Authentication オブジェクトを設定します- ログインの成功を構成済みの RememberMeServices に通知します
- 構成された ApplicationEventPublisher を介して
InteractiveAuthenticationSuccessEvent
を起動します - 追加の動作を
AuthenticationSuccessHandler
に委譲します。
FilterChain
を続行できます。- パラメーター:
request
-response
-chain
-authResult
- attemptAuthentication メソッドから返されるオブジェクト。- 例外:
java.io.IOException
javax.servlet.ServletException
unsuccessfulAuthentication
protected void unsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException failed) throws java.io.IOException, javax.servlet.ServletException
失敗した認証のデフォルトの動作。SecurityContextHolder
をクリアします- セッションに例外を格納します (存在するか、allowSesssionCreation が true に設定されている場合)
- ログインの失敗を構成済みの RememberMeServices に通知します
- 追加の動作を
AuthenticationFailureHandler
に委譲します。
- 例外:
java.io.IOException
javax.servlet.ServletException
getAuthenticationManager
protected AuthenticationManager getAuthenticationManager()
setAuthenticationManager
public void setAuthenticationManager(AuthenticationManager authenticationManager)
setFilterProcessesUrl
public void setFilterProcessesUrl(java.lang.String filterProcessesUrl)
認証が必要かどうかを決定する URL を設定します- パラメーター:
filterProcessesUrl
-
setRequiresAuthenticationRequestMatcher
public final void setRequiresAuthenticationRequestMatcher(RequestMatcher requestMatcher)
getRememberMeServices
public RememberMeServices getRememberMeServices()
setRememberMeServices
public void setRememberMeServices(RememberMeServices rememberMeServices)
setContinueChainBeforeSuccessfulAuthentication
public void setContinueChainBeforeSuccessfulAuthentication(boolean continueChainBeforeSuccessfulAuthentication)
フィルターチェーンをsuccessfulAuthentication(HttpServletRequest, HttpServletResponse, FilterChain, Authentication)
に委譲する前に継続する必要があるかどうかを示します。これは、特定の環境(Tapestry アプリケーションなど)で役立つ場合があります。デフォルトはfalse
です。
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)
- 次で指定:
- インターフェース
org.springframework.context.ApplicationEventPublisherAware
のsetApplicationEventPublisher
setAuthenticationDetailsSource
public void setAuthenticationDetailsSource(AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,?> authenticationDetailsSource)
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource)
- 次で指定:
- インターフェース
org.springframework.context.MessageSourceAware
のsetMessageSource
getAllowSessionCreation
protected boolean getAllowSessionCreation()
setAllowSessionCreation
public void setAllowSessionCreation(boolean allowSessionCreation)
setSessionAuthenticationStrategy
public void setSessionAuthenticationStrategy(SessionAuthenticationStrategy sessionStrategy)
認証リクエストが AuthenticationManager によって正常に処理された直後に呼び出されるセッション処理戦略。たとえば、セッション固定攻撃を防ぐためにセッション識別子の変更を処理するために使用されます。- パラメーター:
sessionStrategy
- 使用する実装。設定しない場合、null 実装が使用されます。
setAuthenticationSuccessHandler
public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler)
成功した認証を処理するために使用される戦略を設定します。デフォルトでは、SavedRequestAwareAuthenticationSuccessHandler
が使用されます。
setAuthenticationFailureHandler
public void setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler)
setSecurityContextRepository
public void setSecurityContextRepository(SecurityContextRepository securityContextRepository)
認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。デフォルトのアクションは、SecurityContext
を保存しないことです。- パラメーター:
securityContextRepository
- 使用するSecurityContextRepository
。null にはできません。
getSuccessHandler
protected AuthenticationSuccessHandler getSuccessHandler()
getFailureHandler
protected AuthenticationFailureHandler getFailureHandler()