public class PolicyOverride extends Object implements org.springframework.core.Ordered
Policy
used to introduce, alter or remove policy configuration on one
or more component methods. Usually declared as a bean in a Spring application context
Configuration class and generally associated with a single Aspect
declaring component,
although the latter is not a requirement. The aspect is responsible for declaring pointcuts that
are responsible for catching calls to methods that should be protected with policy enforcement.
The aspect delegates to PolicyAspectProcessor
, which is responsible for utilizing
PolicyOverride instances to define policy enforcement configuration. In the absence of
PolicyOverride, any applicable Policy
annotations are leveraged.
When enhancing (altering or removing) existing Policy
annotated methods in the Broadleaf
stack, it is not necessary to declare any aspect, as DefaultPolicyAspect
is already
responsible for recognizing these fields. In this case, you may simply declare an instance of
PolicyOverride
with the desired change. Here's an example that alters policy
configuration for a Policy annotated method in TrackableRepository
.
@Bean
PolicyOverride saveOverride() {
return new PolicyOverride("save.*")
.withPermissionRoots(new String[] {"OTHER"})
.withOperationTypes(new OperationType[] {OperationType.UPDATE})
.withAspect(DefaultPolicyAspect.class);
}
When adding policy protection to a method in your own codebase (i.e. extending from Broadleaf),
it is generally easiest to add the Policy
annotation to your methods, which will
automatically be picked up by DefaultPolicyAspect
.
When adding policy protection to a method in the Broadleaf codebase (or Spring codebase) for
which there is not already existing protection, it is necessary to declare an aspect and
appropriate supporting PolicyOverride
instances. See CrudPolicyAspect
as an
example that catches calls to methods in Spring's CrudRepository
. Also, review
CrudPolicyConfiguration
for examples of the supporting PolicyOverride
instances
declared against that aspect.
PolicyOverride
instances are also Ordered
. The first matching override in the
ordered list is the one to be used. This means it is easy to replace the behavior introduced by a
PolicyOverride instance in the Broadleaf codebase with a different/custom PolicyOverride instance
matching on the same method with a higher precedence ordering.
Constructor and Description |
---|
PolicyOverride(Method position) |
PolicyOverride(String positionRegex) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canEqual(Object other) |
boolean |
equals(Object o) |
Class<?> |
getAspect()
Optional parameter used to differentiate which aspect this override should apply against in
the
PolicyAspectProcessor . |
IdentityType[] |
getIdentityTypes()
|
OperationType[] |
getOperationTypes()
|
int |
getOrder() |
String |
getOwnerIdentifier()
|
int |
getOwnerIdentifierParam()
|
int |
getParam()
See
Policy.param() . |
PermissionMatchingStrategy |
getPermissionMatchingStrategy()
|
String[] |
getPermissionRoots()
|
Method |
getPosition()
Matches against a specific method name and params encountered via an aspect pointcut.
|
Pattern |
getPositionPattern()
Matches against a specific method name encountered via an aspect pointcut.
|
String |
getPositionRegex()
Regex string for matching target method.
|
int |
hashCode() |
boolean |
isRemoveTarget()
Whether or not existing policy enforcement configuration at the target method should be
removed.
|
PolicyOverride |
withAspect(Class<?> aspect) |
PolicyOverride |
withIdentityTypes(IdentityType[] identityTypes) |
PolicyOverride |
withOperationTypes(OperationType[] operationTypes) |
PolicyOverride |
withParam(int param) |
PolicyOverride |
withPermissionMatchingStrategy(PermissionMatchingStrategy permissionMatchingStrategy) |
PolicyOverride |
withPermissionRoots(String[] permissionRoots) |
PolicyOverride |
withRemoveTarget(boolean removeTarget) |
public PolicyOverride(Method position)
public PolicyOverride(String positionRegex)
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
public PolicyOverride withAspect(Class<?> aspect)
public PolicyOverride withParam(int param)
public PolicyOverride withPermissionRoots(String[] permissionRoots)
public PolicyOverride withOperationTypes(OperationType[] operationTypes)
public PolicyOverride withIdentityTypes(IdentityType[] identityTypes)
public PolicyOverride withRemoveTarget(boolean removeTarget)
public PolicyOverride withPermissionMatchingStrategy(PermissionMatchingStrategy permissionMatchingStrategy)
protected boolean canEqual(Object other)
public Method getPosition()
public Pattern getPositionPattern()
public Class<?> getAspect()
PolicyAspectProcessor
. If null, this override will apply against all method
pointcuts passed into PolicyAspectProcessor, regardless of the originating aspect. However,
this may result in wasted regex computation for inapplicable aspects, so this field is
generally set as a performance optimization.public int getParam()
Policy.param()
. Default is -1.Policy.param()
. Default is -1.public int getOwnerIdentifierParam()
Policy.ownerIdentifierParam()
. Default is -1.Policy.ownerIdentifierParam()
. Default is -1.public String[] getPermissionRoots()
Policy.permissionRoots()
. Default is empty array.Policy.permissionRoots()
. Default is empty array.public PermissionMatchingStrategy getPermissionMatchingStrategy()
Policy.permissionMatchingStrategy()
. Deafult is MatchingStrategy#ANY
public OperationType[] getOperationTypes()
Policy.operationTypes()
. Default is OperationType.UNKNOWN
.Policy.operationTypes()
. Default is OperationType.UNKNOWN
.public IdentityType[] getIdentityTypes()
Policy.identityTypes()
. Default is IdentityType.UNKNOWN
.Policy.identityTypes()
. Default is IdentityType.UNKNOWN
.public String getOwnerIdentifier()
Policy.ownerIdentifier()
. Default is
PolicyUtils.DEFAULT_AUTH_DETAILS_OWNER_ID
Policy.ownerIdentifier()
. Default is
PolicyUtils.DEFAULT_AUTH_DETAILS_OWNER_ID
DefaultTrackablePolicyUtils.getAuthDetailsOwnerIdentifier()
public boolean isRemoveTarget()
public String getPositionRegex()
positionPattern
.positionPattern
.Copyright © 2021. All rights reserved.