Class WebSecurity
- java.lang.Object
-
- org.springframework.security.config.annotation.AbstractSecurityBuilder<O>
-
- org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder<javax.servlet.Filter,WebSecurity>
-
- org.springframework.security.config.annotation.web.builders.WebSecurity
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,SecurityBuilder<javax.servlet.Filter>,org.springframework.web.context.ServletContextAware
public final class WebSecurity extends AbstractConfiguredSecurityBuilder<javax.servlet.Filter,WebSecurity> implements SecurityBuilder<javax.servlet.Filter>, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware
The
WebSecurityis created byWebSecurityConfigurationto create theFilterChainProxyknown as the Spring Security Filter Chain (springSecurityFilterChain). The springSecurityFilterChain is theFilterthat theDelegatingFilterProxydelegates to.Customizations to the
WebSecuritycan be made by creating aWebSecurityConfigurer, overridingWebSecurityConfigurerAdapteror exposing aWebSecurityCustomizerbean.- Since:
- 3.2
- See Also:
EnableWebSecurity,WebSecurityConfiguration
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classWebSecurity.IgnoredRequestConfigurerAllows registeringRequestMatcherinstances that should be ignored by Spring Security.classWebSecurity.MvcMatchersIgnoredRequestConfigurerAnWebSecurity.IgnoredRequestConfigurerthat allows optionally configuring theMvcRequestMatcher.setMethod(HttpMethod)
-
Constructor Summary
Constructors Constructor Description WebSecurity(ObjectPostProcessor<java.lang.Object> objectPostProcessor)Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description WebSecurityaddSecurityFilterChainBuilder(SecurityBuilder<? extends org.springframework.security.web.SecurityFilterChain> securityFilterChainBuilder)Adds builders to createSecurityFilterChaininstances.WebSecuritydebug(boolean debugEnabled)Controls debugging support for Spring Security.WebSecurityexpressionHandler(org.springframework.security.access.expression.SecurityExpressionHandler<org.springframework.security.web.FilterInvocation> expressionHandler)Set theSecurityExpressionHandlerto be used.org.springframework.security.access.expression.SecurityExpressionHandler<org.springframework.security.web.FilterInvocation>getExpressionHandler()Gets theSecurityExpressionHandlerto be used.org.springframework.security.web.access.WebInvocationPrivilegeEvaluatorgetPrivilegeEvaluator()Gets theWebInvocationPrivilegeEvaluatorto be used.WebSecurityhttpFirewall(org.springframework.security.web.firewall.HttpFirewall httpFirewall)Allows customizing theHttpFirewall.WebSecurity.IgnoredRequestConfigurerignoring()Allows addingRequestMatcherinstances that Spring Security should ignore.protected javax.servlet.FilterperformBuild()Subclasses must implement this method to build the object that is being returned.WebSecuritypostBuildAction(java.lang.Runnable postBuildAction)Executes the Runnable immediately after the build takes placeWebSecurityprivilegeEvaluator(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator privilegeEvaluator)Set theWebInvocationPrivilegeEvaluatorto be used.WebSecuritysecurityInterceptor(org.springframework.security.web.access.intercept.FilterSecurityInterceptor securityInterceptor)Deprecated.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetServletContext(javax.servlet.ServletContext servletContext)-
Methods inherited from class org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder
apply, beforeConfigure, beforeInit, doBuild, getConfigurer, getConfigurers, getOrBuild, getSharedObject, getSharedObjects, objectPostProcessor, postProcess, removeConfigurer, removeConfigurers, setSharedObject
-
Methods inherited from class org.springframework.security.config.annotation.AbstractSecurityBuilder
build, getObject
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.security.config.annotation.SecurityBuilder
build
-
-
-
-
Constructor Detail
-
WebSecurity
public WebSecurity(ObjectPostProcessor<java.lang.Object> objectPostProcessor)
Creates a new instance- Parameters:
objectPostProcessor- theObjectPostProcessorto use- See Also:
WebSecurityConfiguration
-
-
Method Detail
-
ignoring
public WebSecurity.IgnoredRequestConfigurer ignoring()
Allows adding
Example Usage:RequestMatcherinstances that Spring Security should ignore. Web Security provided by Spring Security (including theSecurityContext) will not be available onHttpServletRequestthat match. Typically the requests that are registered should be that of only static resources. For requests that are dynamic, consider mapping the request to allow all users instead.webSecurityBuilder.ignoring() // ignore all URLs that start with /resources/ or /static/ .antMatchers("/resources/**", "/static/**");Alternatively this will accomplish the same result:webSecurityBuilder.ignoring() // ignore all URLs that start with /resources/ or /static/ .antMatchers("/resources/**").antMatchers("/static/**");Multiple invocations of ignoring() are also additive, so the following is also equivalent to the previous two examples:webSecurityBuilder.ignoring() // ignore all URLs that start with /resources/ .antMatchers("/resources/**"); webSecurityBuilder.ignoring() // ignore all URLs that start with /static/ .antMatchers("/static/**"); // now both URLs that start with /resources/ and /static/ will be ignored- Returns:
- the
WebSecurity.IgnoredRequestConfigurerto use for registering request that should be ignored
-
httpFirewall
public WebSecurity httpFirewall(org.springframework.security.web.firewall.HttpFirewall httpFirewall)
Allows customizing theHttpFirewall. The default isStrictHttpFirewall.- Parameters:
httpFirewall- the customHttpFirewall- Returns:
- the
WebSecurityfor further customizations
-
debug
public WebSecurity debug(boolean debugEnabled)
Controls debugging support for Spring Security.- Parameters:
debugEnabled- if true, enables debug support with Spring Security. Default is false.- Returns:
- the
WebSecurityfor further customization. - See Also:
EnableWebSecurity.debug()
-
addSecurityFilterChainBuilder
public WebSecurity addSecurityFilterChainBuilder(SecurityBuilder<? extends org.springframework.security.web.SecurityFilterChain> securityFilterChainBuilder)
Adds builders to create
SecurityFilterChaininstances.Typically this method is invoked automatically within the framework from
WebSecurityConfigurerAdapter.init(WebSecurity)- Parameters:
securityFilterChainBuilder- the builder to use to create theSecurityFilterChaininstances- Returns:
- the
WebSecurityfor further customizations
-
privilegeEvaluator
public WebSecurity privilegeEvaluator(org.springframework.security.web.access.WebInvocationPrivilegeEvaluator privilegeEvaluator)
Set theWebInvocationPrivilegeEvaluatorto be used. If this is not specified, then aDefaultWebInvocationPrivilegeEvaluatorwill be created whensecurityInterceptor(FilterSecurityInterceptor)is non null.- Parameters:
privilegeEvaluator- theWebInvocationPrivilegeEvaluatorto use- Returns:
- the
WebSecurityfor further customizations
-
expressionHandler
public WebSecurity expressionHandler(org.springframework.security.access.expression.SecurityExpressionHandler<org.springframework.security.web.FilterInvocation> expressionHandler)
Set theSecurityExpressionHandlerto be used. If this is not specified, then aDefaultWebSecurityExpressionHandlerwill be used.- Parameters:
expressionHandler- theSecurityExpressionHandlerto use- Returns:
- the
WebSecurityfor further customizations
-
getExpressionHandler
public org.springframework.security.access.expression.SecurityExpressionHandler<org.springframework.security.web.FilterInvocation> getExpressionHandler()
Gets theSecurityExpressionHandlerto be used.- Returns:
- the
SecurityExpressionHandlerfor further customizations
-
getPrivilegeEvaluator
public org.springframework.security.web.access.WebInvocationPrivilegeEvaluator getPrivilegeEvaluator()
Gets theWebInvocationPrivilegeEvaluatorto be used.- Returns:
- the
WebInvocationPrivilegeEvaluatorfor further customizations
-
securityInterceptor
public WebSecurity securityInterceptor(org.springframework.security.web.access.intercept.FilterSecurityInterceptor securityInterceptor)
Deprecated.Sets theFilterSecurityInterceptor. This is typically invoked byWebSecurityConfigurerAdapter.- Parameters:
securityInterceptor- theFilterSecurityInterceptorto use- Returns:
- the
WebSecurityfor further customizations
-
postBuildAction
public WebSecurity postBuildAction(java.lang.Runnable postBuildAction)
Executes the Runnable immediately after the build takes place- Parameters:
postBuildAction-- Returns:
- the
WebSecurityfor further customizations
-
performBuild
protected javax.servlet.Filter performBuild() throws java.lang.ExceptionDescription copied from class:AbstractConfiguredSecurityBuilderSubclasses must implement this method to build the object that is being returned.- Specified by:
performBuildin classAbstractConfiguredSecurityBuilder<javax.servlet.Filter,WebSecurity>- Returns:
- the Object to be buit or null if the implementation allows it
- Throws:
java.lang.Exception
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setServletContext
public void setServletContext(javax.servlet.ServletContext servletContext)
- Specified by:
setServletContextin interfaceorg.springframework.web.context.ServletContextAware
-
-