protected <T> void addAttributeToShadow(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, String attrName, T attrValue) throws SchemaException { ResourceAttributeContainer attrs = ShadowUtil.getAttributesContainer(shadow); ResourceAttributeDefinition attrSnDef = attrs.getDefinition().findAttributeDefinition( new ItemName(ResourceTypeUtil.getResourceNamespace(resource), attrName)); ResourceAttribute<T> attr = attrSnDef.instantiate(); attr.setRealValue(attrValue); attrs.add(attr); }
@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()); } } }
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 PrismObject<ShadowType> createShadow(PrismObject<ResourceType> resource, String uid, String name) throws SchemaException { PrismObject<ShadowType> shadow = getShadowDefinition().instantiate(); ShadowType shadowType = shadow.asObjectable(); if (name != null) { shadowType.setName(PrismTestUtil.createPolyStringType(name)); } ObjectReferenceType resourceRef = new ObjectReferenceType(); resourceRef.setOid(resource.getOid()); shadowType.setResourceRef(resourceRef); shadowType.setKind(ShadowKindType.ACCOUNT); RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource); RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT); shadowType.setObjectClass(objectClassDefinition.getTypeName()); ResourceAttributeContainer attrContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, objectClassDefinition); if (uid != null) { RefinedAttributeDefinition uidAttrDef = objectClassDefinition.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA,"uid")); ResourceAttribute<String> uidAttr = uidAttrDef.instantiate(); uidAttr.setRealValue(uid); attrContainer.add(uidAttr); } if (name != null) { RefinedAttributeDefinition nameAttrDef = objectClassDefinition.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA,"name")); ResourceAttribute<String> nameAttr = nameAttrDef.instantiate(); nameAttr.setRealValue(name); attrContainer.add(nameAttr); } return shadow; }
private ResourceAttributeContainer createResourceObject(String dn, String sn, String cn) throws SchemaException { // Account type is hardcoded now ObjectClassComplexTypeDefinition accountDefinition = resourceSchema .findObjectClassDefinition(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), OpenDJController.OBJECT_CLASS_INETORGPERSON_NAME)); // Determine identifier from the schema ResourceAttributeContainer resourceObject = accountDefinition.instantiate(ShadowType.F_ATTRIBUTES); ResourceAttributeDefinition road = accountDefinition.findAttributeDefinition( new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn")); ResourceAttribute roa = road.instantiate(); roa.setRealValue(sn); resourceObject.add(roa); road = accountDefinition.findAttributeDefinition(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn")); roa = road.instantiate(); roa.setRealValue(cn); resourceObject.add(roa); road = accountDefinition.findAttributeDefinition( new QName(ResourceTypeUtil.getResourceNamespace(resourceType), OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME)); roa = road.instantiate(); roa.setRealValue(dn); resourceObject.add(roa); return resourceObject; }
static ResourceAttributeContainer convertFromContainer(PrismContainer<?> origAttrContainer, ObjectClassComplexTypeDefinition objectClassDefinition) throws SchemaException { if (origAttrContainer == null || origAttrContainer.getValue() == null) { return null; } QName elementName = origAttrContainer.getElementName(); ResourceAttributeContainer attributesContainer = createEmptyContainer(elementName, objectClassDefinition); for (Item item: origAttrContainer.getValue().getItems()) { if (item instanceof PrismProperty) { PrismProperty<?> property = (PrismProperty)item; QName attributeName = property.getElementName(); ResourceAttributeDefinition attributeDefinition = objectClassDefinition.findAttributeDefinition(attributeName); if (attributeDefinition == null) { throw new SchemaException("No definition for attribute "+attributeName+" in object class "+objectClassDefinition); } ResourceAttribute attribute = new ResourceAttributeImpl(attributeName, attributeDefinition , property.getPrismContext()); for(PrismPropertyValue pval: property.getValues()) { attribute.add(pval.clone()); } attributesContainer.add(attribute); attribute.applyDefinition(attributeDefinition); } else { throw new SchemaException("Cannot process item of type "+item.getClass().getSimpleName()+", attributes can only be properties"); } } return attributesContainer; }
ResourceAttribute<String> attribute = attributeDefinition.instantiate(); attribute.setRealValue("uid=" + name + ",ou=people,dc=example,dc=com"); resourceObject.add(attribute); attribute = attributeDefinition.instantiate(); attribute.setRealValue(familyName); resourceObject.add(attribute); attribute = attributeDefinition.instantiate(); attribute.setRealValue(givenName + " " + familyName); resourceObject.add(attribute); attribute = attributeDefinition.instantiate(); attribute.setRealValue(givenName); resourceObject.add(attribute);
protected PrismObject<ShadowType> createAccount(PrismObject<ResourceType> resource, String name, boolean enabled) throws SchemaException { PrismObject<ShadowType> shadow = getShadowDefinition().instantiate(); ShadowType shadowType = shadow.asObjectable(); ObjectReferenceType resourceRef = new ObjectReferenceType(); resourceRef.setOid(resource.getOid()); shadowType.setResourceRef(resourceRef); RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource); RefinedObjectClassDefinition objectClassDefinition = refinedSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT); shadowType.setObjectClass(objectClassDefinition.getTypeName()); shadowType.setKind(ShadowKindType.ACCOUNT); ResourceAttributeContainer attrCont = ShadowUtil.getOrCreateAttributesContainer(shadow, objectClassDefinition); RefinedAttributeDefinition idSecondaryDef = objectClassDefinition.getSecondaryIdentifiers().iterator().next(); ResourceAttribute icfsNameAttr = idSecondaryDef.instantiate(); icfsNameAttr.setRealValue(name); attrCont.add(icfsNameAttr); ActivationType activation = new ActivationType(); shadowType.setActivation(activation); if (enabled) { activation.setAdministrativeStatus(ActivationStatusType.ENABLED); } else { activation.setAdministrativeStatus(ActivationStatusType.DISABLED); } return shadow; }
private void toAssociation(PrismObject<ShadowType> shadow, ShadowAssociationType shadowAssociationType) { shadowAssociationType.setShadowRef(new ObjectReferenceType().oid(shadow.getOid()).type(ShadowType.COMPLEX_TYPE)); // We also need to add identifiers here. Otherwise the delta won't match the shadow association. // And therefore new values won't be computed correctly (MID-4948) // This is not a clean systemic solution. But there was no time for a better solution before 3.9 release. try { ResourceAttributeContainer shadowAttributesContainer = ShadowUtil.getAttributesContainer(shadow); ResourceAttributeContainer identifiersContainer = ObjectFactory.createResourceAttributeContainer( ShadowAssociationType.F_IDENTIFIERS, shadowAttributesContainer.getDefinition(), prismContext); shadowAssociationType.asPrismContainerValue().add(identifiersContainer); Collection<ResourceAttribute<?>> shadowIdentifiers = ShadowUtil.getAllIdentifiers(shadow); for (ResourceAttribute<?> shadowIdentifier : shadowIdentifiers) { identifiersContainer.add(shadowIdentifier.clone()); } } catch (SchemaException e) { // Should not happen throw new SystemException(e.getMessage(), e); } }
ShadowAssociationType.F_IDENTIFIERS, entitlementDef.toResourceAttributeContainerDefinition(), prismContext); associationCVal.add(identifiersContainer); identifiersContainer.add(valueAttribute); LOGGER.trace("Assocciation attribute value resolved to valueAtrribute {} and identifiers container {}", valueAttribute, identifiersContainer);
Collection<ResourceAttribute<?>> primaryIdentifiers = attributesContainer.getPrimaryIdentifiers(); for (PrismProperty<?> p : primaryIdentifiers) { repoAttributesContainer.add(p.clone()); repoAttributesContainer.add(p.clone()); ResourceAttribute<Object> valueAttribute = attributesContainer.findAttribute(valueAttributeName); if (valueAttribute != null) { repoAttributesContainer.add(valueAttribute.clone());