Class GlobalMethodSecurityConfiguration
- java.lang.Object
-
- org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.SmartInitializingSingleton,org.springframework.context.annotation.ImportAware
@Configuration(proxyBeanMethods=false) @Role(2) public class GlobalMethodSecurityConfiguration extends java.lang.Object implements org.springframework.context.annotation.ImportAware, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.BeanFactoryAwareBaseConfigurationfor enabling global method security. Classes may extend this class to customize the defaults, but must be sure to specify theEnableGlobalMethodSecurityannotation on the subclass.- Since:
- 3.2
- See Also:
EnableGlobalMethodSecurity
-
-
Constructor Summary
Constructors Constructor Description GlobalMethodSecurityConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.springframework.security.access.AccessDecisionManageraccessDecisionManager()Allows subclasses to provide a customAccessDecisionManager.protected org.springframework.security.access.intercept.AfterInvocationManagerafterInvocationManager()Provide a customAfterInvocationManagerfor the default implementation ofmethodSecurityInterceptor(MethodSecurityMetadataSource).voidafterSingletonsInstantiated()protected org.springframework.security.authentication.AuthenticationManagerauthenticationManager()Allows providing a customAuthenticationManager.protected voidconfigure(AuthenticationManagerBuilder auth)Sub classes can override this method to register different types of authentication.protected org.springframework.security.access.expression.method.MethodSecurityExpressionHandlercreateExpressionHandler()Provide aMethodSecurityExpressionHandlerthat is registered with theExpressionBasedPreInvocationAdvice.protected org.springframework.security.access.method.MethodSecurityMetadataSourcecustomMethodSecurityMetadataSource()Provides a customMethodSecurityMetadataSourcethat is registered with themethodSecurityMetadataSource().protected org.springframework.security.access.expression.method.MethodSecurityExpressionHandlergetExpressionHandler()Gets theMethodSecurityExpressionHandleror creates it usingexpressionHandler.org.aopalliance.intercept.MethodInterceptormethodSecurityInterceptor(org.springframework.security.access.method.MethodSecurityMetadataSource methodSecurityMetadataSource)Creates the default MethodInterceptor which is a MethodSecurityInterceptor using the following methods to construct it.org.springframework.security.access.method.MethodSecurityMetadataSourcemethodSecurityMetadataSource()Provides the defaultMethodSecurityMetadataSourcethat will be used.org.springframework.security.access.prepost.PreInvocationAuthorizationAdvicepreInvocationAuthorizationAdvice()Creates thePreInvocationAuthorizationAdviceto be used.protected org.springframework.security.access.intercept.RunAsManagerrunAsManager()Provide a customRunAsManagerfor the default implementation ofmethodSecurityInterceptor(MethodSecurityMetadataSource).voidsetBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)voidsetImportMetadata(org.springframework.core.type.AnnotationMetadata importMetadata)Obtains the attributes fromEnableGlobalMethodSecurityif this class was imported using theEnableGlobalMethodSecurityannotation.voidsetMethodSecurityExpressionHandler(java.util.List<org.springframework.security.access.expression.method.MethodSecurityExpressionHandler> handlers)voidsetObjectPostProcessor(ObjectPostProcessor<java.lang.Object> objectPostProcessor)
-
-
-
Method Detail
-
methodSecurityInterceptor
@Bean public org.aopalliance.intercept.MethodInterceptor methodSecurityInterceptor(org.springframework.security.access.method.MethodSecurityMetadataSource methodSecurityMetadataSource)
Creates the default MethodInterceptor which is a MethodSecurityInterceptor using the following methods to construct it.Subclasses can override this method to provide a different
MethodInterceptor.- Parameters:
methodSecurityMetadataSource- the defaultMethodSecurityMetadataSource.- Returns:
- the
MethodInterceptor.
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()
- Specified by:
afterSingletonsInstantiatedin interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
afterInvocationManager
protected org.springframework.security.access.intercept.AfterInvocationManager afterInvocationManager()
Provide a customAfterInvocationManagerfor the default implementation ofmethodSecurityInterceptor(MethodSecurityMetadataSource). The default is null if pre post is not enabled. Otherwise, it returns aAfterInvocationProviderManager.Subclasses should override this method to provide a custom
AfterInvocationManager- Returns:
- the
AfterInvocationManagerto use
-
runAsManager
protected org.springframework.security.access.intercept.RunAsManager runAsManager()
Provide a customRunAsManagerfor the default implementation ofmethodSecurityInterceptor(MethodSecurityMetadataSource). The default is null.- Returns:
- the
RunAsManagerto use
-
accessDecisionManager
protected org.springframework.security.access.AccessDecisionManager accessDecisionManager()
Allows subclasses to provide a customAccessDecisionManager. The default is aAffirmativeBasedwith the following voters:PreInvocationAuthorizationAdviceVoterRoleVoterAuthenticatedVoter
- Returns:
- the
AccessDecisionManagerto use
-
createExpressionHandler
protected org.springframework.security.access.expression.method.MethodSecurityExpressionHandler createExpressionHandler()
Provide aMethodSecurityExpressionHandlerthat is registered with theExpressionBasedPreInvocationAdvice. The default isDefaultMethodSecurityExpressionHandlerwhich optionally will Autowire anAuthenticationTrustResolver.Subclasses may override this method to provide a custom
MethodSecurityExpressionHandler- Returns:
- the
MethodSecurityExpressionHandlerto use
-
getExpressionHandler
protected final org.springframework.security.access.expression.method.MethodSecurityExpressionHandler getExpressionHandler()
Gets theMethodSecurityExpressionHandleror creates it usingexpressionHandler.- Returns:
- a non
nullMethodSecurityExpressionHandler
-
customMethodSecurityMetadataSource
protected org.springframework.security.access.method.MethodSecurityMetadataSource customMethodSecurityMetadataSource()
Provides a customMethodSecurityMetadataSourcethat is registered with themethodSecurityMetadataSource(). Default is null.- Returns:
- a custom
MethodSecurityMetadataSourcethat is registered with themethodSecurityMetadataSource()
-
authenticationManager
protected org.springframework.security.authentication.AuthenticationManager authenticationManager() throws java.lang.ExceptionAllows providing a customAuthenticationManager. The default is to use any authentication mechanisms registered byconfigure(AuthenticationManagerBuilder). Ifconfigure(AuthenticationManagerBuilder)was not overridden, then anAuthenticationManageris attempted to be autowired by type.- Returns:
- the
AuthenticationManagerto use - Throws:
java.lang.Exception
-
configure
protected void configure(AuthenticationManagerBuilder auth) throws java.lang.Exception
Sub classes can override this method to register different types of authentication. If not overridden,configure(AuthenticationManagerBuilder)will attempt to autowire by type.- Parameters:
auth- theAuthenticationManagerBuilderused to register different authentication mechanisms for the global method security.- Throws:
java.lang.Exception
-
methodSecurityMetadataSource
@Bean @Role(2) public org.springframework.security.access.method.MethodSecurityMetadataSource methodSecurityMetadataSource()
Provides the defaultMethodSecurityMetadataSourcethat will be used. It creates aDelegatingMethodSecurityMetadataSourcebased uponcustomMethodSecurityMetadataSource()and the attributes onEnableGlobalMethodSecurity.- Returns:
- the
MethodSecurityMetadataSource
-
preInvocationAuthorizationAdvice
@Bean public org.springframework.security.access.prepost.PreInvocationAuthorizationAdvice preInvocationAuthorizationAdvice()
Creates thePreInvocationAuthorizationAdviceto be used. The default isExpressionBasedPreInvocationAdvice.- Returns:
- the
PreInvocationAuthorizationAdvice
-
setImportMetadata
public final void setImportMetadata(org.springframework.core.type.AnnotationMetadata importMetadata)
Obtains the attributes fromEnableGlobalMethodSecurityif this class was imported using theEnableGlobalMethodSecurityannotation.- Specified by:
setImportMetadatain interfaceorg.springframework.context.annotation.ImportAware
-
setObjectPostProcessor
@Autowired(required=false) public void setObjectPostProcessor(ObjectPostProcessor<java.lang.Object> objectPostProcessor)
-
setMethodSecurityExpressionHandler
@Autowired(required=false) public void setMethodSecurityExpressionHandler(java.util.List<org.springframework.security.access.expression.method.MethodSecurityExpressionHandler> handlers)
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException- Specified by:
setBeanFactoryin interfaceorg.springframework.beans.factory.BeanFactoryAware- Throws:
org.springframework.beans.BeansException
-
-