private boolean isAssignmentExtensionDelta(AttributeStep attributeStep, ItemName name) { if (!(attributeStep.bean instanceof RAssignment)) { return false; } if (!AssignmentType.F_EXTENSION.equals(name)) { return false; } return true; }
@Override public void replaceDefinition(QName itemName, ItemDefinition newDefinition) { for (int i=0; i<itemDefinitions.size(); i++) { ItemDefinition itemDef = itemDefinitions.get(i); if (itemDef.getName().equals(itemName)) { if (!itemDef.getClass().isAssignableFrom(newDefinition.getClass())) { throw new IllegalArgumentException("The provided definition of class "+newDefinition.getClass().getName()+" does not match existing definition of class "+itemDef.getClass().getName()); } if (!itemDef.getName().equals(newDefinition.getName())) { newDefinition = newDefinition.clone(); ((ItemDefinitionImpl) newDefinition).setName(itemName); } // Make sure this is set, not add. set will keep correct ordering itemDefinitions.set(i, newDefinition); return; } } throw new IllegalArgumentException("The definition with name "+ itemName +" was not found in complex type "+getTypeName()); }
@Override public Collection<ResourceAttribute<?>> extractAttributesByDefinitions( Collection<? extends ResourceAttributeDefinition> definitions) { Collection<ResourceAttribute<?>> attributes = new ArrayList<>(definitions.size()); for (ResourceAttributeDefinition attrDef : definitions) { for (ResourceAttribute<?> property : getAttributes()){ if (attrDef.getName().equals(property.getElementName())){ property.setDefinition(attrDef); attributes.add(property); } } } return attributes; }
private void convertFromPassword(PropertyDelta<ProtectedStringType> passwordDelta) throws SchemaException { if (passwordDelta == null) { throw new IllegalArgumentException("No password was provided"); } QName elementName = passwordDelta.getElementName(); if (StringUtils.isBlank(elementName.getNamespaceURI())) { if (!QNameUtil.match(elementName, PasswordType.F_VALUE)) { return; } } else if (!passwordDelta.getElementName().equals(PasswordType.F_VALUE)) { return; } collectPassword(passwordDelta); }
@Override public ValuePolicyType resolve() { if (!outputDefinition.getName().equals(PasswordType.F_VALUE)) { return null; } ValuePolicyType passwordPolicy = credentialsProcessor.determinePasswordPolicy(context.getFocusContext(), task, result); if (passwordPolicy == null) { return null; } return passwordPolicy; } };
private List<OrderConstraintsType> deterimneOrderConstraints(QName assignmentElementQName, AssignmentType changedAssignment) { OrderConstraintsType orderConstraints = new OrderConstraintsType(); if (FocusType.F_ASSIGNMENT.equals(assignmentElementQName)) { orderConstraints.setOrder(0); } else { List<OrderConstraintsType> assignmentOrderConstraints = changedAssignment.getOrderConstraint(); if (!assignmentOrderConstraints.isEmpty()) { return assignmentOrderConstraints; } Integer assignmentOrder = changedAssignment.getOrder(); if (assignmentOrder == null) { orderConstraints.setOrder(1); } else { orderConstraints.setOrder(assignmentOrder); } } List<OrderConstraintsType> orderConstraintsList = new ArrayList<>(1); orderConstraintsList.add(orderConstraints); return orderConstraintsList; }
private boolean hasAllIdentifiers(Collection<? extends ResourceAttribute<?>> attributes, RefinedObjectClassDefinition objectClassDefinition) { Collection<? extends RefinedAttributeDefinition> identifierDefs = objectClassDefinition.getPrimaryIdentifiers(); for (RefinedAttributeDefinition identifierDef: identifierDefs) { boolean found = false; for(ResourceAttribute<?> attribute: attributes) { if (attribute.getElementName().equals(identifierDef.getName()) && !attribute.isEmpty()) { found = true; } } if (!found) { return false; } } return true; }
private ResourceAttributeDefinition getUidDefinition(ResourceObjectIdentification identification) throws SchemaException { ResourceAttribute<String> primaryIdentifier = identification.getPrimaryIdentifier(); if (primaryIdentifier == null) { // fallback, compatibility for (ResourceAttribute<?> attr : identification.getAllIdentifiers()) { if (attr.getElementName().equals(SchemaConstants.ICFS_UID)) { return attr.getDefinition(); } } return null; } return primaryIdentifier.getDefinition(); }
private ResourceAttributeDefinition getNameDefinition(ResourceObjectIdentification identification) throws SchemaException { ResourceAttribute<String> secondaryIdentifier = identification.getSecondaryIdentifier(); if (secondaryIdentifier == null) { // fallback, compatibility for (ResourceAttribute<?> attr : identification.getAllIdentifiers()) { if (attr.getElementName().equals(SchemaConstants.ICFS_NAME)) { return attr.getDefinition(); } } return null; } return secondaryIdentifier.getDefinition(); }
private boolean isSideEffectDelta(ItemDelta<?, ?> modification) { if (modification.getPath().containsNameExactly(ObjectType.F_METADATA) || (modification.getPath().containsNameExactly(FocusType.F_ASSIGNMENT) && modification.getPath().containsNameExactly(ActivationType.F_EFFECTIVE_STATUS))) { return true; } else if (modification.getPath().containsNameExactly(FocusType.F_ASSIGNMENT) && modification.getPath().containsNameExactly(AssignmentType.F_ACTIVATION) && modification.isReplace() && (modification instanceof ContainerDelta<?>)) { Collection<PrismContainerValue<ActivationType>> valuesToReplace = ((ContainerDelta<ActivationType>)modification).getValuesToReplace(); if (valuesToReplace != null && valuesToReplace.size() == 1) { PrismContainerValue<ActivationType> cval = valuesToReplace.iterator().next(); if (cval.getItems().size() == 1) { Item<?, ?> item = cval.getItems().iterator().next(); if (ActivationType.F_EFFECTIVE_STATUS.equals(item.getElementName())) { return true; } } } } return false; }
private void replaceNameValue(ResourceObjectIdentification identification, Name newName) throws SchemaException { ResourceAttribute<String> secondaryIdentifier = identification.getSecondaryIdentifier(); if (secondaryIdentifier == null) { // fallback, compatibility for (ResourceAttribute<?> attr : identification.getAllIdentifiers()) { if (attr.getElementName().equals(SchemaConstants.ICFS_NAME)) { // expecting the NAME property is of type String //noinspection unchecked ((ResourceAttribute<String>) attr).setRealValue(newName.getNameValue()); return; } } throw new IllegalStateException("No identifiers"); } secondaryIdentifier.setRealValue(newName.getNameValue()); }
public static boolean compareCollectionRealValues(Collection<? extends PrismProperty> col1, Collection<? extends PrismProperty> col2) { return MiscUtil.unorderedCollectionEquals(col1, col2, (p1, p2) -> { if (!p1.getElementName().equals(p2.getElementName())) { return false; } Collection p1RealVals = p1.getRealValues(); Collection p2RealVals = p2.getRealValues(); return MiscUtil.unorderedCollectionEquals(p1RealVals, p2RealVals); }); } }
private void replaceUidValue(ResourceObjectIdentification identification, Uid newUid) throws SchemaException { ResourceAttribute<String> primaryIdentifier = identification.getPrimaryIdentifier(); if (primaryIdentifier == null) { // fallback, compatibility Collection<? extends ResourceAttribute<?>> identifiers = identification.getAllIdentifiers(); for (ResourceAttribute<?> attr : identifiers) { if (attr.getElementName().equals(SchemaConstants.ICFS_UID)) { // expecting the UID property is of type String //noinspection unchecked ((ResourceAttribute<String>) attr).setRealValue(newUid.getUidValue()); return; } } throw new IllegalStateException("No UID attribute in " + identifiers); } primaryIdentifier.setRealValue(newUid.getUidValue()); }
private String getEntryUuid(Collection<ResourceAttribute<?>> identifiers) { for (ResourceAttribute<?> identifier : identifiers) { if (identifier.getElementName().equals(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), OpenDJController.RESOURCE_OPENDJ_PRIMARY_IDENTIFIER_LOCAL_NAME))) { return identifier.getValue(String.class).getValue(); } } return null; }
private <V extends PrismValue, D extends ItemDefinition> void applyItemDefinition(ItemDelta<V,D> itemDelta, PrismContainerDefinition<ConnectorConfigurationType> configContainerDef, OperationResult objectResult) throws SchemaException { if (itemDelta.getParentPath() == null){ LOGGER.trace("No parent path defined for item delta {}", itemDelta); return; } QName first = itemDelta.getParentPath().firstToNameOrNull(); if (first == null) { return; } if (itemDelta.getDefinition() == null && (ResourceType.F_CONNECTOR_CONFIGURATION.equals(first) || ResourceType.F_SCHEMA.equals(first))){ ItemPath path = itemDelta.getPath().rest(); D itemDef = configContainerDef.findItemDefinition(path); if (itemDef == null){ LOGGER.warn("No definition found for item {}. Check your namespaces?", path); objectResult.recordWarning("No definition found for item delta: " + itemDelta +". Check your namespaces?" ); // throw new SchemaException("No definition found for item " + path+ ". Check your namespaces?" ); return; } itemDelta.applyDefinition(itemDef); } }
@Override public RAssignmentReference map(Referencable input, MapperContext context) { ObjectReferenceType objectRef = buildReference(input); ObjectTypeUtil.normalizeRelation(objectRef, context.getRelationRegistry()); RAssignment owner = (RAssignment) context.getOwner(); QName name = context.getDelta().getPath().lastName().asSingleName(); RCReferenceOwner refType = null; if (MetadataType.F_CREATE_APPROVER_REF.equals(name)) { refType = RCReferenceOwner.CREATE_APPROVER; } else if (MetadataType.F_MODIFY_APPROVER_REF.equals(name)) { refType = RCReferenceOwner.MODIFY_APPROVER; } RAssignmentReference ref = new RAssignmentReference(); ref.setOwner(owner); ref.setReferenceType(refType); RObjectReference.copyFromJAXB(objectRef, ref, context.getRelationRegistry()); return ref; } }
private boolean matches(ResourceAttribute<?> identifier, ResourceAttribute<?> attributeToMatch, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException { if (!identifier.getElementName().equals(attributeToMatch.getElementName())) { return false; } RefinedAttributeDefinition rAttrDef = rOcDef.findAttributeDefinition(identifier.getElementName()); QName matchingRuleQName = rAttrDef.getMatchingRuleQName(); if (matchingRuleQName == null || matchingRuleRegistry == null) { return identifier.equals(attributeToMatch, EquivalenceStrategy.REAL_VALUE); } MatchingRule<Object> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName()); return matchingRule.match(identifier.getRealValue(), attributeToMatch.getRealValue()); }
private String checkRepoShadow(PrismObject<ShadowType> repoShadow) { ShadowType repoShadowType = repoShadow.asObjectable(); String uid = null; boolean hasOthers = false; List<Object> xmlAttributes = repoShadowType.getAttributes().getAny(); for (Object element : xmlAttributes) { if (SchemaConstants.ICFS_UID.equals(JAXBUtil.getElementQName(element)) || getOpenDjPrimaryIdentifierQName().equals(JAXBUtil.getElementQName(element))) { if (uid != null) { AssertJUnit.fail("Multiple values for ICF UID in shadow attributes"); } else { uid = ((Element) element).getTextContent(); } } else if (SchemaConstants.ICFS_NAME.equals(JAXBUtil.getElementQName(element)) || getOpenDjSecondaryIdentifierQName().equals(JAXBUtil.getElementQName(element))) { // This is OK } else { hasOthers = true; } } assertFalse("Shadow "+repoShadow+" has unexpected elements", hasOthers); assertNotNull(uid); return uid; }
private void changeDefinition(QName piracyShip, QName piracyShipBroken) { PrismObjectDefinition<UserType> userDef = prismContext.getSchemaRegistry() .findObjectDefinitionByCompileTimeClass(UserType.class); PrismContainerDefinition<?> extensionDefinition = userDef.getExtensionDefinition(); List<? extends ItemDefinition> extensionDefs = extensionDefinition.getComplexTypeDefinition().getDefinitions(); for (ItemDefinition itemDefinition : extensionDefs) { if (itemDefinition.getName().equals(piracyShip)) { //iterator.remove(); // not possible as the collection is unmodifiable itemDefinition.toMutable().setName(piracyShipBroken); } } }
private void assertAttributeDef(Collection<? extends RefinedAttributeDefinition> attrDefs, QName name, QName typeName, int minOccurs, int maxOccurs, String displayName, Integer displayOrder, boolean hasOutbound, boolean ignore, boolean canCreate, boolean canRead, boolean canUpdate, LayerType sourceLayer, LayerType validationLayer) { for (RefinedAttributeDefinition def : attrDefs) { if (def.getName().equals(name)) { assertEquals("Attribute " + name + " ("+sourceLayer+") type mismatch", typeName, def.getTypeName()); assertEquals("Attribute " + name + " ("+sourceLayer+") minOccurs mismatch", minOccurs, def.getMinOccurs()); assertEquals("Attribute " + name + " ("+sourceLayer+") maxOccurs mismatch", maxOccurs, def.getMaxOccurs()); if (validationLayer == LayerType.MODEL || validationLayer == LayerType.PRESENTATION) { assertEquals("Attribute " + name + " ("+sourceLayer+") displayName mismatch", displayName, def.getDisplayName()); assertEquals("Attribute " + name + " ("+sourceLayer+") displayOrder mismatch", displayOrder, def.getDisplayOrder()); assertEquals("Attribute " + name + " ("+sourceLayer+") outbound mismatch", hasOutbound, def.getOutboundMappingType() != null); } assertEquals("Attribute " + name + " ("+sourceLayer+") ignored flag mismatch", ignore, def.isIgnored()); assertEquals("Attribute " + name + " ("+sourceLayer+") canCreate mismatch", canCreate, def.canAdd()); assertEquals("Attribute " + name + " ("+sourceLayer+") canRead mismatch", canRead, def.canRead()); assertEquals("Attribute " + name + " ("+sourceLayer+") canUpdate mismatch", canUpdate, def.canModify()); return; } } Assert.fail("Attribute " + name + " not found"); }