Class SecurityContextHolderAwareRequestFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter
-
- 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.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class SecurityContextHolderAwareRequestFilter extends org.springframework.web.filter.GenericFilterBeanAFilterwhich populates theServletRequestwith a request wrapper which implements the servlet API security methods.SecurityContextHolderAwareRequestWrapperis extended to provide the following additional methods:HttpServletRequest.authenticate(HttpServletResponse)- Allows the user to determine if they are authenticated and if not send the user to the login page. SeesetAuthenticationEntryPoint(AuthenticationEntryPoint).HttpServletRequest.login(String, String)- Allows the user to authenticate using theAuthenticationManager. SeesetAuthenticationManager(AuthenticationManager).HttpServletRequest.logout()- Allows the user to logout using theLogoutHandlers configured in Spring Security. SeesetLogoutHandlers(List).AsyncContext.start(Runnable)- Automatically copy theSecurityContextfrom theSecurityContextHolderfound on the Thread that invokedAsyncContext.start(Runnable)to the Thread that processes theRunnable.
-
-
Constructor Summary
Constructors Constructor Description SecurityContextHolderAwareRequestFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()voiddoFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)voidsetAuthenticationEntryPoint(AuthenticationEntryPoint authenticationEntryPoint)Sets theAuthenticationEntryPointused when integratingHttpServletRequestwith Servlet 3 APIs.voidsetAuthenticationManager(org.springframework.security.authentication.AuthenticationManager authenticationManager)Sets theAuthenticationManagerused when integratingHttpServletRequestwith Servlet 3 APIs.voidsetLogoutHandlers(java.util.List<LogoutHandler> logoutHandlers)Sets theLogoutHandlers used when integrating withHttpServletRequestwith Servlet 3 APIs.voidsetRolePrefix(java.lang.String rolePrefix)voidsetTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver trustResolver)Sets theAuthenticationTrustResolverto be used.
-
-
-
Method Detail
-
setRolePrefix
public void setRolePrefix(java.lang.String rolePrefix)
-
setAuthenticationEntryPoint
public void setAuthenticationEntryPoint(AuthenticationEntryPoint authenticationEntryPoint)
Sets the
AuthenticationEntryPointused when integratingHttpServletRequestwith Servlet 3 APIs. Specifically, it will be used whenHttpServletRequest.authenticate(HttpServletResponse)is called and the user is not authenticated.If the value is null (default), then the default container behavior will be be retained when invoking
HttpServletRequest.authenticate(HttpServletResponse).- Parameters:
authenticationEntryPoint- theAuthenticationEntryPointto use when invokingHttpServletRequest.authenticate(HttpServletResponse)if the user is not authenticated.
-
setAuthenticationManager
public void setAuthenticationManager(org.springframework.security.authentication.AuthenticationManager authenticationManager)
Sets the
AuthenticationManagerused when integratingHttpServletRequestwith Servlet 3 APIs. Specifically, it will be used whenHttpServletRequest.login(String, String)is invoked to determine if the user is authenticated.If the value is null (default), then the default container behavior will be retained when invoking
HttpServletRequest.login(String, String).- Parameters:
authenticationManager- theAuthenticationManagerto use when invokingHttpServletRequest.login(String, String)
-
setLogoutHandlers
public void setLogoutHandlers(java.util.List<LogoutHandler> logoutHandlers)
Sets the
LogoutHandlers used when integrating withHttpServletRequestwith Servlet 3 APIs. Specifically it will be used whenHttpServletRequest.logout()is invoked in order to log the user out. So long as theLogoutHandlers do not commit theHttpServletResponse(expected), then the user is in charge of handling the response.If the value is null (default), the default container behavior will be retained when invoking
HttpServletRequest.logout().- Parameters:
logoutHandlers- theList<LogoutHandler>s when invokingHttpServletRequest.logout().
-
doFilter
public void doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
afterPropertiesSet
public void afterPropertiesSet() throws javax.servlet.ServletException- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.web.filter.GenericFilterBean- Throws:
javax.servlet.ServletException
-
setTrustResolver
public void setTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver trustResolver)
Sets theAuthenticationTrustResolverto be used. The default isAuthenticationTrustResolverImpl.- Parameters:
trustResolver- theAuthenticationTrustResolverto use. Cannot be null.
-
-