Class AbstractDmnBasedPermissionHelper<T>
java.lang.Object
com.flowable.platform.service.permission.AbstractDmnBasedPermissionHelper<T>
- Type Parameters:
T
- the type of the scoped object this permission helper is implemented for (e.g. a conversation, a user or a case, etc)
- Direct Known Subclasses:
UserPermissionServiceImpl
public abstract class AbstractDmnBasedPermissionHelper<T>
extends java.lang.Object
An abstract based class for DMN based permission helpers where the evaluation of permissions is based on the execution of DMN models.
There are two possible ways to implement such a helper: based on a default and detailed DMN permission model or simply based on one only.
If based on two models, implement
getDecisionKeyDefaultPermissions()
and return the DMN key of the default permission model, otherwise return
null
instead. The idea of the default model is around execution speed where the commonly used use cases should already be covered by executing the
default model and the details should only be needed for deeper testing or not so common use cases.-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NONE_VALUE
static java.lang.String
OUTPUT_KEY_ERROR_MESSAGE
static java.lang.String
OUTPUT_KEY_ERROR_MESSAGE_CODE
static java.lang.String
OUTPUT_KEY_GROUP_NEEDED
static java.lang.String
OUTPUT_KEY_PERMISSION
-
Constructor Summary
Constructors Constructor Description AbstractDmnBasedPermissionHelper()
-
Method Summary
Modifier and Type Method Description protected abstract java.util.Map<java.lang.String,java.lang.Object>
createRuleInputForDefaultModel(java.lang.String userId, AuthorizedAction action, T scopedObject, java.util.Map<java.lang.String,java.lang.Object> detailedRuleInput, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)
IfgetDecisionKeyDefaultPermissions()
returns a non-null value, this method must be implemented in order to create the rule input data for evaluating the default permission model.protected PermissionEvaluationResult
evaluateDefaultPermissionOutput(java.lang.String userId, java.util.Collection<java.lang.String> userGroupKeys, java.lang.String userTenantId, java.lang.String tenantId, AuthorizedAction action, T scopedObject, java.util.Map<java.lang.String,java.lang.Object> detailedRuleInput, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)
Evaluates the basic permissions for a given action within the scoped object for a specific user based on the default permission DMN model.protected PermissionEvaluationResult
evaluatePermissionRuleOutput(java.lang.String userId, java.util.Collection<java.lang.String> userGroupKeys, java.lang.String userTenantId, java.util.Map<java.lang.String,java.lang.Object> outputValues, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)
Further evaluates the permission output as retrieved from executing the DMN model.protected java.util.Optional<java.lang.String>
evaluatePermissionsAndProcessResult(java.lang.String userId, java.util.Collection<java.lang.String> userGroupKeys, java.lang.String userTenantId, java.lang.String tenantId, AuthorizedAction action, T scopedObject, java.util.Map<java.lang.String,java.lang.Object> ruleInput, java.lang.String decisionModelKey, java.lang.String globalErrorMessageCode, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)
Evaluates default permissions first using the default DMN rule model and depending on the outcome, evaluates the detail DMN rule model according the provided action and decision key and finally processes the outcome accordingly resulting in an optional error message, if permissions have been denied.protected java.util.Map<java.lang.String,java.lang.Object>
executeAndLogPermissionModel(org.flowable.common.engine.impl.interceptor.CommandContext commandContext, java.lang.String decisionModelKey, java.lang.String tenantId, java.util.Map<java.lang.String,java.lang.Object> ruleInput)
Executes a DMN model based on the given input and decision model key with optional logging and returns the output as a single result.protected abstract java.lang.String
getDecisionKeyDefaultPermissions()
If the permission helper is based on a default and detail DMN permission rule mechanism, this method must return the DMN key of the default permission rule model to execute.protected java.util.List<java.lang.String>
getEmptyListOnNullValue(java.util.List<java.lang.String> list)
protected java.util.List<com.flowable.core.idm.api.PlatformGroup>
getGroups(java.lang.String userId, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)
protected abstract java.lang.String
getTenantId(T scopedObject)
protected boolean
isGroupMember(java.lang.String userId, java.util.Collection<java.lang.String> memberGroups, java.lang.String identityType, java.util.List<org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity> identityLinks)
protected boolean
isUserMemberOfGroup(java.util.List<com.flowable.core.idm.api.PlatformGroup> groups, java.lang.String groupKey)
protected boolean
isUserType(java.lang.String userId, java.lang.String identityType, java.util.List<org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity> identityLinks)
protected java.util.Optional<java.lang.String>
processErrorMessage(java.lang.String tenantId, PermissionEvaluationResult evaluationResult, java.lang.String globalErrorMessageCode, java.util.Map<java.lang.String,java.lang.Object> ruleInput)
Processes and returns the error code according the available error message or error message code within the given evaluation result.protected java.lang.String
renderErrorMessage(java.lang.String tenantId, java.lang.String errorCode, java.util.Map<java.lang.String,java.lang.Object> payload)
Creates a permission error message based on the provided error code and payload.
-
Field Details
-
NONE_VALUE
public static final java.lang.String NONE_VALUE- See Also:
- Constant Field Values
-
OUTPUT_KEY_PERMISSION
public static final java.lang.String OUTPUT_KEY_PERMISSION- See Also:
- Constant Field Values
-
OUTPUT_KEY_GROUP_NEEDED
public static final java.lang.String OUTPUT_KEY_GROUP_NEEDED- See Also:
- Constant Field Values
-
OUTPUT_KEY_ERROR_MESSAGE
public static final java.lang.String OUTPUT_KEY_ERROR_MESSAGE- See Also:
- Constant Field Values
-
OUTPUT_KEY_ERROR_MESSAGE_CODE
public static final java.lang.String OUTPUT_KEY_ERROR_MESSAGE_CODE- See Also:
- Constant Field Values
-
-
Constructor Details
-
AbstractDmnBasedPermissionHelper
public AbstractDmnBasedPermissionHelper()
-
-
Method Details
-
evaluatePermissionsAndProcessResult
protected java.util.Optional<java.lang.String> evaluatePermissionsAndProcessResult(java.lang.String userId, java.util.Collection<java.lang.String> userGroupKeys, java.lang.String userTenantId, java.lang.String tenantId, AuthorizedAction action, T scopedObject, java.util.Map<java.lang.String,java.lang.Object> ruleInput, java.lang.String decisionModelKey, java.lang.String globalErrorMessageCode, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)Evaluates default permissions first using the default DMN rule model and depending on the outcome, evaluates the detail DMN rule model according the provided action and decision key and finally processes the outcome accordingly resulting in an optional error message, if permissions have been denied.- Parameters:
userId
- the id of the user to test for permissionsuserGroupKeys
- the group keys of the user to check the permissions foruserTenantId
- the tenant id of the user to check the permissions fortenantId
- the id of the tenant that will be used for lookup of the dmn definitionaction
- the action to be testedscopedObject
- the scoped object in which context the permissions should be checkedruleInput
- the map containing the necessary input values for executing the detailed DMN rule modeldecisionModelKey
- the key of the detailed DMN decision modelglobalErrorMessageCode
- the error message code to be used for error message rendering, if permissions are denied but no detailed error message was providedcommandContext
- the command context to execute commands or request additional services and information- Returns:
- the optional error message if permissions are denied, for granted access, an Optional.empty is returned
-
processErrorMessage
protected java.util.Optional<java.lang.String> processErrorMessage(java.lang.String tenantId, PermissionEvaluationResult evaluationResult, java.lang.String globalErrorMessageCode, java.util.Map<java.lang.String,java.lang.Object> ruleInput)Processes and returns the error code according the available error message or error message code within the given evaluation result. If none is provided, the general error message will be returned instead.- Parameters:
evaluationResult
- the result from the DMN permission model evaluationglobalErrorMessageCode
- the global error message code to be used if not a specific one is providedruleInput
- the map with the input values to the DMN model- Returns:
- the error message
-
evaluateDefaultPermissionOutput
protected PermissionEvaluationResult evaluateDefaultPermissionOutput(java.lang.String userId, java.util.Collection<java.lang.String> userGroupKeys, java.lang.String userTenantId, java.lang.String tenantId, AuthorizedAction action, T scopedObject, java.util.Map<java.lang.String,java.lang.Object> detailedRuleInput, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)Evaluates the basic permissions for a given action within the scoped object for a specific user based on the default permission DMN model. The output might directly grant or deny access to the action or there is the need to test the action with the particular detailed DMN model for that action.- Parameters:
userId
- the id of the user to test for action permissionuserGroupKeys
- the group keys of the user to check the permissions foruserTenantId
- the tenant id of the user to check the permissions foraction
- the action to test privilegesscopedObject
- the optional scoped object for which the action should be checkedcommandContext
- the command context used for execution or access to further services
-
createRuleInputForDefaultModel
protected abstract java.util.Map<java.lang.String,java.lang.Object> createRuleInputForDefaultModel(java.lang.String userId, AuthorizedAction action, T scopedObject, java.util.Map<java.lang.String,java.lang.Object> detailedRuleInput, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)IfgetDecisionKeyDefaultPermissions()
returns a non-null value, this method must be implemented in order to create the rule input data for evaluating the default permission model. The easiest way is by just returning the same rule input as being used for the detailed rule model, but in some cases, the rule input data is different for the default DMN model.- Parameters:
userId
- the id of the user to test for action permissionsaction
- the action to test privilegesscopedObject
- the optional scoped object for which the action should be checkeddetailedRuleInput
- the rule input as provided and used for the detailed rule model executioncommandContext
- the command context used for execution or access to further services- Returns:
- the rule input data used for executing the default DMN permission model
-
getDecisionKeyDefaultPermissions
protected abstract java.lang.String getDecisionKeyDefaultPermissions()If the permission helper is based on a default and detail DMN permission rule mechanism, this method must return the DMN key of the default permission rule model to execute.- Returns:
- the optional key of the default DMN permission model,
null
, if none needed
-
executeAndLogPermissionModel
protected java.util.Map<java.lang.String,java.lang.Object> executeAndLogPermissionModel(org.flowable.common.engine.impl.interceptor.CommandContext commandContext, java.lang.String decisionModelKey, java.lang.String tenantId, java.util.Map<java.lang.String,java.lang.Object> ruleInput)Executes a DMN model based on the given input and decision model key with optional logging and returns the output as a single result.- Parameters:
commandContext
- the command context used to execute the DMN modeldecisionModelKey
- the key of the DMN model to be executedtenantId
- the id of the tenant used to lookup the dmn definitionruleInput
- the input values used for executing the DMN model- Returns:
- the single output result
-
evaluatePermissionRuleOutput
protected PermissionEvaluationResult evaluatePermissionRuleOutput(java.lang.String userId, java.util.Collection<java.lang.String> userGroupKeys, java.lang.String userTenantId, java.util.Map<java.lang.String,java.lang.Object> outputValues, org.flowable.common.engine.impl.interceptor.CommandContext commandContext)Further evaluates the permission output as retrieved from executing the DMN model. Depending on the output permission, it further checks whether the user is a member of a certain required group and returns the evaluated permission accordingly.- Parameters:
userId
- the id of the user to check the permissions foruserGroupKeys
- the group keys of the user to check the permissions foruserTenantId
- the tenant id of the user to check the permissions foroutputValues
- the output values as being retrieved by executing the DMN modelcommandContext
- the command context for retrieving further values- Returns:
- the final evaluated permission
-
renderErrorMessage
protected java.lang.String renderErrorMessage(java.lang.String tenantId, java.lang.String errorCode, java.util.Map<java.lang.String,java.lang.Object> payload)Creates a permission error message based on the provided error code and payload. The payload must at least contain the necessary parameters as being defined within theTemplateVariationModel
. This one uses english as the default language.- Parameters:
tenantId
- the if of the tenant that should be used when preparing the messageerrorCode
- the error code to choose the template variation forpayload
- the optional payload containing the necessary parameters (if any needed by the template)- Returns:
- the rendered permission error message
-
getEmptyListOnNullValue
protected java.util.List<java.lang.String> getEmptyListOnNullValue(java.util.List<java.lang.String> list) -
isUserMemberOfGroup
protected boolean isUserMemberOfGroup(java.util.List<com.flowable.core.idm.api.PlatformGroup> groups, java.lang.String groupKey) -
getGroups
protected java.util.List<com.flowable.core.idm.api.PlatformGroup> getGroups(java.lang.String userId, org.flowable.common.engine.impl.interceptor.CommandContext commandContext) -
isUserType
protected boolean isUserType(java.lang.String userId, java.lang.String identityType, java.util.List<org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity> identityLinks) -
isGroupMember
protected boolean isGroupMember(java.lang.String userId, java.util.Collection<java.lang.String> memberGroups, java.lang.String identityType, java.util.List<org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity> identityLinks) -
getTenantId
-