クラス AbstractPreAuthenticatedProcessingFilter
- 実装されたすべてのインターフェース:
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.core.env.EnvironmentCapable
、org.springframework.web.context.ServletContextAware
- 既知の直属サブクラス
J2eePreAuthenticatedProcessingFilter
、RequestAttributeAuthenticationFilter
、RequestHeaderAuthenticationFilter
、WebSpherePreAuthenticatedProcessingFilter
、X509AuthenticationFilter
その目的は、認証するのではなく、受信リクエストからプリンシパルに関する必要な情報を抽出することだけです。外部認証システムは、事前認証システムが抽出できるヘッダーやクッキーなどのリクエストデータを介してこの情報を提供する場合があります。外部システムは、データの正確性と偽造された値の送信を防ぐことに責任があると想定されています。サブクラスは getPreAuthenticatedPrincipal()
および getPreAuthenticatedCredentials()
メソッドを実装する必要があります。このフィルターのサブクラスは通常、PreAuthenticatedAuthenticationProvider
と組み合わせて使用されます。PreAuthenticatedAuthenticationProvider
は、ユーザーの追加データをロードするために使用されます。このプロバイダーは null 資格情報を拒否するため、getPreAuthenticatedCredentials(jakarta.servlet.http.HttpServletRequest)
メソッドは有効なプリンシパルに対して null を返すべきではありません。
セキュリティコンテキストにすでに Authentication
オブジェクトが含まれている場合(フィルターの呼び出しから、または他の認証メカニズムのため)、フィルターはデフォルトでは何もしません。checkForPrincipalChanges
プロパティを設定することにより、プリンシパルの変更を強制的にチェックできます。
デフォルトでは、認証試行が失敗した場合、他の認証メカニズムがリクエストを処理できるようにするために、フィルターチェーンが続行します。資格情報をすぐに拒否するには、 continueFilterChainOnUnsuccessfulAuthentication フラグを false に設定します。 AuthenticationManager によって発生した例外は再スローされます。これは、チェーンが通常どおり続行する場合、getPreAuthenticatedPrincipal(jakarta.servlet.http.HttpServletRequest)
によって返されるプリンシパルが null の場合には影響しないことに注意してください。
- 導入:
- 2.0
フィールドサマリー
クラス org.springframework.web.filter.GenericFilterBean から継承されたフィールド
logger
コンストラクターのサマリー
コンストラクターメソッドのサマリー
修飾子と型メソッド説明void
すべての必須プロパティが設定されているかどうかを確認します。void
doFilter
(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) ユーザーがまだ認証されていない場合は、Spring Security で事前認証されたユーザーを認証してください。protected AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest,
?> protected abstract ObjectSE
getPreAuthenticatedCredentials
(jakarta.servlet.http.HttpServletRequest request) オーバーライドして、現在のリクエストから資格情報(該当する場合)を抽出します。protected abstract ObjectSE
getPreAuthenticatedPrincipal
(jakarta.servlet.http.HttpServletRequest request) 現在のリクエストからプリンシパル情報を抽出するオーバーライドprotected boolean
principalChanged
(jakarta.servlet.http.HttpServletRequest request, Authentication currentAuthentication) 現在のプリンシパルが変更されたかどうかを判断します。void
setApplicationEventPublisher
(org.springframework.context.ApplicationEventPublisher anApplicationEventPublisher) void
setAuthenticationDetailsSource
(AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) void
setAuthenticationFailureHandler
(AuthenticationFailureHandler authenticationFailureHandler) 失敗した認証の処理に使用される戦略を設定します。void
setAuthenticationManager
(AuthenticationManager authenticationManager) void
setAuthenticationSuccessHandler
(AuthenticationSuccessHandler authenticationSuccessHandler) 成功した認証を処理するために使用される戦略を設定します。void
setCheckForPrincipalChanges
(boolean checkForPrincipalChanges) 設定すると、事前認証されたプリンシパルが各リクエストでチェックされ、現在の認証オブジェクトの名前と比較されます。void
setContinueFilterChainOnUnsuccessfulAuthentication
(boolean shouldContinue) true
(デフォルト)に設定されている場合、AuthenticationManager
によって発生したAuthenticationException
はすべて飲み込まれ、潜在的に代替認証メカニズムを使用して、リクエストの続行が許可されます。void
setInvalidateSessionOnPrincipalChange
(boolean invalidateSessionOnPrincipalChange) checkForPrincipalChanges が設定され、プリンシパルの変更が検出された場合、新しいプリンシパルの認証に進む前に、既存のセッションを無効にするかどうかを決定します。void
setRequiresAuthenticationRequestMatcher
(RequestMatcher requiresAuthenticationRequestMatcher) リクエストマッチャーを設定して、リクエストをさらに進めるかどうかを確認します。void
setSecurityContextHolderStrategy
(SecurityContextHolderStrategy securityContextHolderStrategy) 使用するSecurityContextHolderStrategy
を設定します。void
setSecurityContextRepository
(SecurityContextRepository securityContextRepository) 認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。protected void
successfulAuthentication
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Authentication authResult) 認証マネージャーから返されたAuthentication
インスタンスを安全なコンテキストに入れます。protected void
unsuccessfulAuthentication
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, AuthenticationException failed) 認証が失敗した場合、セキュアコンテキストの認証オブジェクトが null に設定されるようにします。クラス org.springframework.web.filter.GenericFilterBean から継承されたメソッド
addRequiredProperty, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
コンストラクターの詳細
AbstractPreAuthenticatedProcessingFilter
public AbstractPreAuthenticatedProcessingFilter()
メソッドの詳細
afterPropertiesSet
public void afterPropertiesSet()すべての必須プロパティが設定されているかどうかを確認します。- 次で指定:
- インターフェース
org.springframework.beans.factory.InitializingBean
のafterPropertiesSet
- オーバーライド:
- クラス
org.springframework.web.filter.GenericFilterBean
のafterPropertiesSet
doFilter
public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOExceptionSE, jakarta.servlet.ServletException ユーザーがまだ認証されていない場合は、Spring Security で事前認証されたユーザーを認証してください。- 次で指定:
- インターフェース
jakarta.servlet.Filter
のdoFilter
- 例外:
IOExceptionSE
jakarta.servlet.ServletException
principalChanged
protected boolean principalChanged(jakarta.servlet.http.HttpServletRequest request, Authentication currentAuthentication) 現在のプリンシパルが変更されたかどうかを判断します。デフォルトの実装はgetPreAuthenticatedPrincipal(HttpServletRequest)
が文字列の場合、Principal.getName()
は事前に認証されたプリンシパルと比較されます- それ以外の場合、
getPreAuthenticatedPrincipal(HttpServletRequest)
はAuthentication.getPrincipal()
と比較されます
サブクラスはこのメソッドをオーバーライドして、プリンシパルがいつ変更されたかを判断できます。
- パラメーター:
request
-currentAuthentication
-- 戻り値:
- プリンシパルが変更された場合は true、そうでない場合は false
successfulAuthentication
protected void successfulAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Authentication authResult) throws IOExceptionSE, jakarta.servlet.ServletException 認証マネージャーから返されたAuthentication
インスタンスを安全なコンテキストに入れます。- 例外:
IOExceptionSE
jakarta.servlet.ServletException
unsuccessfulAuthentication
protected void unsuccessfulAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, AuthenticationException failed) throws IOExceptionSE, jakarta.servlet.ServletException 認証が失敗した場合、セキュアコンテキストの認証オブジェクトが null に設定されるようにします。失敗の例外をリクエスト属性としてキャッシュします
- 例外:
IOExceptionSE
jakarta.servlet.ServletException
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher anApplicationEventPublisher) - 次で指定:
- インターフェース
org.springframework.context.ApplicationEventPublisherAware
のsetApplicationEventPublisher
- パラメーター:
anApplicationEventPublisher
- 使用する ApplicationEventPublisher
setSecurityContextRepository
認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。デフォルトのアクションは、SecurityContext
を保存しないことです。- パラメーター:
securityContextRepository
- 使用するSecurityContextRepository
。null にはできません。
setAuthenticationDetailsSource
public void setAuthenticationDetailsSource(AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest, ?> authenticationDetailsSource) - パラメーター:
authenticationDetailsSource
- 使用する AuthenticationDetailsSource
getAuthenticationDetailsSource
protected AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest,?> getAuthenticationDetailsSource()setAuthenticationManager
- パラメーター:
authenticationManager
- 使用する AuthenticationManager
setContinueFilterChainOnUnsuccessfulAuthentication
public void setContinueFilterChainOnUnsuccessfulAuthentication(boolean shouldContinue) true
(デフォルト)に設定されている場合、AuthenticationManager
によって発生したAuthenticationException
はすべて飲み込まれ、潜在的に代替認証メカニズムを使用して、リクエストの続行が許可されます。false
の場合、認証に失敗するとすぐに例外が発生します。- パラメーター:
shouldContinue
-true
に設定すると、認証が失敗した後にリクエストを続行できます。
setCheckForPrincipalChanges
public void setCheckForPrincipalChanges(boolean checkForPrincipalChanges) 設定すると、事前認証されたプリンシパルが各リクエストでチェックされ、現在の認証オブジェクトの名前と比較されます。Authentication.getPrincipal()
がプリンシパルに等しいかどうかを確認するチェックも実行されます。変更が検出されると、ユーザーは再認証されます。- パラメーター:
checkForPrincipalChanges
-
setInvalidateSessionOnPrincipalChange
public void setInvalidateSessionOnPrincipalChange(boolean invalidateSessionOnPrincipalChange) checkForPrincipalChanges が設定され、プリンシパルの変更が検出された場合、新しいプリンシパルの認証に進む前に、既存のセッションを無効にするかどうかを決定します。- パラメーター:
invalidateSessionOnPrincipalChange
- false は、既存のセッションを保持します。デフォルトは true です。
setAuthenticationSuccessHandler
public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler authenticationSuccessHandler) 成功した認証を処理するために使用される戦略を設定します。setAuthenticationFailureHandler
public void setAuthenticationFailureHandler(AuthenticationFailureHandler authenticationFailureHandler) 失敗した認証の処理に使用される戦略を設定します。setRequiresAuthenticationRequestMatcher
public void setRequiresAuthenticationRequestMatcher(RequestMatcher requiresAuthenticationRequestMatcher) リクエストマッチャーを設定して、リクエストをさらに進めるかどうかを確認します。setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) 使用するSecurityContextHolderStrategy
を設定します。デフォルトのアクションは、SecurityContextHolder
に格納されているSecurityContextHolderStrategy
を使用することです。- 導入:
- 5.8
getPreAuthenticatedPrincipal
protected abstract ObjectSE getPreAuthenticatedPrincipal(jakarta.servlet.http.HttpServletRequest request) 現在のリクエストからプリンシパル情報を抽出するオーバーライドgetPreAuthenticatedCredentials
protected abstract ObjectSE getPreAuthenticatedCredentials(jakarta.servlet.http.HttpServletRequest request) オーバーライドして、現在のリクエストから資格情報(該当する場合)を抽出します。有効なプリンシパルに対して null を返すべきではありませんが、実装によってはダミー値を返す場合があります。