Class ExceptionTranslationFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.security.web.access.ExceptionTranslationFilter
-
- All Implemented Interfaces:
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.context.MessageSourceAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class ExceptionTranslationFilter extends org.springframework.web.filter.GenericFilterBean implements org.springframework.context.MessageSourceAwareHandles anyAccessDeniedExceptionandAuthenticationExceptionthrown within the filter chain.This filter is necessary because it provides the bridge between Java exceptions and HTTP responses. It is solely concerned with maintaining the user interface. This filter does not do any actual security enforcement.
If an
AuthenticationExceptionis detected, the filter will launch theauthenticationEntryPoint. This allows common handling of authentication failures originating from any subclass ofAbstractSecurityInterceptor.If an
AccessDeniedExceptionis detected, the filter will determine whether or not the user is an anonymous user. If they are an anonymous user, theauthenticationEntryPointwill be launched. If they are not an anonymous user, the filter will delegate to theAccessDeniedHandler. By default the filter will useAccessDeniedHandlerImpl.To use this filter, it is necessary to specify the following properties:
authenticationEntryPointindicates the handler that should commence the authentication process if anAuthenticationExceptionis detected. Note that this may also switch the current protocol from http to https for an SSL login.- requestCache determines the strategy used to save a request during the
authentication process in order that it may be retrieved and reused once the user has
authenticated. The default implementation is
HttpSessionRequestCache.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.context.support.MessageSourceAccessormessages
-
Constructor Summary
Constructors Constructor Description ExceptionTranslationFilter(AuthenticationEntryPoint authenticationEntryPoint)ExceptionTranslationFilter(AuthenticationEntryPoint authenticationEntryPoint, RequestCache requestCache)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)AuthenticationEntryPointgetAuthenticationEntryPoint()protected org.springframework.security.authentication.AuthenticationTrustResolvergetAuthenticationTrustResolver()protected voidsendStartAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, org.springframework.security.core.AuthenticationException reason)voidsetAccessDeniedHandler(AccessDeniedHandler accessDeniedHandler)voidsetAuthenticationTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver authenticationTrustResolver)voidsetMessageSource(org.springframework.context.MessageSource messageSource)voidsetThrowableAnalyzer(ThrowableAnalyzer throwableAnalyzer)
-
-
-
Constructor Detail
-
ExceptionTranslationFilter
public ExceptionTranslationFilter(AuthenticationEntryPoint authenticationEntryPoint)
-
ExceptionTranslationFilter
public ExceptionTranslationFilter(AuthenticationEntryPoint authenticationEntryPoint, RequestCache requestCache)
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.web.filter.GenericFilterBean
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
getAuthenticationEntryPoint
public AuthenticationEntryPoint getAuthenticationEntryPoint()
-
getAuthenticationTrustResolver
protected org.springframework.security.authentication.AuthenticationTrustResolver getAuthenticationTrustResolver()
-
sendStartAuthentication
protected void sendStartAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, org.springframework.security.core.AuthenticationException reason) throws javax.servlet.ServletException, java.io.IOException- Throws:
javax.servlet.ServletExceptionjava.io.IOException
-
setAccessDeniedHandler
public void setAccessDeniedHandler(AccessDeniedHandler accessDeniedHandler)
-
setAuthenticationTrustResolver
public void setAuthenticationTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver authenticationTrustResolver)
-
setThrowableAnalyzer
public void setThrowableAnalyzer(ThrowableAnalyzer throwableAnalyzer)
-
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource)
- Specified by:
setMessageSourcein interfaceorg.springframework.context.MessageSourceAware- Since:
- 5.5
-
-