public static String getHumanReadableName(ShadowType shadowType) { if (shadowType == null) { return "null"; } return getHumanReadableName(shadowType.asPrismObject()); }
public static String getDisplayName(ShadowType shadow) { String objectName = PolyString.getOrig(shadow.getName()); QName oc = shadow.getObjectClass(); String ocName = oc != null ? oc.getLocalPart() : null; return objectName + " (" + shadow.getKind() + " - " + shadow.getIntent() + " - " + ocName + ")"; }
public static boolean matches(ShadowType shadowType, String resourceOid, ShadowKindType kind, String intent) { if (shadowType == null) { return false; } if (!resourceOid.equals(shadowType.getResourceRef().getOid())) { return false; } if (!MiscUtil.equals(kind, shadowType.getKind())) { return false; } if (intent == null) { return true; } return MiscUtil.equals(intent, shadowType.getIntent()); }
public ShadowType clone() { ShadowType object = new ShadowType(); PrismObject value = asPrismObject().clone(); object.setupContainer(value); return object; }
private PrismObject<ShadowType> createAccountShadow(String username) throws SchemaException { ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext); ObjectClassComplexTypeDefinition defaultAccountDefinition = resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT); ShadowType shadowType = new ShadowType(); PrismTestUtil.getPrismContext().adopt(shadowType); shadowType.setName(PrismTestUtil.createPolyStringType(username)); ObjectReferenceType resourceRef = new ObjectReferenceType(); resourceRef.setOid(resource.getOid()); shadowType.setResourceRef(resourceRef); shadowType.setObjectClass(defaultAccountDefinition.getTypeName()); PrismObject<ShadowType> shadow = shadowType.asPrismObject(); PrismContainer<Containerable> attrsCont = shadow.findOrCreateContainer(ShadowType.F_ATTRIBUTES); PrismProperty<String> icfsNameProp = attrsCont.findOrCreateProperty(SchemaConstants.ICFS_NAME); icfsNameProp.setRealValue(username); return shadow; }
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; }
public static void checkRepoShadow(PrismObject<ShadowType> repoShadow, ShadowKindType kind, Integer expectedNumberOfAttributes) { ShadowType repoShadowType = repoShadow.asObjectable(); assertNotNull("No OID in repo shadow "+repoShadow, repoShadowType.getOid()); assertNotNull("No name in repo shadow "+repoShadow, repoShadowType.getName()); assertNotNull("No objectClass in repo shadow "+repoShadow, repoShadowType.getObjectClass()); assertEquals("Wrong kind in repo shadow "+repoShadow, kind, repoShadowType.getKind()); PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES); assertNotNull("No attributes in repo shadow "+repoShadow, attributesContainer); List<Item<?,?>> attributes = attributesContainer.getValue().getItems(); assertFalse("Empty attributes in repo shadow "+repoShadow, attributes.isEmpty()); if (expectedNumberOfAttributes != null) { assertEquals("Unexpected number of attributes in repo shadow "+repoShadow, (int)expectedNumberOfAttributes, attributes.size()); } }
private void assertJaxb(ShadowType shadow, boolean isObject) throws SchemaException { if (isObject) { assertEquals("88519fca-3f4a-44ca-91c8-dc9be5bf3d03", shadow.getOid()); } assertEquals("Wrong name", PrismTestUtil.createPolyStringType("hbarbossa"), shadow.getName()); ActivationType activation = shadow.getActivation(); assertNotNull("No activation", activation); assertEquals("User not enabled", ActivationStatusType.ENABLED, activation.getAdministrativeStatus()); ObjectReferenceType resourceRef = shadow.getResourceRef(); assertNotNull("No resourceRef", resourceRef); assertEquals("Wrong resourceRef oid (jaxb)", "10000000-0000-0000-0000-000000000003", resourceRef.getOid()); assertEquals("Wrong resourceRef type (jaxb)", ResourceType.COMPLEX_TYPE, resourceRef.getType()); }
public static ObjectClassComplexTypeDefinition determineObjectClass(RefinedResourceSchema refinedSchema, PrismObject<ShadowType> shadow) throws SchemaException { ShadowType s = shadow.asObjectable(); return determineObjectClassInternal(refinedSchema, s.getObjectClass(), s.getKind(), s.getIntent(), s); }
@Test public void test120AddAccountWill() throws Exception { final String TEST_NAME = "test120AddAccountWill"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ShadowType object = parseObjectType(ACCOUNT_WILL_FILE, ShadowType.class); System.out.println(SchemaDebugUtil.prettyPrint(object)); System.out.println(object.asPrismObject().debugDump()); String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, task, result); assertEquals(ACCOUNT_WILL_OID, addedObjectOid); ShadowType repoShadowType = getShadowRepo(ACCOUNT_WILL_OID).asObjectable(); PrismAsserts.assertEqualsPolyString("Name not equal (repo)", "uid=will,ou=People,dc=example,dc=com", repoShadowType.getName()); assertAttribute(repoShadowType, getSecondaryIdentifierQName(), StringUtils.lowerCase(ACCOUNT_WILL_DN)); ShadowType provisioningAccountType = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, task, result).asObjectable(); PrismAsserts.assertEqualsPolyString("Name not equal.", "uid=will,ou=People,dc=example,dc=com", provisioningAccountType.getName()); assertShadows(1 + getNumberOfBaseContextShadows()); }
@Override public boolean matches(ShadowType shadowType) { if (shadowType == null) { return false; } if (!QNameUtil.match(getTypeName(), shadowType.getObjectClass())) { return false; } return true; }
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; }
@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); }
public static void cleanupShadowActivation(ShadowType repoShadowType) { // cleanup activation - we don't want to store these data in repo shadow (MID-2585) if (repoShadowType.getActivation() != null) { cleanupShadowActivation(repoShadowType.getActivation()); } }
private void validateResourceInShadow(ShadowType shadow, ResourceType resource) { if (shadow.getResource() != null || shadow.getResourceRef() != null) { return; } ObjectReferenceType reference = new ObjectReferenceType(); reference.setOid(resource.getOid()); reference.setType(ObjectTypes.RESOURCE.getTypeQName()); shadow.setResourceRef(reference); }
public static ShadowKindType getKind(ShadowType shadow) { if (shadow == null) { return null; } ShadowKindType kind = shadow.getKind(); if (kind != null) { return kind; } return ShadowKindType.ACCOUNT; }
protected void assertShadowName(PrismObject<ShadowType> shadow, String expectedName) { PrismAsserts.assertEqualsPolyString("Shadow name is wrong in "+shadow, expectedName, shadow.asObjectable().getName()); }
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; }