public static String getSecondaryIdentifierRealValue(PrismObject<? extends ShadowType> shadow) throws SchemaException { ResourceAttribute<String> secondaryIdentifier = getSecondaryIdentifier(shadow); if (secondaryIdentifier == null) { return null; } return secondaryIdentifier.getRealValue(); }
public static String getSecondaryIdentifier(PrismObject<ShadowType> shadow) { Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(shadow); if (secondaryIdentifiers == null || secondaryIdentifiers.isEmpty()) { return null; } if (secondaryIdentifiers.size() > 1) { throw new IllegalArgumentException("Too many secondary indentifiers in "+shadow); } return (String) secondaryIdentifiers.iterator().next().getRealValue(); }
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 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; }
public static String getHumanReadableName(PrismObject<? extends ShadowType> shadow) { if (shadow == null) { return "null"; } StringBuilder sb = new StringBuilder(); ShadowType shadowType = shadow.asObjectable(); ShadowKindType kind = shadowType.getKind(); if (kind != null) { sb.append(kind).append(" "); } sb.append("shadow "); boolean first = true; for(ResourceAttribute iattr: getPrimaryIdentifiers(shadow)) { if (first) { sb.append("["); first = false; } else { sb.append(","); } sb.append(iattr.getElementName().getLocalPart()); sb.append("="); sb.append(iattr.getRealValue()); } if (first) { sb.append("["); } sb.append("]"); return shadow.toString(); }
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 Uid getUid(ResourceObjectIdentification resourceObjectIdentification) throws SchemaException { ResourceAttribute<String> primaryIdentifier = resourceObjectIdentification.getPrimaryIdentifier(); if (primaryIdentifier == null) { return null; } String uidValue = primaryIdentifier.getRealValue(); String nameValue = getNameValue(resourceObjectIdentification); if (uidValue != null) { if (nameValue == null) { return new Uid(uidValue); } else { return new Uid(uidValue, new Name(nameValue)); } } return null; }
return new Uid((String) identifiers.iterator().next().getRealValue()); } catch (IllegalArgumentException e) { throw new SchemaException(e.getMessage(), e);
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)); }
protected void assertSyncOldShadow(PrismObject<? extends ShadowType> oldShadow, String repoName, Integer expectedNumberOfAttributes) { assertNotNull("Old shadow missing", oldShadow); assertNotNull("Old shadow does not have an OID", oldShadow.getOid()); PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow); ShadowType oldShadowType = oldShadow.asObjectable(); ResourceAttributeContainer attributesContainer = ShadowUtil .getAttributesContainer(oldShadowType); assertNotNull("No attributes container in old shadow", attributesContainer); Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes(); assertFalse("Attributes container is empty", attributes.isEmpty()); if (expectedNumberOfAttributes != null) { assertEquals("Unexpected number of attributes", (int)expectedNumberOfAttributes, attributes.size()); } ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME); assertNotNull("No ICF name attribute in old shadow", icfsNameAttribute); assertEquals("Wrong value of ICF name attribute in old shadow", repoName, icfsNameAttribute.getRealValue()); }
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; }
private PropertyModificationOperation convertToSimulatedActivationAdministrativeStatusAttribute(ProvisioningContext ctx, PropertyDelta activationDelta, ShadowType shadow, ActivationStatusType status, ActivationCapabilityType activationCapabilityType, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { ResourceType resource = ctx.getResource(); ActivationStatusCapabilityType capActStatus = getActivationAdministrativeStatusFromSimulatedActivation(ctx, activationCapabilityType, shadow, result); if (capActStatus == null){ throw new SchemaException("Attempt to modify activation on "+resource+" which does not have activation capability"); } ResourceAttribute<?> simulatedAttribute = getSimulatedActivationAdministrativeStatusAttribute(ctx, shadow, capActStatus, result); if (simulatedAttribute == null) { return null; } Class<?> simulatedAttrValueClass = getAttributeValueClass(ctx, shadow, simulatedAttribute, capActStatus); PropertyDelta<?> simulatedAttrDelta; if (status == null && activationDelta.isDelete()){ LOGGER.trace("deleting activation property."); simulatedAttrDelta = prismContext.deltaFactory().property().createModificationDeleteProperty( ItemPath.create(ShadowType.F_ATTRIBUTES, simulatedAttribute.getElementName()), simulatedAttribute.getDefinition(), simulatedAttribute.getRealValue()); } else if (status == ActivationStatusType.ENABLED) { Object enableValue = getEnableValue(capActStatus, simulatedAttrValueClass); simulatedAttrDelta = createActivationPropDelta(simulatedAttribute.getElementName(), simulatedAttribute.getDefinition(), enableValue); } else { Object disableValue = getDisableValue(capActStatus, simulatedAttrValueClass); simulatedAttrDelta = createActivationPropDelta(simulatedAttribute.getElementName(), simulatedAttribute.getDefinition(), disableValue); } PropertyModificationOperation attributeChange = new PropertyModificationOperation(simulatedAttrDelta); return attributeChange; }
shadowUuid = (String) identifier.getRealValue();
throw e; String secondaryIdentifierValue = secondaryIdentifier.getRealValue(String.class); ObjectClass baseContextIcfObjectClass = connIdNameMapper.objectClassToConnId(baseContextIdentification.getObjectClassDefinition(), getSchemaNamespace(), connectorType, legacySchema); QualifiedUid containerQualifiedUid = new QualifiedUid(baseContextIcfObjectClass, new Uid(secondaryIdentifierValue));
assertNotNull("No fullname attribute in current shadow", fullnameAttribute); assertEquals("Wrong value of fullname attribute in current shadow", "Sir Francis Drake", fullnameAttribute.getRealValue());