public class DefaultTrackablePolicyUtils extends Object implements TrackablePolicyUtils
AUTH_DETAILS_ADMIN_USER_ID_KEY, AUTH_DETAILS_APPLICATION_ACCESS_KEY, AUTH_DETAILS_APPLICATIONS_KEY, AUTH_DETAILS_CUSTOMER_CONTEXT_IDS, AUTH_DETAILS_GLOBAL_KEY, AUTH_DETAILS_TENANT_ACCESS_KEY, AUTH_DETAILS_TENANT_KEY
DEFAULT_AUTH_DETAILS_OWNER_ID, ROLE_ANONYMOUS
Constructor and Description |
---|
DefaultTrackablePolicyUtils(CatalogFinder<Catalog> catalogFinder,
TrackableBehaviorUtil trackableBehaviorUtil) |
DefaultTrackablePolicyUtils(CatalogFinder<Catalog> catalogFinder,
TrackableBehaviorUtil behaviorUtil,
String ownerIdentifier) |
Modifier and Type | Method and Description |
---|---|
protected Map<String,List<String>> |
expandPermissionRootsToPermissions(@NonNull String[] permissionRoots,
OperationType operationType) |
org.springframework.core.convert.converter.Converter<org.springframework.security.core.Authentication,Map<String,Object>> |
getAttributesConverter() |
String |
getAuthDetailsOwnerIdentifier()
Returns the owner identifier when evaluating owned entities.
|
Map<String,Object> |
getAuthenticationAttributes()
Retrieves the attributes on the current
Authentication that are useful in making
policy determinations. |
protected Collection<String> |
getCustomerContextIdsForUser() |
protected Optional<String> |
getImplicitApplicationCatalog(Application application,
Catalog catalog) |
protected PolicyResponse |
invalidPolicyResponse(PolicyResponse response,
String reason,
ContextInfo contextInfo) |
protected PolicyResponse |
invalidPolicyResponse(PolicyResponse response,
String reason,
org.apache.commons.lang3.tuple.Pair<String,String>... details) |
protected boolean |
isAdminUser(Map<String,Object> details) |
boolean |
isAnonymous()
Determine whether or not a user is an anonymous user.
|
protected boolean |
isApplicationCatalogAddAllowed(Application application,
Catalog catalog) |
protected boolean |
isApplicationVisible(Application application) |
boolean |
isCatalogMutable(@NonNull Application application,
@NonNull Catalog catalog)
Check if a catalog is mutable, given an application.
|
boolean |
isCatalogVisible(@NonNull Application application,
Catalog catalog)
Check if a catalog is visible, given an application.
|
protected boolean |
isCatalogVisible(Catalog catalog,
Application application) |
protected boolean |
isContextVisible(ContextInfo contextInfo) |
protected boolean |
isGlobalApplication(String applicationId) |
protected boolean |
isGlobalChangeInHiddenCatalog(Application application,
Catalog catalog) |
protected boolean |
isGlobalTenant(String tenantId) |
boolean |
isGlobalTenantUser()
Whether or not the current user is a global user.
|
protected boolean |
isGlobalTenantUser(Map<String,Object> details) |
boolean |
isMutationPossibleForContext(ContextInfo contextInfo)
Return whether or not the currently identified user has the necessary assigned tenant
relationships to make a mutating operation possible given the requested application, and/or
catalog, and/or lack thereof.
|
protected boolean |
isNotUser(Map<String,Object> details) |
boolean |
isOwnerUser(String ownerIdentifier)
Detect whether or not the currently logged in user (if applicable) is a user capable of
operating as a
IdentityType.OWNER . |
protected boolean |
isSandboxVisible(ContextInfo contextInfo) |
protected boolean |
isTenantVisible(String tenantId,
String applicationId) |
boolean |
isUserApplicationLevelAccess()
Whether or not the current user has access to the application level context.
|
protected boolean |
isUserApplicationLevelAccess(Map<String,Object> authDetails) |
boolean |
isUserApplicationRestricted()
Whether or not the current user has any application restrictions.
|
protected boolean |
isUserApplicationRestricted(Map<String,Object> details) |
boolean |
isUserTenantLevelAccess()
Whether or not the current user has access to the tenant level context.
|
protected boolean |
isUserTenantLevelAccess(Map<String,Object> authDetails) |
boolean |
isValidApplicationUser(Application application)
Check if the user described by the current
Authentication is a member of the
application instance provided. |
boolean |
isValidApplicationUser(Application application,
boolean isGlobalChange)
Check if the user described by the current
Authentication is a member of the
application instance provided. |
boolean |
isValidApplicationUser(String applicationId)
Version of
TrackablePolicyUtils.isValidApplicationUser(Application) that takes just he application's ID. |
boolean |
isValidApplicationUser(String applicationId,
boolean isTenantChange)
Version of
TrackablePolicyUtils.isValidApplicationUser(Application, boolean) that takes just he
application's ID. |
protected boolean |
isValidCustomerContext(String customerContextId) |
boolean |
isValidSandboxUser()
Return whether or not the currently identified user is capable of viewing a sandbox context.
|
boolean |
isValidTenantUser(String tenantId,
boolean isTenantLevelContext,
boolean isGlobalChange)
Check if the user described by the current
Authentication is a member of the tenant
instance provided. |
void |
setAttributesConverter(org.springframework.core.convert.converter.Converter<org.springframework.security.core.Authentication,Map<String,Object>> attributesConverter) |
protected Stream<String> |
streamApplications(Map<String,Object> details) |
protected PolicyResponse |
validateApplicationCatalogUpdate(@NonNull Trackable entity,
@NonNull Application application)
If a catalog discriminated entity, validate that the current user is capable of updating an
entity via the catalogs visible to the current application.
|
protected PolicyResponse |
validateApplicationUpdate(@NonNull Trackable entity,
@NonNull Application application)
If an application discriminated entity, validate that the current user is capable of updating
an entity via the application requested in the context.
|
protected boolean |
validateCatalogInsert(@NonNull ContextInfo contextInfo)
If a catalog discriminated entity, validate that the current user is capable of inserting an
entity via the application and catalog requested in the context.
|
PolicyResponse |
validateContext(ContextInfo contextInfo)
Review the
ContextInfo parameter for valid tenant user membership and valid catalog
visibility based on the current Authentication and requested tenant information in
the contextInfo. |
PolicyResponse |
validateContext(ContextInfo contextInfo,
String[] requiredPermissionRoots,
PermissionMatchingStrategy permissionMatchingStrategy,
OperationType operationType)
Review the
ContextInfo parameter for valid tenant user membership and valid catalog
visibility based on the current Authentication and requested tenant information in
the contextInfo. |
PolicyResponse |
validateDelete(Trackable entity,
ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy)
Validate that before deleting (if the catalog discrimination is in play) that the item's
catalog is both visible to the current application, and mutable.
|
protected PolicyResponse |
validateEntityOperation(Trackable entity,
ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy,
OperationType operationType) |
protected PolicyResponse |
validateEntityUpdate(Trackable entity,
@NonNull ContextInfo contextInfo)
Check update validity for a given entity instance
|
protected PolicyResponse |
validateEntityUpdateForTenantFactors(Trackable entity,
Application application,
String tenantId,
TrackableBehaviorPackage behavior) |
protected PolicyResponse |
validateGlobalMutateToInheritedCatalog(Trackable entity,
ContextInfo contextInfo) |
protected PolicyResponse |
validateGlobalUpdateToHiddenCatalog(Trackable entity) |
PolicyResponse |
validateInsert(Trackable entity,
ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy)
Validate that before inserting (if catalog discrimination is in play and the current entity
is catalog discriminatable) that the current catalog target for insertion is mutable.
|
protected PolicyResponse |
validateOperation(ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy) |
protected PolicyResponse |
validateOperation(ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy,
OperationType operationType) |
PolicyResponse |
validateOther(ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy)
Validate that before misc operation, the required permission is available
|
PolicyResponse |
validateOwner(Object test,
IdentityType[] identityTypes,
String ownerIdentifier)
Validate the object against the currently logged in user.
|
PolicyResponse |
validatePermission(ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy)
Validate the permission against the granted authorities of the current
Authentication . |
PolicyResponse |
validatePermission(String[] permissionRoots,
PermissionMatchingStrategy strategy,
OperationType operationType,
ContextInfo contextInfo)
Validate the permission against the granted authorities of the current
Authentication . |
PolicyResponse |
validateRead(ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy)
Validate that before reading, the required permission is available.
|
protected boolean |
validateTenantTrackableUpdate(Trackable entity,
Application application,
TrackableBehaviorPackage behavior) |
protected PolicyResponse |
validateTenantUpdate(@NonNull Trackable entity,
String tenantId) |
PolicyResponse |
validateUpdate(Trackable entity,
ContextInfo contextInfo,
String[] permissionRoots,
PermissionMatchingStrategy strategy)
Validate that before updating (if the catalog discrimination is in play) that the item's
catalog is both visible to the current application, and mutable.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAuthentication, validatePermissions
public DefaultTrackablePolicyUtils(CatalogFinder<Catalog> catalogFinder, TrackableBehaviorUtil trackableBehaviorUtil)
public DefaultTrackablePolicyUtils(CatalogFinder<Catalog> catalogFinder, TrackableBehaviorUtil behaviorUtil, String ownerIdentifier)
@Autowired @Qualifier(value="authenticationAttributesConverter") public void setAttributesConverter(@Nullable org.springframework.core.convert.converter.Converter<org.springframework.security.core.Authentication,Map<String,Object>> attributesConverter)
public String getAuthDetailsOwnerIdentifier()
getAuthDetailsOwnerIdentifier
in interface PolicyUtils
public Map<String,Object> getAuthenticationAttributes()
PolicyUtils
Authentication
that are useful in making
policy determinations. This method is expected to return the attributes in a map which is
generally achieved by a registered Converter
bean.getAuthenticationAttributes
in interface PolicyUtils
Authentication
public PolicyResponse validateContext(@Nullable ContextInfo contextInfo)
TrackablePolicyUtils
ContextInfo
parameter for valid tenant user membership and valid catalog
visibility based on the current Authentication
and requested tenant information in
the contextInfo.validateContext
in interface TrackablePolicyUtils
contextInfo
- the context containing multitenant application, tenant and catalog
informationpublic PolicyResponse validateContext(@Nullable ContextInfo contextInfo, @Nullable String[] requiredPermissionRoots, @Nullable PermissionMatchingStrategy permissionMatchingStrategy, @Nullable OperationType operationType)
TrackablePolicyUtils
ContextInfo
parameter for valid tenant user membership and valid catalog
visibility based on the current Authentication
and requested tenant information in
the contextInfo.
Additionally allows supplying policy requirements to inform validation decisions.
validateContext
in interface TrackablePolicyUtils
contextInfo
- the context containing multitenant application, tenant and catalog
informationrequiredPermissionRoots
- the permission roots required by the policypermissionMatchingStrategy
- how to validate multiple permissionsoperationType
- the operation type required by the policypublic boolean isValidSandboxUser()
TrackablePolicyUtils
isValidSandboxUser
in interface TrackablePolicyUtils
public boolean isMutationPossibleForContext(@Nullable ContextInfo contextInfo)
TrackablePolicyUtils
isMutationPossibleForContext
in interface TrackablePolicyUtils
contextInfo
- The requested contextprotected boolean isSandboxVisible(ContextInfo contextInfo)
protected boolean isContextVisible(ContextInfo contextInfo)
protected boolean isValidCustomerContext(String customerContextId)
@NonNull protected Collection<String> getCustomerContextIdsForUser()
protected boolean isTenantVisible(@Nullable String tenantId, @Nullable String applicationId)
protected boolean isApplicationVisible(@Nullable Application application)
protected boolean isCatalogVisible(@Nullable Catalog catalog, @Nullable Application application)
public boolean isValidTenantUser(@Nullable String tenantId, boolean isTenantLevelContext, boolean isGlobalChange)
TrackablePolicyUtils
Authentication
is a member of the tenant
instance provided. This is generally determined by looking at
PolicyUtils.getAuthenticationAttributes()
.isValidTenantUser
in interface TrackablePolicyUtils
tenantId
- The ID of the tenant instance with which to check user membershipisTenantLevelContext
- Whether or not the current context is for the tenant level itselfisGlobalChange
- Whether or not the current change is mutating a "global" resource,
belonging to no particular tenantprotected boolean isGlobalTenant(@Nullable String tenantId)
public boolean isUserTenantLevelAccess()
TrackablePolicyUtils
PolicyUtils.getAuthenticationAttributes()
.isUserTenantLevelAccess
in interface TrackablePolicyUtils
public boolean isValidApplicationUser(@NonNull Application application)
TrackablePolicyUtils
Authentication
is a member of the
application instance provided. This is generally determined by looking at
PolicyUtils.getAuthenticationAttributes()
.isValidApplicationUser
in interface TrackablePolicyUtils
application
- The application instance with which to check user membershippublic boolean isValidApplicationUser(@NonNull String applicationId)
TrackablePolicyUtils
TrackablePolicyUtils.isValidApplicationUser(Application)
that takes just he application's ID.
If null, that means this is the global application.isValidApplicationUser
in interface TrackablePolicyUtils
applicationId
- The ID of the application instance with which to check user membershippublic boolean isValidApplicationUser(@NonNull Application application, boolean isGlobalChange)
TrackablePolicyUtils
Authentication
is a member of the
application instance provided. This is generally determined by looking at
PolicyUtils.getAuthenticationAttributes()
.isValidApplicationUser
in interface TrackablePolicyUtils
application
- The application instance with which to check user membershipisGlobalChange
- Whether or not the current mutating change is against a "tenant"
resource, belonging to a tenant but not particular applicationpublic boolean isValidApplicationUser(@Nullable String applicationId, boolean isTenantChange)
TrackablePolicyUtils
TrackablePolicyUtils.isValidApplicationUser(Application, boolean)
that takes just he
application's ID. If null, that means this is the global application.isValidApplicationUser
in interface TrackablePolicyUtils
applicationId
- The ID of the application instance with which to check user membershipisTenantChange
- Whether or not the current mutating change is against a "tenant"
resource, belonging to a tenant but not particular applicationpublic boolean isUserApplicationLevelAccess()
TrackablePolicyUtils
PolicyUtils.getAuthenticationAttributes()
.isUserApplicationLevelAccess
in interface TrackablePolicyUtils
protected boolean isUserApplicationLevelAccess(Map<String,Object> authDetails)
public boolean isUserApplicationRestricted()
TrackablePolicyUtils
PolicyUtils.getAuthenticationAttributes()
.isUserApplicationRestricted
in interface TrackablePolicyUtils
protected boolean isUserApplicationRestricted(Map<String,Object> details)
protected boolean isGlobalApplication(@Nullable String applicationId)
public boolean isGlobalTenantUser()
TrackablePolicyUtils
PolicyUtils.getAuthenticationAttributes()
.isGlobalTenantUser
in interface TrackablePolicyUtils
public boolean isOwnerUser(@Nullable String ownerIdentifier)
TrackablePolicyUtils
IdentityType.OWNER
. If so, the user may participate in validation for
owned entities. See Policy.identityTypes()
.isOwnerUser
in interface TrackablePolicyUtils
ownerIdentifier
- The identifier key to use when verifying ownership.IdentityType.OWNER
.getAuthDetailsOwnerIdentifier()
,
Policy.ownerIdentifier()
,
Owned
public boolean isAnonymous()
TrackablePolicyUtils
isAnonymous
in interface TrackablePolicyUtils
public boolean isCatalogVisible(@NonNull @NonNull Application application, Catalog catalog)
TrackablePolicyUtils
Authentication
, especially details *
regarding application membership.isCatalogVisible
in interface TrackablePolicyUtils
application
- The application instance with which to weigh catalog visibility againstcatalog
- The catalog for which visibility status is being checkedpublic boolean isCatalogMutable(@NonNull @NonNull Application application, @NonNull @NonNull Catalog catalog)
TrackablePolicyUtils
Authentication
, especially details
regarding application membership.isCatalogMutable
in interface TrackablePolicyUtils
application
- The application instance with which to weigh catalog mutability againstcatalog
- The catalog for which mutability status is being checkedprotected Optional<String> getImplicitApplicationCatalog(Application application, Catalog catalog)
public PolicyResponse validateInsert(@Nullable Trackable entity, @Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy)
TrackablePolicyUtils
validateInsert
in interface TrackablePolicyUtils
entity
- The item being insertedcontextInfo
- the context containing multitenant application and catalog informationpermissionRoots
- The permission roots to validate. If not specified, then permission
validation will not be performed.strategy
- how to treat multiple permissionsprotected boolean validateCatalogInsert(@NonNull @NonNull ContextInfo contextInfo)
contextInfo
- The context containing the current application and current catalogprotected boolean isGlobalChangeInHiddenCatalog(@Nullable Application application, @Nullable Catalog catalog)
protected boolean isApplicationCatalogAddAllowed(Application application, Catalog catalog)
public PolicyResponse validateRead(@Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy)
TrackablePolicyUtils
validateRead
in interface TrackablePolicyUtils
contextInfo
- the context containing multitenant application and catalog informationpermissionRoots
- The permission roots to validate. If not specified, then permission
validation will not be performed.strategy
- how to treat multiple permissionspublic PolicyResponse validateUpdate(@Nullable Trackable entity, @Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy)
TrackablePolicyUtils
validateUpdate
in interface TrackablePolicyUtils
entity
- The item being updatedcontextInfo
- the context containing multitenant application and catalog informationpermissionRoots
- The permission to validate. If not specified, then permission
validation will not be performed.strategy
- how to treat multiple permissionspublic PolicyResponse validateDelete(@Nullable Trackable entity, @Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy)
TrackablePolicyUtils
validateDelete
in interface TrackablePolicyUtils
entity
- The item being deletedcontextInfo
- the context containing multitenant application and catalog informationpermissionRoots
- The permission roots to validate. If not specified, then permission
validation will not be performed.strategy
- how to treat multiple permissionsprotected PolicyResponse validateEntityOperation(@Nullable Trackable entity, @Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy, @Nullable OperationType operationType)
protected PolicyResponse validateEntityUpdate(@Nullable Trackable entity, @NonNull @NonNull ContextInfo contextInfo)
entity
- The Trackable entitycontextInfo
- The context containing the current application and current catalog@Nullable protected PolicyResponse validateEntityUpdateForTenantFactors(Trackable entity, @Nullable Application application, String tenantId, TrackableBehaviorPackage behavior)
protected boolean validateTenantTrackableUpdate(Trackable entity, @Nullable Application application, TrackableBehaviorPackage behavior)
protected PolicyResponse validateGlobalUpdateToHiddenCatalog(Trackable entity)
protected PolicyResponse validateGlobalMutateToInheritedCatalog(Trackable entity, @Nullable ContextInfo contextInfo)
protected PolicyResponse validateApplicationCatalogUpdate(@NonNull @NonNull Trackable entity, @NonNull @NonNull Application application)
entity
- The catalog discriminated entityapplication
- The application whose associated catalogs should be reviewedprotected PolicyResponse validateApplicationUpdate(@NonNull @NonNull Trackable entity, @NonNull @NonNull Application application)
entity
- The application discriminated entityapplication
- The current applicationprotected PolicyResponse validateTenantUpdate(@NonNull @NonNull Trackable entity, String tenantId)
public PolicyResponse validateOther(@Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy)
TrackablePolicyUtils
validateOther
in interface TrackablePolicyUtils
contextInfo
- the context containing multitenant application and catalog informationpermissionRoots
- The permission roots to validate. If not specified, then permission
validation will not be performed.strategy
- how to treat multiple permissionsprotected PolicyResponse validateOperation(@Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy)
protected PolicyResponse validateOperation(@Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy, @Nullable OperationType operationType)
public PolicyResponse validatePermission(@Nullable ContextInfo contextInfo, @Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy)
TrackablePolicyUtils
Authentication
. If not defined, the response will be PolicyResponse.VALID
.validatePermission
in interface TrackablePolicyUtils
contextInfo
- the context containing multitenant application and catalog informationpermissionRoots
- the permission roots requestedstrategy
- how to treat multiple permissionspublic PolicyResponse validatePermission(@Nullable String[] permissionRoots, @Nullable PermissionMatchingStrategy strategy, @Nullable OperationType operationType, @Nullable ContextInfo contextInfo)
TrackablePolicyUtils
Authentication
. If neither parameter is defined, the response will be
PolicyResponse.VALID
.validatePermission
in interface TrackablePolicyUtils
permissionRoots
- the permission roots requestedoperationType
- the explicit type of operation to validatecontextInfo
- the context containing multitenant application, tenant and catalog
information. Not used in the default implementation, though custom implementations may
use this for validation purposes.protected Map<String,List<String>> expandPermissionRootsToPermissions(@NonNull @NonNull String[] permissionRoots, @Nullable OperationType operationType)
public PolicyResponse validateOwner(@Nullable Object test, @Nullable IdentityType[] identityTypes, @Nullable String ownerIdentifier)
TrackablePolicyUtils
PolicyResponse.VALID
. If the test object is provided, but no
identityTypes are provided, the response will be PolicyResponse.NOT_PERMITTED
.
Furthermore, if the identityTypes are provided, and none are of the type
IdentityType.OWNER
, then the response will be PolicyResponse.VALID
.
Otherwise, the identifier from the authenticated user (if applicable) will be compared
against the identifier of the Owned
entity for validation.validateOwner
in interface TrackablePolicyUtils
test
- The entity object to test for ownership agains the currently logged in useridentityTypes
- The type of identities requested for the policy call. Validating
ownership is only applicable against IdentityType.OWNER
.ownerIdentifier
- The identifier key to use when verifying ownership.Owned
,
Policy.ownerIdentifier()
protected PolicyResponse invalidPolicyResponse(PolicyResponse response, String reason, org.apache.commons.lang3.tuple.Pair<String,String>... details)
protected PolicyResponse invalidPolicyResponse(PolicyResponse response, String reason, @Nullable ContextInfo contextInfo)
Copyright © 2021. All rights reserved.