Class RequestSecurityFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.craftercms.security.servlet.filters.RequestSecurityFilter
- All Implemented Interfaces:
javax.servlet.Filter,SecurityEnabledAware,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 RequestSecurityFilter
extends org.springframework.web.filter.GenericFilterBean
implements SecurityEnabledAware
Filter for running security. Uses a list of
RequestSecurityProcessor. The last processor should basically
call the filter chain.- Author:
- Alfonso Vásquez
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.util.PathMatcherprotected booleanprotected List<RequestSecurityProcessor>protected String[]protected String[]Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.craftercms.commons.http.RequestContextcreateRequestContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Returns a newRequestContext, using the specifiedHttpServletRequestandHttpServletResponse.voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) IfsecurityEnabled, passes the request through the chain ofRequestSecurityProcessors, depending if the request URL matches or not theurlsToIncludeor theurlsToExclude.protected voiddoFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain) Passes the request through the chain ofRequestSecurityProcessors.protected booleanexcludeRequest(javax.servlet.http.HttpServletRequest request) Returns trues if the request should be excluded from processing.protected RequestSecurityProcessorgetLastProcessorInChain(javax.servlet.FilterChain chain) Returns the last processor of the chain, which should actually call theFilterChain.protected booleanincludeRequest(javax.servlet.http.HttpServletRequest request) Returns trues if the request should be included for processing.voidsetSecurityEnabled(boolean securityEnabled) Sets if security is enabled or disabled.voidsetSecurityProcessors(List<RequestSecurityProcessor> securityProcessors) Sets the chain ofRequestSecurityProcessor.voidsetUrlsToExclude(String... urlsToExclude) Sets the regular expressions used to match the URLs of requests that should NOT be processed by the security chain.voidsetUrlsToInclude(String... urlsToInclude) Sets the regular expressions used to match the URLs of requests that should be processed by the security chain.Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Field Details
-
securityEnabled
protected boolean securityEnabled -
securityProcessors
-
urlsToInclude
-
urlsToExclude
-
pathMatcher
protected org.springframework.util.PathMatcher pathMatcher
-
-
Constructor Details
-
RequestSecurityFilter
public RequestSecurityFilter()
-
-
Method Details
-
setSecurityEnabled
public void setSecurityEnabled(boolean securityEnabled) Sets if security is enabled or disabled. If disabled, the security processor chain is not run.- Specified by:
setSecurityEnabledin interfaceSecurityEnabledAware
-
setSecurityProcessors
Sets the chain ofRequestSecurityProcessor. -
setUrlsToInclude
Sets the regular expressions used to match the URLs of requests that should be processed by the security chain. -
setUrlsToExclude
Sets the regular expressions used to match the URLs of requests that should NOT be processed by the security chain. -
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException IfsecurityEnabled, passes the request through the chain ofRequestSecurityProcessors, depending if the request URL matches or not theurlsToIncludeor theurlsToExclude. The last processor of the chain calls the actual filter chain.- Specified by:
doFilterin interfacejavax.servlet.Filter- Parameters:
request-response-chain-- Throws:
IOExceptionjavax.servlet.ServletException
-
doFilterInternal
protected void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException Passes the request through the chain ofRequestSecurityProcessors.- Parameters:
request-response-chain-- Throws:
IOExceptionjavax.servlet.ServletException
-
excludeRequest
protected boolean excludeRequest(javax.servlet.http.HttpServletRequest request) Returns trues if the request should be excluded from processing. -
includeRequest
protected boolean includeRequest(javax.servlet.http.HttpServletRequest request) Returns trues if the request should be included for processing. -
createRequestContext
protected org.craftercms.commons.http.RequestContext createRequestContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Returns a newRequestContext, using the specifiedHttpServletRequestandHttpServletResponse. -
getLastProcessorInChain
Returns the last processor of the chain, which should actually call theFilterChain.
-