public ShadowType kind(ShadowKindType value) { setKind(value); return this; }
public void setKindIfNecessary(ShadowType repoShadowType, RefinedObjectClassDefinition objectClassDefinition) { if (repoShadowType.getKind() == null && objectClassDefinition != null) { repoShadowType.setKind(objectClassDefinition.getKind()); } }
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; }
@Override public PrismObjectDefinition<ShadowType> getEditShadowDefinition(ResourceShadowDiscriminator discr, AuthorizationPhaseType phase, Task task, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, SecurityViolationException { // HACK hack hack // Make a dummy shadow instance here and evaluate the schema for that. It is not 100% correct. But good enough for now. // TODO: refactor when we add better support for multi-tenancy PrismObject<ShadowType> shadow = prismContext.createObject(ShadowType.class); ShadowType shadowType = shadow.asObjectable(); ObjectReferenceType resourceRef = new ObjectReferenceType(); if (discr != null) { resourceRef.setOid(discr.getResourceOid()); shadowType.setResourceRef(resourceRef); shadowType.setKind(discr.getKind()); shadowType.setIntent(discr.getIntent()); shadowType.setObjectClass(discr.getObjectClass()); } return getEditObjectDefinition(shadow, phase, task, parentResult); }
private ShadowType createShadow(UserType user, String resourceOid, int resourceId) throws SchemaException { ShadowType shadow = new ShadowType(); shadow.setOid(UUID.randomUUID().toString()); final String DN = "cn=" + user.getName().getOrig() + ",ou=resource" + resourceId + ",dc=example,dc=com"; shadow.setName(createPoly(DN)); shadow.setResourceRef(createRef(resourceOid, ResourceType.COMPLEX_TYPE)); shadow.setKind(ShadowKindType.ACCOUNT); shadow.setIntent("standardAccount"); shadow.setObjectClass(new QName("http://midpoint.evolveum.com/xml/ns/public/resource/instance/" + resourceOid, "AccountObjectClass")); PrismObject<ShadowType> prism = shadow.asPrismObject(); prismContext.adopt(prism); PrismContainer attributes = prism.findOrCreateContainer(ShadowType.F_ATTRIBUTES); PrismProperty property = attributes.findOrCreateProperty(SchemaConstants.ICFS_UID); property.setRealValue(UUID.randomUUID().toString()); property = attributes.findOrCreateProperty(SchemaConstants.ICFS_NAME); property.setRealValue(DN); return shadow; }
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; }
@Test public void test210AddAccountNoObjectclass() throws Exception { TestUtil.displayTestTitle("test210AddAccountNoObjectclass"); // GIVEN Task task = taskManager.createTaskInstance(TestDummyNegative.class.getName() + ".test210AddAccountNoObjectclass"); OperationResult result = new OperationResult(TestDummyNegative.class.getName() + ".test210AddAccountNoObjectclass"); syncServiceMock.reset(); ShadowType accountType = parseObjectType(ACCOUNT_WILL_FILE, ShadowType.class); PrismObject<ShadowType> account = accountType.asPrismObject(); account.checkConsistence(); // IMPORTANT: deliberately violating the schema accountType.setObjectClass(null); accountType.setKind(null); display("Adding shadow", account); try { // WHEN provisioningService.addObject(account, null, null, task, result); AssertJUnit.fail("The addObject operation was successful. But expecting an exception."); } catch (SchemaException e) { // This is expected display("Expected exception", e); } syncServiceMock.assertNotifyFailureOnly(); }
resourceShadow.asObjectable().setKind(repositoryShadow.asObjectable().getKind()); resourceShadow.asObjectable().setIntent(repositoryShadow.asObjectable().getIntent()); ProvisioningContext shadowCtx = ctx.spawn(resourceShadow);
conflictingShadow.asObjectable().setKind(newShadow.asObjectable().getKind());