Class DefaultMethodSecurityExpressionHandler
java.lang.Object
org.springframework.security.access.expression.AbstractSecurityExpressionHandler<org.aopalliance.intercept.MethodInvocation>
org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler
- All Implemented Interfaces:
- org.springframework.aop.framework.AopInfrastructureBean,- org.springframework.beans.factory.Aware,- org.springframework.context.ApplicationContextAware,- MethodSecurityExpressionHandler,- SecurityExpressionHandler<org.aopalliance.intercept.MethodInvocation>
public class DefaultMethodSecurityExpressionHandler
extends AbstractSecurityExpressionHandler<org.aopalliance.intercept.MethodInvocation>
implements MethodSecurityExpressionHandler
The standard implementation of 
MethodSecurityExpressionHandler.
 A single instance should usually be shared amongst the beans that require expression support.
- Since:
- 3.0
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionorg.springframework.expression.EvaluationContextcreateEvaluationContext(Supplier<? extends @Nullable Authentication> authentication, org.aopalliance.intercept.MethodInvocation mi) Provides an evaluation context in which to evaluate security expressions for the invocation type.org.springframework.expression.spel.support.StandardEvaluationContextcreateEvaluationContextInternal(@Nullable Authentication auth, org.aopalliance.intercept.MethodInvocation mi) Uses aMethodSecurityEvaluationContextas the EvaluationContext implementation.protected MethodSecurityExpressionOperationscreateSecurityExpressionRoot(@Nullable Authentication authentication, org.aopalliance.intercept.MethodInvocation invocation) Creates the root object for expression evaluation.filter(@Nullable Object filterTarget, org.springframework.expression.Expression filterExpression, org.springframework.expression.EvaluationContext ctx) Filters thefilterTargetobject (which must be either aCollection,Array,MaporStream), by evaluating the supplied expression.protected StringDeprecated.protected org.springframework.core.ParameterNameDiscovererprotected AuthenticationTrustResolverDeprecated.voidsetDefaultRolePrefix(@Nullable String defaultRolePrefix) Deprecated.voidsetParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer) Sets theParameterNameDiscovererto use.voidsetPermissionCacheOptimizer(PermissionCacheOptimizer permissionCacheOptimizer) voidsetReturnObject(@Nullable Object returnObject, org.springframework.expression.EvaluationContext ctx) Used to inform the expression system of the return object for the given evaluation context.voidsetTrustResolver(AuthenticationTrustResolver trustResolver) Deprecated.Methods inherited from class org.springframework.security.access.expression.AbstractSecurityExpressionHandlercreateEvaluationContext, getAuthorizationManagerFactory, getBeanResolver, getDefaultAuthorizationManagerFactory, getExpressionParser, getPermissionEvaluator, getRoleHierarchy, setApplicationContext, setAuthorizationManagerFactory, setExpressionParser, setPermissionEvaluator, setRoleHierarchyMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.security.access.expression.SecurityExpressionHandlercreateEvaluationContext, getExpressionParser
- 
Field Details- 
loggerprotected final org.apache.commons.logging.Log logger
 
- 
- 
Constructor Details- 
DefaultMethodSecurityExpressionHandlerpublic DefaultMethodSecurityExpressionHandler()
 
- 
- 
Method Details- 
createEvaluationContextInternalpublic org.springframework.expression.spel.support.StandardEvaluationContext createEvaluationContextInternal(@Nullable Authentication auth, org.aopalliance.intercept.MethodInvocation mi) Uses aMethodSecurityEvaluationContextas the EvaluationContext implementation.- Overrides:
- createEvaluationContextInternalin class- AbstractSecurityExpressionHandler<org.aopalliance.intercept.MethodInvocation>
- Parameters:
- auth- the current authentication object
- mi- the invocation (filter, method, channel)
- Returns:
- A StandardEvaluationContextor potentially a custom subclass if overridden.
 
- 
createEvaluationContextpublic org.springframework.expression.EvaluationContext createEvaluationContext(Supplier<? extends @Nullable Authentication> authentication, org.aopalliance.intercept.MethodInvocation mi) Description copied from interface:SecurityExpressionHandlerProvides an evaluation context in which to evaluate security expressions for the invocation type. You can override this method in order to provide a custom implementation that uses lazy initialization of theAuthenticationobject. By default, this method uses eager initialization of theAuthenticationobject.- Specified by:
- createEvaluationContextin interface- SecurityExpressionHandler<org.aopalliance.intercept.MethodInvocation>
- Parameters:
- authentication- the- Supplierof the- Authenticationto use
- mi- the- SecurityExpressionHandlerto use
- Returns:
- the EvaluationContextto use
 
- 
createSecurityExpressionRootprotected MethodSecurityExpressionOperations createSecurityExpressionRoot(@Nullable Authentication authentication, org.aopalliance.intercept.MethodInvocation invocation) Creates the root object for expression evaluation.- Specified by:
- createSecurityExpressionRootin class- AbstractSecurityExpressionHandler<org.aopalliance.intercept.MethodInvocation>
- Parameters:
- authentication- the current authentication object
- invocation- the invocation (filter, method, channel)
- Returns:
- the object
 
- 
filterpublic Object filter(@Nullable Object filterTarget, org.springframework.expression.Expression filterExpression, org.springframework.expression.EvaluationContext ctx) Filters thefilterTargetobject (which must be either aCollection,Array,MaporStream), by evaluating the supplied expression.Returns new instances of the same type as the supplied filterTargetobject- Specified by:
- filterin interface- MethodSecurityExpressionHandler
- Parameters:
- filterTarget- the array or collection to be filtered.
- filterExpression- the expression which should be used as the filter condition. If it returns false on evaluation, the object will be removed from the returned collection
- ctx- the current evaluation context (as created through a call to- SecurityExpressionHandler.createEvaluationContext(org.springframework.security.core.Authentication, Object)
- Returns:
- The filtered Collection,Array,MaporStream
 
- 
setTrustResolverDeprecated.Sets theAuthenticationTrustResolverto be used. The default isAuthenticationTrustResolverImpl.- Parameters:
- trustResolver- the- AuthenticationTrustResolverto use. Cannot be null.
 
- 
getTrustResolverDeprecated.- Returns:
- The current AuthenticationTrustResolver
 
- 
setParameterNameDiscovererpublic void setParameterNameDiscoverer(org.springframework.core.ParameterNameDiscoverer parameterNameDiscoverer) Sets theParameterNameDiscovererto use. The default isDefaultSecurityParameterNameDiscoverer.- Parameters:
- parameterNameDiscoverer-
 
- 
getParameterNameDiscovererprotected org.springframework.core.ParameterNameDiscoverer getParameterNameDiscoverer()- Returns:
- The current ParameterNameDiscoverer
 
- 
setPermissionCacheOptimizer
- 
setReturnObjectpublic void setReturnObject(@Nullable Object returnObject, org.springframework.expression.EvaluationContext ctx) Description copied from interface:MethodSecurityExpressionHandlerUsed to inform the expression system of the return object for the given evaluation context. Only applies to method invocations.- Specified by:
- setReturnObjectin interface- MethodSecurityExpressionHandler
- Parameters:
- returnObject- the return object value
- ctx- the context within which the object should be set (as created through a call to- SecurityExpressionHandler.createEvaluationContext(org.springframework.security.core.Authentication, Object)
 
- 
setDefaultRolePrefixDeprecated.Sets the default prefix to be added to SecurityExpressionRoot.hasAnyRole(String...)orSecurityExpressionRoot.hasRole(String). For example, if hasRole("ADMIN") or hasRole("ROLE_ADMIN") is passed in, then the role ROLE_ADMIN will be used when the defaultRolePrefix is "ROLE_" (default).If null or empty, then no default role prefix is used. - Parameters:
- defaultRolePrefix- the default prefix to add to roles. Default "ROLE_".
 
- 
getDefaultRolePrefixDeprecated.- Returns:
- The default role prefix
 
 
- 
AbstractSecurityExpressionHandler.setAuthorizationManagerFactory(AuthorizationManagerFactory)instead