T
- the type of the scoped object this permission helper is implemented for (e.g. a conversation, a user or a case, etc)public abstract class AbstractDmnBasedPermissionHelper<T> extends Object
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.Modifier and Type | Field and Description |
---|---|
static String |
NONE_VALUE |
static String |
OUTPUT_KEY_ERROR_MESSAGE |
static String |
OUTPUT_KEY_ERROR_MESSAGE_CODE |
static String |
OUTPUT_KEY_GROUP_NEEDED |
static String |
OUTPUT_KEY_PERMISSION |
Constructor and Description |
---|
AbstractDmnBasedPermissionHelper() |
Modifier and Type | Method and Description |
---|---|
protected abstract Map<String,Object> |
createRuleInputForDefaultModel(String userId,
AuthorizedAction action,
T scopedObject,
Map<String,Object> detailedRuleInput,
CommandContext commandContext)
If
getDecisionKeyDefaultPermissions() 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(String userId,
Collection<String> userGroupKeys,
String userTenantId,
String tenantId,
AuthorizedAction action,
T scopedObject,
Map<String,Object> detailedRuleInput,
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(String userId,
Collection<String> userGroupKeys,
String userTenantId,
Map<String,Object> outputValues,
CommandContext commandContext)
Further evaluates the permission output as retrieved from executing the DMN model.
|
protected Optional<String> |
evaluatePermissionsAndProcessResult(String userId,
Collection<String> userGroupKeys,
String userTenantId,
String tenantId,
AuthorizedAction action,
T scopedObject,
Map<String,Object> ruleInput,
String decisionModelKey,
String globalErrorMessageCode,
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 Map<String,Object> |
executeAndLogPermissionModel(CommandContext commandContext,
String decisionModelKey,
String tenantId,
Map<String,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 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 List<String> |
getEmptyListOnNullValue(List<String> list) |
protected List<PlatformGroup> |
getGroups(String userId,
CommandContext commandContext) |
protected abstract String |
getTenantId(T scopedObject) |
protected boolean |
isGroupMember(String userId,
Collection<String> memberGroups,
String identityType,
List<IdentityLinkEntity> identityLinks) |
protected boolean |
isUserMemberOfGroup(List<PlatformGroup> groups,
String groupKey) |
protected boolean |
isUserType(String userId,
String identityType,
List<IdentityLinkEntity> identityLinks) |
protected Optional<String> |
processErrorMessage(String tenantId,
PermissionEvaluationResult evaluationResult,
String globalErrorMessageCode,
Map<String,Object> ruleInput)
Processes and returns the error code according the available error message or error message code within the given evaluation result.
|
protected String |
renderErrorMessage(String tenantId,
String errorCode,
Map<String,Object> payload)
Creates a permission error message based on the provided error code and payload.
|
public static final String NONE_VALUE
public static final String OUTPUT_KEY_PERMISSION
public static final String OUTPUT_KEY_GROUP_NEEDED
public static final String OUTPUT_KEY_ERROR_MESSAGE
public static final String OUTPUT_KEY_ERROR_MESSAGE_CODE
protected Optional<String> evaluatePermissionsAndProcessResult(String userId, Collection<String> userGroupKeys, String userTenantId, String tenantId, AuthorizedAction action, T scopedObject, Map<String,Object> ruleInput, String decisionModelKey, String globalErrorMessageCode, CommandContext commandContext)
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 informationprotected Optional<String> processErrorMessage(String tenantId, PermissionEvaluationResult evaluationResult, String globalErrorMessageCode, Map<String,Object> ruleInput)
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 modelprotected PermissionEvaluationResult evaluateDefaultPermissionOutput(String userId, Collection<String> userGroupKeys, String userTenantId, String tenantId, AuthorizedAction action, T scopedObject, Map<String,Object> detailedRuleInput, CommandContext commandContext)
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 servicesprotected abstract Map<String,Object> createRuleInputForDefaultModel(String userId, AuthorizedAction action, T scopedObject, Map<String,Object> detailedRuleInput, CommandContext commandContext)
getDecisionKeyDefaultPermissions()
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.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 servicesprotected abstract String getDecisionKeyDefaultPermissions()
null
, if none neededprotected Map<String,Object> executeAndLogPermissionModel(CommandContext commandContext, String decisionModelKey, String tenantId, Map<String,Object> ruleInput)
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 modelprotected PermissionEvaluationResult evaluatePermissionRuleOutput(String userId, Collection<String> userGroupKeys, String userTenantId, Map<String,Object> outputValues, CommandContext commandContext)
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 valuesprotected String renderErrorMessage(String tenantId, String errorCode, Map<String,Object> payload)
TemplateVariationModel
. This one uses english as the default language.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)protected boolean isUserMemberOfGroup(List<PlatformGroup> groups, String groupKey)
protected List<PlatformGroup> getGroups(String userId, CommandContext commandContext)
protected boolean isUserType(String userId, String identityType, List<IdentityLinkEntity> identityLinks)
protected boolean isGroupMember(String userId, Collection<String> memberGroups, String identityType, List<IdentityLinkEntity> identityLinks)