クラス BasicAuthenticationFilter

java.lang.ObjectSE
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.security.web.authentication.www.BasicAuthenticationFilter
実装されたすべてのインターフェース:
jakarta.servlet.Filterorg.springframework.beans.factory.Awareorg.springframework.beans.factory.BeanNameAwareorg.springframework.beans.factory.DisposableBeanorg.springframework.beans.factory.InitializingBeanorg.springframework.context.EnvironmentAwareorg.springframework.core.env.EnvironmentCapableorg.springframework.web.context.ServletContextAware

public class BasicAuthenticationFilter extends org.springframework.web.filter.OncePerRequestFilter
HTTP リクエストの BASIC 認証ヘッダーを処理し、結果を SecurityContextHolder に入れます。

このフィルターが処理するように設計されているものの詳細な背景については、RFC 1945、セクション 11.1 を参照してください。HTTP リクエストで提示されたレルム名は無視されます。

要約すると、このフィルターは、Basic の認証スキームと Base64 エンコードされた username:password トークンを使用して、Authorization の HTTP リクエストヘッダーを持つすべてのリクエストを処理します。例: ユーザー "Aladdin" をパスワード「open ゴマ」で認証するには、次のヘッダーが表示されます。


 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
 

このフィルターを使用して、リモート認証プロトコルクライアント(Hessian や SOAP など)と標準ユーザーエージェント(Internet Explorer や Netscape など)の両方に BASIC 認証サービスを提供できます。

認証が成功すると、結果の Authentication オブジェクトが SecurityContextHolder に配置されます。

認証が失敗し、ignoreFailure が false (デフォルト)の場合、AuthenticationEntryPoint 実装が呼び出されます( ignoreFailure プロパティが true に設定されている場合を除く)。通常、これは BasicAuthenticationEntryPoint である必要があります。これにより、ユーザーは BASIC 認証を介して再度認証を求められます。

基本認証は、シンプルで広く導入されているため、魅力的なプロトコルです。ただし、パスワードは平文で送信されるため、多くの状況では望ましくありません。

RememberMeServices が設定されている場合、このフィルターは、remember-me の詳細をクライアントに自動的に送信します。後続のリクエストは、remember-me メカニズムを使用して認証されるため、BASIC 認証ヘッダーを提示する必要はありません。

  • コンストラクターの詳細

    • BasicAuthenticationFilter

      public BasicAuthenticationFilter(AuthenticationManager authenticationManager)
      提供された AuthenticationManager に対して認証し、失敗した認証試行を無視するインスタンスを作成し、リクエストがフィルターチェーンを下って進むことを許可します。
      パラメーター:
      authenticationManager - 認証リクエストを送信する Bean
    • BasicAuthenticationFilter

      public BasicAuthenticationFilter(AuthenticationManager authenticationManager, AuthenticationEntryPoint authenticationEntryPoint)
      提供された AuthenticationManager に対して認証し、提供された AuthenticationEntryPoint を使用して認証の失敗を処理するインスタンスを作成します。
      パラメーター:
      authenticationManager - 認証リクエストを送信する Bean
      authenticationEntryPoint - 認証が失敗したときに呼び出されます。通常は BasicAuthenticationEntryPoint のインスタンスです。
  • メソッドの詳細

    • setSecurityContextRepository

      public void setSecurityContextRepository(SecurityContextRepository securityContextRepository)
      認証が成功したときに SecurityContext を保存するように SecurityContextRepository を設定します。デフォルトのアクションは、SecurityContext を保存しないことです。
      パラメーター:
      securityContextRepository - 使用する SecurityContextRepository。null にはできません。
    • setAuthenticationConverter

      public void setAuthenticationConverter(AuthenticationConverter authenticationConverter)
      使用する AuthenticationConverter を設定します。デフォルトは BasicAuthenticationConverter
      パラメーター:
      authenticationConverter - 使用するコンバーター
      導入:
      6.2
    • afterPropertiesSet

      public void afterPropertiesSet()
      次で指定:
      インターフェース org.springframework.beans.factory.InitializingBeanafterPropertiesSet 
      オーバーライド:
      クラス org.springframework.web.filter.GenericFilterBeanafterPropertiesSet 
    • doFilterInternal

      protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws IOExceptionSE, jakarta.servlet.ServletException
      次で指定:
      クラス org.springframework.web.filter.OncePerRequestFilterdoFilterInternal 
      例外:
      IOExceptionSE
      jakarta.servlet.ServletException
    • authenticationIsRequired

      protected boolean authenticationIsRequired(StringSE username)
    • onSuccessfulAuthentication

      protected void onSuccessfulAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, Authentication authResult) throws IOExceptionSE
      例外:
      IOExceptionSE
    • onUnsuccessfulAuthentication

      protected void onUnsuccessfulAuthentication(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, AuthenticationException failed) throws IOExceptionSE
      例外:
      IOExceptionSE
    • getAuthenticationEntryPoint

      protected AuthenticationEntryPoint getAuthenticationEntryPoint()
    • getAuthenticationManager

      protected AuthenticationManager getAuthenticationManager()
    • isIgnoreFailure

      protected boolean isIgnoreFailure()
    • setSecurityContextHolderStrategy

      public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
      使用する SecurityContextHolderStrategy を設定します。デフォルトのアクションは、SecurityContextHolder に格納されている SecurityContextHolderStrategy を使用することです。
      導入:
      5.8
    • setAuthenticationDetailsSource

      public void setAuthenticationDetailsSource(AuthenticationDetailsSource<jakarta.servlet.http.HttpServletRequest,?> authenticationDetailsSource)
      使用する AuthenticationDetailsSource を設定します。デフォルトでは、WebAuthenticationDetailsSource を使用するように設定されています。この構成は、authenticationConverter が BasicAuthenticationConverter に設定されている場合にのみ適用されることに注意してください。別の実装を利用している場合は、その実装で認証の詳細を手動で指定する必要があります。
      パラメーター:
      authenticationDetailsSource - 使用する AuthenticationDetailsSource
    • setRememberMeServices

      public void setRememberMeServices(RememberMeServices rememberMeServices)
    • setCredentialsCharset

      public void setCredentialsCharset(StringSE credentialsCharset)
      資格情報を StringSE にデコードするときに使用する文字セットを設定します。デフォルトでは、UTF-8 に設定されています。この構成は、authenticationConverter が BasicAuthenticationConverter に設定されている場合にのみ適用されることに注意してください。別の実装を利用している場合は、その実装の文字セットを手動で指定する必要があります。
      パラメーター:
      credentialsCharset - 使用する文字セット。
    • getCredentialsCharset

      protected StringSE getCredentialsCharset(jakarta.servlet.http.HttpServletRequest httpRequest)