クラス BasicAuthenticationFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.web.filter.OncePerRequestFilter
-
- org.springframework.security.web.authentication.www.BasicAuthenticationFilter
- 実装されたすべてのインターフェース:
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.EnvironmentAware
、org.springframework.core.env.EnvironmentCapable
、org.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 認証を介して再度認証するように求められます。基本認証はシンプルで広くデプロイされているため、魅力的なプロトコルです。ただし、パスワードはクリアテキストで送信されるため、多くの状況では望ましくありません。ダイジェスト認証も Spring Security によって提供され、可能な限り基本認証の代わりに使用する必要があります。
DigestAuthenticationFilter
を参照してください。RememberMeServices
が設定されている場合、このフィルターは、remember-me の詳細をクライアントに自動的に送信します。後続のリクエストは、remember-me メカニズムを使用して認証されるため、BASIC 認証ヘッダーを提示する必要はありません。
コンストラクターのサマリー
コンストラクター コンストラクター 説明 BasicAuthenticationFilter(AuthenticationManager authenticationManager)
提供されたAuthenticationManager
に対して認証し、失敗した認証試行を無視するインスタンスを作成し、リクエストがフィルターチェーンを下って進むことを許可します。BasicAuthenticationFilter(AuthenticationManager authenticationManager, AuthenticationEntryPoint authenticationEntryPoint)
提供されたAuthenticationManager
に対して認証し、提供されたAuthenticationEntryPoint
を使用して認証の失敗を処理するインスタンスを作成します。
メソッドのサマリー
すべてのメソッド インスタンスメソッド 具象メソッド 修飾子と型 メソッド 説明 void
afterPropertiesSet()
protected void
doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
protected AuthenticationEntryPoint
getAuthenticationEntryPoint()
protected AuthenticationManager
getAuthenticationManager()
protected java.lang.String
getCredentialsCharset(javax.servlet.http.HttpServletRequest httpRequest)
protected boolean
isIgnoreFailure()
protected void
onSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Authentication authResult)
protected void
onUnsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException failed)
void
setAuthenticationDetailsSource(AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,?> authenticationDetailsSource)
void
setCredentialsCharset(java.lang.String credentialsCharset)
void
setRememberMeServices(RememberMeServices rememberMeServices)
void
setSecurityContextRepository(SecurityContextRepository securityContextRepository)
認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。クラス org.springframework.web.filter.OncePerRequestFilter から継承されたメソッド
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
コンストラクターの詳細
BasicAuthenticationFilter
public BasicAuthenticationFilter(AuthenticationManager authenticationManager)
提供されたAuthenticationManager
に対して認証し、失敗した認証試行を無視するインスタンスを作成し、リクエストがフィルターチェーンを下って進むことを許可します。- パラメーター:
authenticationManager
- 認証リクエストを送信する Bean
BasicAuthenticationFilter
public BasicAuthenticationFilter(AuthenticationManager authenticationManager, AuthenticationEntryPoint authenticationEntryPoint)
提供されたAuthenticationManager
に対して認証し、提供されたAuthenticationEntryPoint
を使用して認証の失敗を処理するインスタンスを作成します。- パラメーター:
authenticationManager
- 認証リクエストを送信する BeanauthenticationEntryPoint
- 認証が失敗したときに呼び出されます。通常はBasicAuthenticationEntryPoint
のインスタンスです。
メソッドの詳細
setSecurityContextRepository
public void setSecurityContextRepository(SecurityContextRepository securityContextRepository)
認証が成功したときにSecurityContext
を保存するようにSecurityContextRepository
を設定します。デフォルトのアクションは、SecurityContext
を保存しないことです。- パラメーター:
securityContextRepository
- 使用するSecurityContextRepository
。null にはできません。
afterPropertiesSet
public void afterPropertiesSet()
- 次で指定:
- インターフェース
org.springframework.beans.factory.InitializingBean
のafterPropertiesSet
- オーバーライド:
- クラス
org.springframework.web.filter.GenericFilterBean
のafterPropertiesSet
doFilterInternal
protected void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
- 次で指定:
- クラス
org.springframework.web.filter.OncePerRequestFilter
のdoFilterInternal
- 例外:
java.io.IOException
javax.servlet.ServletException
onSuccessfulAuthentication
protected void onSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Authentication authResult) throws java.io.IOException
- 例外:
java.io.IOException
onUnsuccessfulAuthentication
protected void onUnsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AuthenticationException failed) throws java.io.IOException
- 例外:
java.io.IOException
getAuthenticationEntryPoint
protected AuthenticationEntryPoint getAuthenticationEntryPoint()
getAuthenticationManager
protected AuthenticationManager getAuthenticationManager()
isIgnoreFailure
protected boolean isIgnoreFailure()
setAuthenticationDetailsSource
public void setAuthenticationDetailsSource(AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,?> authenticationDetailsSource)
setRememberMeServices
public void setRememberMeServices(RememberMeServices rememberMeServices)
setCredentialsCharset
public void setCredentialsCharset(java.lang.String credentialsCharset)
getCredentialsCharset
protected java.lang.String getCredentialsCharset(javax.servlet.http.HttpServletRequest httpRequest)