protected boolean isUserPrivilege(String privilegeId, String userId) { User user = identityService.createUserQuery().userId(userId).singleResult(); if (user == null) { throw new IllegalArgumentException("Invalid user id"); } return identityService.createPrivilegeQuery().privilegeId(privilegeId).userId(userId).count() > 0; }
protected boolean isGroupPrivilege(String privilegeId, String groupId) { Group group = identityService.createGroupQuery().groupId(groupId).singleResult(); if (group == null) { throw new IllegalArgumentException("Invalid group id"); } return identityService.createPrivilegeQuery().privilegeId(privilegeId).groupId(groupId).count() > 0; }
@Override public Privilege execute(CommandContext commandContext) { long count = CommandContextUtil.getPrivilegeEntityManager(commandContext).createNewPrivilegeQuery().privilegeName(name).count(); if (count > 0) { throw new FlowableIllegalArgumentException("Provided privilege name already exists"); } PrivilegeEntity entity = CommandContextUtil.getPrivilegeEntityManager(commandContext).create(); entity.setName(name); CommandContextUtil.getPrivilegeEntityManager(commandContext).insert(entity); return entity; } }