クラス AbstractPreAuthenticatedProcessingFilter

java.lang.ObjectSE
org.springframework.web.filter.GenericFilterBean
org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter
実装されたすべてのインターフェース:
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.core.env.EnvironmentCapableorg.springframework.web.context.ServletContextAware
既知の直属サブクラス
J2eePreAuthenticatedProcessingFilterRequestAttributeAuthenticationFilterRequestHeaderAuthenticationFilterWebSpherePreAuthenticatedProcessingFilterX509AuthenticationFilter

public abstract class AbstractPreAuthenticatedProcessingFilter extends org.springframework.web.filter.GenericFilterBean implements org.springframework.context.ApplicationEventPublisherAware
事前認証された認証リクエストを処理するフィルターを処理するための基本クラス。この場合、プリンシパルはすでに外部システムによって認証されていると想定されます。

その目的は、認証するのではなく、受信リクエストからプリンシパルに関する必要な情報を抽出することだけです。外部認証システムは、事前認証システムが抽出できるヘッダーやクッキーなどのリクエストデータを介してこの情報を提供する場合があります。外部システムは、データの正確性と偽造された値の送信を防ぐことに責任があると想定されています。サブクラスは getPreAuthenticatedPrincipal() および getPreAuthenticatedCredentials() メソッドを実装する必要があります。このフィルターのサブクラスは通常、PreAuthenticatedAuthenticationProvider と組み合わせて使用されます。PreAuthenticatedAuthenticationProvider は、ユーザーの追加データをロードするために使用されます。このプロバイダーは null 資格情報を拒否するため、getPreAuthenticatedCredentials(jakarta.servlet.http.HttpServletRequest) メソッドは有効なプリンシパルに対して null を返すべきではありません。

セキュリティコンテキストにすでに Authentication オブジェクトが含まれている場合(フィルターの呼び出しから、または他の認証メカニズムのため)、フィルターはデフォルトでは何もしません。checkForPrincipalChanges プロパティを設定することにより、プリンシパルの変更を強制的にチェックできます。

デフォルトでは、認証試行が失敗した場合、他の認証メカニズムがリクエストを処理できるようにするために、フィルターチェーンが続行します。資格情報をすぐに拒否するには、 continueFilterChainOnUnsuccessfulAuthentication フラグを false に設定します。 AuthenticationManager によって発生した例外は再スローされます。これは、チェーンが通常どおり続行する場合、getPreAuthenticatedPrincipal(jakarta.servlet.http.HttpServletRequest) によって返されるプリンシパルが null の場合には影響しないことに注意してください。

導入:
2.0
  • コンストラクターの詳細

    • AbstractPreAuthenticatedProcessingFilter

      public AbstractPreAuthenticatedProcessingFilter()
  • メソッドの詳細

    • afterPropertiesSet

      public void afterPropertiesSet()
      すべての必須プロパティが設定されているかどうかを確認します。
      次で指定:
      インターフェース org.springframework.beans.factory.InitializingBeanafterPropertiesSet 
      オーバーライド:
      クラス org.springframework.web.filter.GenericFilterBeanafterPropertiesSet 
    • 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.FilterdoFilter 
      例外:
      IOExceptionSE
      jakarta.servlet.ServletException
    • principalChanged

      protected boolean principalChanged(jakarta.servlet.http.HttpServletRequest request, Authentication currentAuthentication)
      現在のプリンシパルが変更されたかどうかを判断します。デフォルトの実装は

      サブクラスはこのメソッドをオーバーライドして、プリンシパルがいつ変更されたかを判断できます。

      パラメーター:
      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.ApplicationEventPublisherAwaresetApplicationEventPublisher 
      パラメーター:
      anApplicationEventPublisher - 使用する ApplicationEventPublisher
    • setSecurityContextRepository

      public void setSecurityContextRepository(SecurityContextRepository securityContextRepository)
      認証が成功したときに 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

      public void setAuthenticationManager(AuthenticationManager authenticationManager)
      パラメーター:
      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 を返すべきではありませんが、実装によってはダミー値を返す場合があります。