private void relationToMap(Map<String, Integer> map, ObjectReferenceType ref) { if (ref != null) { String relation = null; if (ref.getRelation() != null) { relation = ref.getRelation().getLocalPart(); } Integer i = map.get(relation); if (i == null) { i = 0; } i++; map.put(relation, i); } }
@Override public QName getRelation() { ObjectReferenceType targetRef = getTargetRef(); return targetRef != null ? targetRef.getRelation() : null; }
@NotNull public static Collection<PrismReferenceValue> getDelegatorReferences(@NotNull UserType user, @NotNull RelationRegistry relationRegistry) { return user.getDelegatedRef().stream() .filter(ref -> relationRegistry.isDelegation(ref.getRelation())) .map(ref -> ref.asReferenceValue().clone()) .collect(Collectors.toList()); }
private boolean referenceMatches(ObjectReferenceType ref, String targetOid, QName relation) { if (targetOid != null && !targetOid.equals(ref.getOid())) { return false; } if (relation != null && !QNameUtil.match(relation, ref.getRelation())) { return false; } return true; }
@Override public boolean isManager(UserType user) { for (ObjectReferenceType objectReferenceType : user.getParentOrgRef()) { if (relationRegistry.isManager(objectReferenceType.getRelation())) { return true; } } return false; }
private boolean isDeputyDelegation(AssignmentType assignmentType) { ObjectReferenceType targetRef = assignmentType.getTargetRef(); return targetRef != null && relationRegistry.isDelegation(targetRef.getRelation()); }
@Override public QName getNormalizedRelation(RelationRegistry relationRegistry) { ObjectReferenceType targetRef = getTargetRef(); return targetRef != null ? relationRegistry.normalizeRelation(targetRef.getRelation()) : null; }
public static void normalizeRelation(ObjectReferenceType reference, RelationRegistry relationRegistry) { if (reference != null) { reference.setRelation(relationRegistry.normalizeRelation(reference.getRelation())); } }
@Nullable private QName getRelation(AssignmentType assignmentType) { return assignmentType.getTargetRef() != null ? relationRegistry.normalizeRelation(assignmentType.getTargetRef().getRelation()) : null; }
public List<PrismObject<RoleType>> resolveRoles(Collection<AssignmentType> assignments, Collection<String> filterOids) { Collection<AssignmentType> toResolve = assignments; if (CollectionUtils.isNotEmpty(filterOids) && CollectionUtils.isNotEmpty(assignments)) { toResolve = assignments.stream().filter(Objects::nonNull) .filter(as -> as.getTargetRef() != null && as.getTargetRef().getOid() != null && filterOids.contains(as.getTargetRef().getOid())) // filter to default relation only - ignores approvers etc .filter(as -> prismContext.isDefaultRelation(as.getTargetRef().getRelation())) .collect(Collectors.toList()); } return resolveRoles(toResolve); }
public static boolean isDelegationAssignment(AssignmentType assignment, @NotNull RelationRegistry relationRegistry) { return assignment != null && assignment.getTargetRef() != null && relationRegistry.isDelegation(assignment.getTargetRef().getRelation()); }
@Override public boolean isManagerOf(UserType user, String orgOid, boolean preAuthorized) { for (ObjectReferenceType objectReferenceType : user.getParentOrgRef()) { if (orgOid.equals(objectReferenceType.getOid()) && relationRegistry.isManager(objectReferenceType.getRelation())) { return true; } } return false; }
public boolean matches(ObjectReferenceType groupRef, ObjectReferenceType targetRef) { return relationRegistry.isMember(targetRef.getRelation()) && targetRef.getOid().equals(groupRef.getOid()); }
public static <O extends ObjectType> boolean hasOrg(PrismObject<O> user, String orgOid, QName relation) { for (ObjectReferenceType orgRef: user.asObjectable().getParentOrgRef()) { if (orgOid.equals(orgRef.getOid()) && getPrismContext().relationMatches(relation, orgRef.getRelation())) { return true; } } return false; }
public static boolean referenceMatches(ObjectReferenceType refPattern, ObjectReferenceType ref, PrismContext prismContext) { if (refPattern.getOid() != null && !refPattern.getOid().equals(ref.getOid())) { return false; } if (refPattern.getType() != null && !QNameUtil.match(refPattern.getType(), ref.getType())) { return false; } if (!prismContext.relationMatches(refPattern.getRelation(), ref.getRelation())) { return false; } return true; }
@Override public boolean isManagerOfOrgType(UserType user, String orgType, boolean preAuthorized) throws SchemaException { for (ObjectReferenceType objectReferenceType : user.getParentOrgRef()) { if (relationRegistry.isManager(objectReferenceType.getRelation())) { OrgType org = getOrgByOid(objectReferenceType.getOid(), preAuthorized); if (determineSubTypes(org).contains(orgType)) { return true; } } } return false; }
protected AssignmentType getUserAssignment(String userOid, String roleOid, QName relation) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException { PrismObject<UserType> user = getUser(userOid); List<AssignmentType> assignments = user.asObjectable().getAssignment(); for (AssignmentType assignment: assignments) { ObjectReferenceType targetRef = assignment.getTargetRef(); if (targetRef != null && roleOid.equals(targetRef.getOid()) && prismContext.relationMatches(relation, targetRef.getRelation())) { return assignment; } } return null; }
public static ObjectReference copyFromJAXB(ObjectReferenceType jaxb, ObjectReference repo, RelationRegistry relationRegistry) { Validate.notNull(repo, "Repo object must not be null."); Validate.notNull(jaxb, "JAXB object must not be null."); Validate.notEmpty(jaxb.getOid(), "Target oid must not be null."); repo.setType(ClassMapper.getHQLTypeForQName(jaxb.getType())); repo.setRelation(qnameToString(relationRegistry.normalizeRelation(jaxb.getRelation()))); repo.setTargetOid(jaxb.getOid()); return repo; }
public static void fromJaxb(ObjectReferenceType jaxb, REmbeddedReference repo, RelationRegistry relationRegistry) { Validate.notNull(repo, "Repo object must not be null."); Validate.notNull(jaxb, "JAXB object must not be null."); if (jaxb.getFilter() == null) { Validate.notEmpty(jaxb.getOid(), "Target oid must not be null."); } repo.setType(ClassMapper.getHQLTypeForQName(jaxb.getType())); repo.setRelation(qnameToString(relationRegistry.normalizeRelation(jaxb.getRelation()))); repo.setTargetOid(jaxb.getOid()); }
public static PrismReferenceValue objectReferenceTypeToReferenceValue(ObjectReferenceType refType, PrismContext prismContext) { if (refType == null) { return null; } PrismReferenceValue rval = prismContext.itemFactory().createReferenceValue(); rval.setOid(refType.getOid()); rval.setDescription(refType.getDescription()); rval.setFilter(refType.getFilter()); rval.setRelation(refType.getRelation()); rval.setTargetType(refType.getType()); return rval; }