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()); }
private PropertyModificationOperation convertToSimulatedActivationLockoutStatusAttribute(ProvisioningContext ctx, PropertyDelta activationDelta, ShadowType shadow, LockoutStatusType status, ActivationCapabilityType activationCapability, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { ActivationLockoutStatusCapabilityType capActStatus = getActivationLockoutStatusFromSimulatedActivation(ctx, activationCapability, shadow, result); if (capActStatus == null){ throw new SchemaException("Attempt to modify lockout on "+ctx.getResource()+" which does not have activation lockout capability"); } ResourceAttribute<?> activationAttribute = getSimulatedActivationLockoutStatusAttribute(ctx, shadow, capActStatus, result); if (activationAttribute == null){ return null; } PropertyDelta<?> lockoutAttributeDelta = null; if (status == null && activationDelta.isDelete()){ LOGGER.trace("deleting activation property."); lockoutAttributeDelta = prismContext.deltaFactory().property().createModificationDeleteProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, activationAttribute.getElementName()), activationAttribute.getDefinition(), activationAttribute.getRealValue()); } else if (status == LockoutStatusType.NORMAL) { String normalValue = getLockoutNormalValue(capActStatus); lockoutAttributeDelta = createActivationPropDelta(activationAttribute.getElementName(), activationAttribute.getDefinition(), normalValue); } else { String lockedValue = getLockoutLockedValue(capActStatus); lockoutAttributeDelta = createActivationPropDelta(activationAttribute.getElementName(), activationAttribute.getDefinition(), lockedValue); } PropertyModificationOperation attributeChange = new PropertyModificationOperation(lockoutAttributeDelta); return attributeChange; }
return new Uid((String) identifiers.iterator().next().getRealValue()); } catch (IllegalArgumentException e) { throw new SchemaException(e.getMessage(), e); String nameValue = null; for (ResourceAttribute<?> attr : identifiers) { if (objectClass.isPrimaryIdentifier(attr.getElementName())) { uidValue = ((ResourceAttribute<String>) attr).getValue().getValue(); if (objectClass.isSecondaryIdentifier(attr.getElementName())) { ResourceAttributeDefinition<?> attrDef = objectClass.findAttributeDefinition(attr.getElementName()); String frameworkAttributeName = attrDef.getFrameworkAttributeName(); if (Name.NAME.equals(frameworkAttributeName)) { nameValue = ((ResourceAttribute<String>) attr).getValue().getValue(); if (attr.getElementName().equals(SchemaConstants.ICFS_UID)) { return new Uid(((ResourceAttribute<String>) attr).getValue().getValue());
private static void shortDumpShadowIdentifiers(StringBuilder sb, PrismObject<ShadowType> shadow, Collection<ResourceAttribute<?>> identifiers) { Iterator<ResourceAttribute<?>> iterator = identifiers.iterator(); while (iterator.hasNext()) { ResourceAttribute<?> identifier = iterator.next(); sb.append(identifier.getElementName().getLocalPart()); sb.append("="); sb.append(identifier.getRealValue()); if (iterator.hasNext()) { sb.append(";"); } } }
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 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(); }
public static void setAttribute(PrismObject<ShadowType> account, QName attrName, QName typeName, PrismContext prismContext, String value) throws SchemaException { PrismContainer<Containerable> attributesContainer = account.findContainer(ShadowType.F_ATTRIBUTES); ResourceAttributeDefinition attrDef = ObjectFactory.createResourceAttributeDefinition(attrName, typeName, prismContext); ResourceAttribute attribute = attrDef.instantiate(); attribute.setRealValue(value); attributesContainer.add(attribute); }
public static boolean hasPrimaryIdentifier(Collection<? extends ResourceAttribute<?>> identifiers, ObjectClassComplexTypeDefinition objectClassDefinition) { for (ResourceAttribute identifier: identifiers) { if (objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) { return true; } } return false; }
if (namingAttribute == null || namingAttribute.isEmpty()) { throw new SchemaException("Could not determine shadow name."); return nameAttribute.getValue(String.class).getValue(); List<PrismPropertyValue<String>> possibleValues = namingAttribute.getValues(); + namingAttribute.getElementName() + ", values: {}" + possibleValues + ")");
private Attribute convertToConnIdAttribute(ResourceAttribute<?> mpAttribute, ObjectClassComplexTypeDefinition ocDef) throws SchemaException { QName midPointAttrQName = mpAttribute.getElementName(); if (midPointAttrQName.equals(SchemaConstants.ICFS_UID)) { throw new SchemaException("ICF UID explicitly specified in attributes"); } String connIdAttrName = icfNameMapper.convertAttributeNameToConnId(mpAttribute, ocDef); Set<Object> connIdAttributeValues = new HashSet<>(); for (PrismPropertyValue<?> pval: mpAttribute.getValues()) { connIdAttributeValues.add(ConnIdUtil.convertValueToIcf(pval, protector, mpAttribute.getElementName())); } try { return AttributeBuilder.build(connIdAttrName, connIdAttributeValues); } catch (IllegalArgumentException e) { throw new SchemaException(e.getMessage(), e); } }
QName attributeName = attribute.getElementName(); boolean isIdentifier = QNameUtil.matchAny(attributeName, identifiers); List<? extends PrismPropertyValue<?>> valuesToReplace; if (isIdentifier) { valuesToReplace = CloneUtil.cloneCollectionMembers(attribute.getValues()); LOGGER.trace("- updating identifier {} value of {}", attributeName, attribute.getValues()); rv.add(prismContext.deltaFor(ShadowType.class) .item(ItemPath.create(ShadowType.F_ATTRIBUTES, attributeName), attribute.getDefinition()).replace(valuesToReplace) .asItemDelta()); QNameUtil.remove(outstandingInRepo, attributeName);
public static String getSecondaryIdentifierRealValue(PrismObject<? extends ShadowType> shadow) throws SchemaException { ResourceAttribute<String> secondaryIdentifier = getSecondaryIdentifier(shadow); if (secondaryIdentifier == null) { return null; } return secondaryIdentifier.getRealValue(); }
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; }
Item existingSimulatedAttr = attributesContainer.findItem(newSimulatedAttr.getElementName()); if (!isBlank(newSimulatedAttrRealValue)) { PrismPropertyValue newSimulatedAttrValue = prismContext.itemFactory().createPropertyValue(newSimulatedAttrRealValue); if (existingSimulatedAttr == null) { newSimulatedAttr.add(newSimulatedAttrValue); attributesContainer.add(newSimulatedAttr); } else { activationRealValue = getLockoutLockedValue(capActStatus); Item existingAttribute = attributesContainer.findItem(activationSimulateAttribute.getElementName()); if (!StringUtils.isBlank(activationRealValue)) { ((ResourceAttribute) activationSimulateAttribute).addRealValue(activationRealValue); if (attributesContainer.findItem(activationSimulateAttribute.getElementName()) == null) { attributesContainer.add(activationSimulateAttribute); } else{ attributesContainer.findItem(activationSimulateAttribute.getElementName()).replace(activationSimulateAttribute.getValue());
private void assertDeprecatedProtectedAccount(String message, ResourceObjectPattern protectedPattern, String identifierValue, RefinedObjectClassDefinition rAccount) throws SchemaException { Collection<ResourceAttribute<?>> identifiers = protectedPattern.getIdentifiers(); assertNotNull("Null identifiers in "+message, identifiers); assertEquals("Wrong number identifiers in "+message, 1, identifiers.size()); ResourceAttribute<?> identifier = identifiers.iterator().next(); assertNotNull("Null identifier in "+message, identifier); assertEquals("Wrong identifier value in "+message, identifier.getRealValue(), identifierValue); // Try matching PrismObject<ShadowType> shadow = rAccount.getObjectDefinition().instantiate(); ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, rAccount); ResourceAttribute<String> confusingAttr1 = createStringAttribute(new QName("http://whatever.com","confuseMe"), "HowMuchWoodWouldWoodchuckChuckIfWoodchuckCouldChudkWood"); attributesContainer.add(confusingAttr1); ResourceAttribute<String> nameAttr = createStringAttribute(SchemaTestConstants.ICFS_NAME, identifierValue); attributesContainer.add(nameAttr); ResourceAttribute<String> confusingAttr2 = createStringAttribute(new QName("http://whatever.com","confuseMeAgain"), "WoodchuckWouldChuckNoWoodAsWoodchuckCannotChuckWood"); attributesContainer.add(confusingAttr2); assertTrue("Test attr not matched in "+message, protectedPattern.matches(shadow, null, relationRegistry)); nameAttr.setRealValue("huhulumululul"); assertFalse("Test attr nonsense was matched in "+message, protectedPattern.matches(shadow, null, relationRegistry)); }
private String getNameValue(ResourceObjectIdentification resourceObjectIdentification) throws SchemaException { Collection<? extends ResourceAttribute<?>> secondaryIdentifiers = resourceObjectIdentification.getSecondaryIdentifiers(); if (secondaryIdentifiers == null) { return null; } if (secondaryIdentifiers.size() == 1) { return (String) secondaryIdentifiers.iterator().next().getRealValue(); } else if (secondaryIdentifiers.size() > 1) { for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) { ResourceAttributeDefinition<?> definition = secondaryIdentifier.getDefinition(); if (definition != null) { if (Name.NAME.equals(definition.getFrameworkAttributeName())) { return (String) secondaryIdentifier.getRealValue(); } } } throw new SchemaException("More than one secondary indentifier in "+resourceObjectIdentification+", cannot detemine ConnId __NAME__"); } return null; }
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; }
@SuppressWarnings({ "rawtypes", "unchecked" }) private void applyAfterOperationAttributes(PrismObject<ShadowType> shadow, Collection<ResourceAttribute<?>> resourceAttributesAfterAdd) throws SchemaException { if (resourceAttributesAfterAdd == null) { return; } ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(shadow); for (ResourceAttribute attributeAfter : resourceAttributesAfterAdd) { ResourceAttribute attributeBefore = attributesContainer.findAttribute(attributeAfter.getElementName()); if (attributeBefore != null) { attributesContainer.remove(attributeBefore); } if (!attributesContainer.contains(attributeAfter)) { attributesContainer.add(attributeAfter.clone()); } } }
@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 <T> Collection<T> getNormalizedAttributeValues(ResourceAttribute<T> attribute, RefinedAttributeDefinition rAttrDef) throws SchemaException { MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(rAttrDef.getMatchingRuleQName(), rAttrDef.getTypeName()); if (matchingRule == null) { return attribute.getRealValues(); } else { Collection<T> normalizedValues = new ArrayList<>(); for (PrismPropertyValue<T> pval: attribute.getValues()) { T normalizedRealValue = matchingRule.normalize(pval.getValue()); normalizedValues.add(normalizedRealValue); } return normalizedValues; } }