public boolean hasPermission(String permissionName, String actionName) { Permission permission = Permission.valueOf(permissionName); Action action = Action.valueOf(actionName); return permissionService.hasPermission(permission, action); }
public boolean hasPermissionOnAllContext(String permissionName, String actionName) { Permission permission = Permission.valueOf(permissionName); Action action = Action.valueOf(actionName); return permissionService.hasPermissionOnAllContext(permission, action, null, null); }
public boolean hasPermissionForResourceType(String permissionName, String actionName, String resourceTypeName) { Permission permission = Permission.valueOf(permissionName); Action action = Action.valueOf(actionName); final ResourceTypeEntity resourceType = resourceTypeRepository.getByName(resourceTypeName); return resourceType != null && permissionService.hasPermission(permission, action, resourceType); }
public boolean hasPermissionForResourceType(String permissionName, String actionName, String resourceTypeName, Integer contextId) { Permission permission = Permission.valueOf(permissionName); Action action = Action.valueOf(actionName); final ResourceTypeEntity resourceType = resourceTypeRepository.getByName(resourceTypeName); final ContextEntity context = contextLocator.getContextById(contextId); return resourceType != null && permissionService.hasPermission(permission, context, action, null, resourceType); }
/** * Checks if a Restriction gives permission for a specific Action * * @param restriction * @param action */ private boolean hasPermissionForAction(RestrictionEntity restriction, Action action) { return action == null || restriction.getAction().equals(action) || restriction.getAction().equals(ALL); }
private static List<Action> getRequiredAction(InvocationContext context) { HasPermission permissionMethodAnnotation = getMethodPermissionAnnotation(context); List<Action> actions = new ArrayList<>(); if (permissionMethodAnnotation != null) { if (!permissionMethodAnnotation.action().equals(Action.NULL)) { actions.add(permissionMethodAnnotation.action()); } if (permissionMethodAnnotation.oneOfAction().length > 0) { Collections.addAll(actions, permissionMethodAnnotation.oneOfAction()); } } return actions; }
/** * Checks if the caller is allowed to edit Deployments */ public boolean hasPermissionToEditDeployment() { for (Map.Entry<String, List<RestrictionDTO>> entry : getDeployableRoles().entrySet()) { if (sessionContext.isCallerInRole(entry.getKey())) { for (RestrictionDTO restrictionDTO : entry.getValue()) { if (restrictionDTO.getRestriction().getAction().equals(Action.UPDATE) || restrictionDTO.getRestriction().getAction().equals(Action.ALL)) { return true; } } } } return hasUserRestriction(Permission.DEPLOYMENT.name(), null, Action.UPDATE, null, null); }
/** * Checks if the caller is allowed to create (re-)Deployments */ public boolean hasPermissionToCreateDeployment() { for (Map.Entry<String, List<RestrictionDTO>> entry : getDeployableRoles().entrySet()) { if (sessionContext.isCallerInRole(entry.getKey())) { for (RestrictionDTO restrictionDTO : entry.getValue()) { if (restrictionDTO.getRestriction().getAction().equals(Action.CREATE) || restrictionDTO.getRestriction().getAction().equals(Action.ALL)) { return true; } } } } return hasUserRestriction(Permission.DEPLOYMENT.name(), null, Action.CREATE, null, null); }
/** * Checks if restrictionEntityOne is more specific (grants less rights) than restrictionEntityTwo * * @param restrictionEntityOne * @param restrictionEntityTwo */ private boolean isMoreSpecificRestriction(RestrictionEntity restrictionEntityOne, RestrictionEntity restrictionEntityTwo) { // allow update of existing - do not compare with itself if (restrictionEntityOne.getId() != null && restrictionEntityOne.getId().equals(restrictionEntityTwo.getId())) { return false; } if (restrictionEntityOne.getAction().equals(Action.ALL) && !restrictionEntityTwo.getAction().equals(Action.ALL)) { return false; } if (restrictionEntityOne.getResourceGroup() == null && restrictionEntityTwo.getResourceGroup() != null) { return false; } if (restrictionEntityOne.getResourceType() == null && restrictionEntityTwo.getResourceType() != null) { return false; } if (restrictionEntityOne.getResourceTypePermission().equals(ResourceTypePermission.ANY) && !restrictionEntityTwo.getResourceTypePermission().equals(ResourceTypePermission.ANY)) { return false; } return true; }