Class AbstractConfiguredSecurityBuilder<O,B extends SecurityBuilder<O>>
- java.lang.Object
-
- org.springframework.security.config.annotation.AbstractSecurityBuilder<O>
-
- org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder<O,B>
-
- Type Parameters:
O- The object that this builder returnsB- The type of this builder (that is returned by the base class)
- All Implemented Interfaces:
SecurityBuilder<O>
- Direct Known Subclasses:
AuthenticationManagerBuilder,HttpSecurity,WebSecurity
public abstract class AbstractConfiguredSecurityBuilder<O,B extends SecurityBuilder<O>> extends AbstractSecurityBuilder<O>
A base
SecurityBuilderthat allowsSecurityConfigurerto be applied to it. This makes modifying theSecurityBuildera strategy that can be customized and broken up into a number ofSecurityConfigurerobjects that have more specific goals than that of theSecurityBuilder.For example, a
SecurityBuildermay build anDelegatingFilterProxy, but aSecurityConfigurermight populate theSecurityBuilderwith the filters necessary for session management, form based login, authorization, etc.- See Also:
WebSecurity
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractConfiguredSecurityBuilder(ObjectPostProcessor<java.lang.Object> objectPostProcessor)Creates a new instance with the providedObjectPostProcessor.protectedAbstractConfiguredSecurityBuilder(ObjectPostProcessor<java.lang.Object> objectPostProcessor, boolean allowConfigurersOfSameType)Creates a new instance with the providedObjectPostProcessor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <C extends SecurityConfigurerAdapter<O,B>>
Capply(C configurer)Applies aSecurityConfigurerAdapterto thisSecurityBuilderand invokesSecurityConfigurerAdapter.setBuilder(SecurityBuilder).protected voidbeforeConfigure()Invoked prior to invoking eachSecurityConfigurer.configure(SecurityBuilder)method.protected voidbeforeInit()Invoked prior to invoking eachSecurityConfigurer.init(SecurityBuilder)method.protected OdoBuild()Executes the build using theSecurityConfigurer's that have been applied using the following steps: InvokesbeforeInit()for any subclass to hook into InvokesSecurityConfigurer.init(SecurityBuilder)for anySecurityConfigurerthat was applied to this builder. InvokesbeforeConfigure()for any subclass to hook into InvokesperformBuild()which actually builds the Object<C extends SecurityConfigurer<O,B>>
CgetConfigurer(java.lang.Class<C> clazz)Gets theSecurityConfigurerby its class name ornullif not found.<C extends SecurityConfigurer<O,B>>
java.util.List<C>getConfigurers(java.lang.Class<C> clazz)Gets all theSecurityConfigurerinstances by its class name or an empty List if not found.OgetOrBuild()Similar toAbstractSecurityBuilder.build()andAbstractSecurityBuilder.getObject()but checks the state to determine ifAbstractSecurityBuilder.build()needs to be called first.<C> CgetSharedObject(java.lang.Class<C> sharedType)Gets a shared Object.java.util.Map<java.lang.Class<?>,java.lang.Object>getSharedObjects()Gets the shared objectsBobjectPostProcessor(ObjectPostProcessor<java.lang.Object> objectPostProcessor)Specifies theObjectPostProcessorto use.protected abstract OperformBuild()Subclasses must implement this method to build the object that is being returned.protected <P> PpostProcess(P object)Performs post processing of an object.<C extends SecurityConfigurer<O,B>>
CremoveConfigurer(java.lang.Class<C> clazz)Removes and returns theSecurityConfigurerby its class name ornullif not found.<C extends SecurityConfigurer<O,B>>
java.util.List<C>removeConfigurers(java.lang.Class<C> clazz)Removes all theSecurityConfigurerinstances by its class name or an empty List if not found.<C> voidsetSharedObject(java.lang.Class<C> sharedType, C object)Sets an object that is shared by multipleSecurityConfigurer.-
Methods inherited from class org.springframework.security.config.annotation.AbstractSecurityBuilder
build, getObject
-
-
-
-
Constructor Detail
-
AbstractConfiguredSecurityBuilder
protected AbstractConfiguredSecurityBuilder(ObjectPostProcessor<java.lang.Object> objectPostProcessor)
Creates a new instance with the providedObjectPostProcessor. This post processor must support Object since there are many types of objects that may be post processed.- Parameters:
objectPostProcessor- theObjectPostProcessorto use
-
AbstractConfiguredSecurityBuilder
protected AbstractConfiguredSecurityBuilder(ObjectPostProcessor<java.lang.Object> objectPostProcessor, boolean allowConfigurersOfSameType)
Creates a new instance with the providedObjectPostProcessor. This post processor must support Object since there are many types of objects that may be post processed.- Parameters:
objectPostProcessor- theObjectPostProcessorto useallowConfigurersOfSameType- if true, will not override otherSecurityConfigurer's when performing apply
-
-
Method Detail
-
getOrBuild
public O getOrBuild()
Similar toAbstractSecurityBuilder.build()andAbstractSecurityBuilder.getObject()but checks the state to determine ifAbstractSecurityBuilder.build()needs to be called first.- Returns:
- the result of
AbstractSecurityBuilder.build()orAbstractSecurityBuilder.getObject(). If an error occurs while building, returns null.
-
apply
public <C extends SecurityConfigurerAdapter<O,B>> C apply(C configurer) throws java.lang.Exception
Applies aSecurityConfigurerAdapterto thisSecurityBuilderand invokesSecurityConfigurerAdapter.setBuilder(SecurityBuilder).- Parameters:
configurer-- Returns:
- the
SecurityConfigurerAdapterfor further customizations - Throws:
java.lang.Exception
-
apply
public <C extends SecurityConfigurer<O,B>> C apply(C configurer) throws java.lang.Exception
Applies aSecurityConfigurerto thisSecurityBuilderoverriding anySecurityConfigurerof the exact same class. Note that object hierarchies are not considered.- Parameters:
configurer-- Returns:
- the
SecurityConfigurerAdapterfor further customizations - Throws:
java.lang.Exception
-
setSharedObject
public <C> void setSharedObject(java.lang.Class<C> sharedType, C object)Sets an object that is shared by multipleSecurityConfigurer.- Parameters:
sharedType- the Class to key the shared object by.object- the Object to store
-
getSharedObject
public <C> C getSharedObject(java.lang.Class<C> sharedType)
Gets a shared Object. Note that object heirarchies are not considered.- Parameters:
sharedType- the type of the shared Object- Returns:
- the shared Object or null if it is not found
-
getSharedObjects
public java.util.Map<java.lang.Class<?>,java.lang.Object> getSharedObjects()
Gets the shared objects- Returns:
- the shared Objects
-
getConfigurers
public <C extends SecurityConfigurer<O,B>> java.util.List<C> getConfigurers(java.lang.Class<C> clazz)
Gets all theSecurityConfigurerinstances by its class name or an empty List if not found. Note that object hierarchies are not considered.- Parameters:
clazz- theSecurityConfigurerclass to look for- Returns:
- a list of
SecurityConfigurers for further customization
-
removeConfigurers
public <C extends SecurityConfigurer<O,B>> java.util.List<C> removeConfigurers(java.lang.Class<C> clazz)
Removes all theSecurityConfigurerinstances by its class name or an empty List if not found. Note that object hierarchies are not considered.- Parameters:
clazz- theSecurityConfigurerclass to look for- Returns:
- a list of
SecurityConfigurers for further customization
-
getConfigurer
public <C extends SecurityConfigurer<O,B>> C getConfigurer(java.lang.Class<C> clazz)
Gets theSecurityConfigurerby its class name ornullif not found. Note that object hierarchies are not considered.- Parameters:
clazz-- Returns:
- the
SecurityConfigurerfor further customizations
-
removeConfigurer
public <C extends SecurityConfigurer<O,B>> C removeConfigurer(java.lang.Class<C> clazz)
Removes and returns theSecurityConfigurerby its class name ornullif not found. Note that object hierarchies are not considered.- Parameters:
clazz-- Returns:
-
objectPostProcessor
public B objectPostProcessor(ObjectPostProcessor<java.lang.Object> objectPostProcessor)
Specifies theObjectPostProcessorto use.- Parameters:
objectPostProcessor- theObjectPostProcessorto use. Cannot be null- Returns:
- the
SecurityBuilderfor further customizations
-
postProcess
protected <P> P postProcess(P object)
Performs post processing of an object. The default is to delegate to theObjectPostProcessor.- Parameters:
object- the Object to post process- Returns:
- the possibly modified Object to use
-
doBuild
protected final O doBuild() throws java.lang.Exception
Executes the build using theSecurityConfigurer's that have been applied using the following steps:- Invokes
beforeInit()for any subclass to hook into - Invokes
SecurityConfigurer.init(SecurityBuilder)for anySecurityConfigurerthat was applied to this builder. - Invokes
beforeConfigure()for any subclass to hook into - Invokes
performBuild()which actually builds the Object
- Specified by:
doBuildin classAbstractSecurityBuilder<O>- Returns:
- the object that should be returned by
AbstractSecurityBuilder.build(). - Throws:
java.lang.Exception- if an error occurs
- Invokes
-
beforeInit
protected void beforeInit() throws java.lang.ExceptionInvoked prior to invoking eachSecurityConfigurer.init(SecurityBuilder)method. Subclasses may override this method to hook into the lifecycle without using aSecurityConfigurer.- Throws:
java.lang.Exception
-
beforeConfigure
protected void beforeConfigure() throws java.lang.ExceptionInvoked prior to invoking eachSecurityConfigurer.configure(SecurityBuilder)method. Subclasses may override this method to hook into the lifecycle without using aSecurityConfigurer.- Throws:
java.lang.Exception
-
performBuild
protected abstract O performBuild() throws java.lang.Exception
Subclasses must implement this method to build the object that is being returned.- Returns:
- the Object to be buit or null if the implementation allows it
- Throws:
java.lang.Exception
-
-