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 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()); }
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 Collection<ResourceAttribute<?>> convertToIdentifiers(Uid uid, ObjectClassComplexTypeDefinition ocDef, ResourceSchema resourceSchema) throws SchemaException { ObjectClassComplexTypeDefinition concreteObjectClassDefinition = getConcreteObjectClassDefinition(ocDef, resourceSchema); if (concreteObjectClassDefinition == null) { throw new SchemaException("Concrete object class of "+ocDef+" cannot be found"); } ResourceAttributeDefinition<String> uidDefinition = getUidDefinition(concreteObjectClassDefinition); if (uidDefinition == null) { throw new SchemaException("No definition for ConnId UID attribute found in definition " + ocDef); } Collection<ResourceAttribute<?>> identifiers = new ArrayList<>(2); ResourceAttribute<String> uidRoa = uidDefinition.instantiate(); uidRoa.setRealValue(uid.getUidValue()); identifiers.add(uidRoa); if (uid.getNameHint() != null) { ResourceAttributeDefinition<String> nameDefinition = getNameDefinition(concreteObjectClassDefinition); if (nameDefinition == null) { throw new SchemaException("No definition for ConnId NAME attribute found in definition " + ocDef); } ResourceAttribute<String> nameRoa = nameDefinition.instantiate(); nameRoa.setRealValue(uid.getNameHintValue()); identifiers.add(nameRoa); } return identifiers; }
private PrismProperty createProperty(String propertyName, String propertyValue) { ObjectClassComplexTypeDefinition accountDefinition = resourceSchema.findObjectClassDefinition( new QName(ResourceTypeUtil.getResourceNamespace(resourceType), OpenDJController.OBJECT_CLASS_INETORGPERSON_NAME)); ResourceAttributeDefinition propertyDef = accountDefinition.findAttributeDefinition(new QName( ResourceTypeUtil.getResourceNamespace(resourceType), propertyName)); ResourceAttribute property = propertyDef.instantiate(); property.setRealValue(propertyValue); return property; }
private ResourceAttribute<String> createStringAttribute(QName attrName, String value) { ResourceAttributeDefinition testAttrDef = new ResourceAttributeDefinitionImpl(attrName, DOMUtil.XSD_STRING, getPrismContext()); ResourceAttribute<String> testAttr = testAttrDef.instantiate(); testAttr.setRealValue(value); return testAttr; }
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); }
private <T> void setAttribute(PrismObject<ShadowType> account, String attrName, T val) throws SchemaException { PrismContainer<Containerable> attrsCont = account.findContainer(ShadowType.F_ATTRIBUTES); ResourceAttribute<T> attr = ObjectFactory.createResourceAttribute( dummyResourceCtl.getAttributeQName(attrName), null, prismContext); attr.setRealValue(val); attrsCont.add(attr); }
attr.setRealValue(patternType.getName()); resourceObjectPattern.addIdentifier(attr); } else if (patternType.getUid() != null) { attr.setRealValue(patternType.getUid()); resourceObjectPattern.addIdentifier(attr); } else {
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; }
primaryIdentifier.setRealValue(property.getRealValue()); primaryIdentifiers.add(primaryIdentifier);
.findAttributeDefinition(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), OpenDJController.RESOURCE_OPENDJ_SECONDARY_IDENTIFIER_LOCAL_NAME)); ResourceAttribute<String> attribute = attributeDefinition.instantiate(); attribute.setRealValue("uid=" + name + ",ou=people,dc=example,dc=com"); resourceObject.add(attribute); .findAttributeDefinition(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn")); attribute = attributeDefinition.instantiate(); attribute.setRealValue(familyName); resourceObject.add(attribute); .findAttributeDefinition(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "cn")); attribute = attributeDefinition.instantiate(); attribute.setRealValue(givenName + " " + familyName); resourceObject.add(attribute); "givenName")); attribute = attributeDefinition.instantiate(); attribute.setRealValue(givenName); resourceObject.add(attribute);
primaryIdentifier.setRealValue(property.getRealValue()); primaryIdentifiers.add(primaryIdentifier);
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 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)); }
@Test public void test040AddAccount() throws Exception { final String TEST_NAME = "test040AddAccount"; TestUtil.displayTestTitle(this, TEST_NAME); OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME); ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); ShadowType shadowType = new ShadowType(); PrismTestUtil.getPrismContext().adopt(shadowType); shadowType.setName(PrismTestUtil.createPolyStringType(ACCOUNT_JACK_USERNAME)); ObjectReferenceType resourceRef = new ObjectReferenceType(); resourceRef.setOid(resource.getOid()); shadowType.setResourceRef(resourceRef); shadowType.setObjectClass(defaultAccountDefinition.getTypeName()); PrismObject<ShadowType> shadow = shadowType.asPrismObject(); ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, defaultAccountDefinition); ResourceAttribute<String> icfsNameProp = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME); icfsNameProp.setRealValue(ACCOUNT_JACK_USERNAME); // WHEN cc.addObject(shadow, null, null, result); // THEN DummyAccount dummyAccount = dummyResource.getAccountByUsername(ACCOUNT_JACK_USERNAME); assertNotNull("Account "+ACCOUNT_JACK_USERNAME+" was not created", dummyAccount); assertNotNull("Account "+ACCOUNT_JACK_USERNAME+" has no username", dummyAccount.getName()); }
@Test public void test100AddAccount() throws Exception { final String TEST_NAME = "test100AddAccount"; TestUtil.displayTestTitle(this, TEST_NAME); OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME); ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); ShadowType shadowType = new ShadowType(); PrismTestUtil.getPrismContext().adopt(shadowType); shadowType.setName(PrismTestUtil.createPolyStringType(ACCOUNT_JACK_USERNAME)); ObjectReferenceType resourceRef = new ObjectReferenceType(); resourceRef.setOid(resource.getOid()); shadowType.setResourceRef(resourceRef); shadowType.setObjectClass(defaultAccountDefinition.getTypeName()); PrismObject<ShadowType> shadow = shadowType.asPrismObject(); ResourceAttributeContainer attributesContainer = ShadowUtil.getOrCreateAttributesContainer(shadow, defaultAccountDefinition); ResourceAttribute<String> icfsNameProp = attributesContainer.findOrCreateAttribute(SchemaConstants.ICFS_NAME); icfsNameProp.setRealValue(ACCOUNT_JACK_USERNAME); // WHEN cc.addObject(shadow, null, null, result); // THEN DummyAccount dummyAccount = dummyResource.getAccountByUsername(ACCOUNT_JACK_USERNAME); assertNotNull("Account "+ACCOUNT_JACK_USERNAME+" was not created", dummyAccount); assertNotNull("Account "+ACCOUNT_JACK_USERNAME+" has no username", dummyAccount.getName()); }
uidRoa.setRealValue(uid.getUidValue()); attributesContainer.getValue().add(uidRoa);