public static boolean isConflicting(ShadowType shadow1, ShadowType shadow2) { if (!shadow1.getResourceRef().getOid().equals(shadow2.getResourceRef().getOid())) { return false; } if (!MiscUtil.equals(getKind(shadow1), getKind(shadow2))) { return false; } return ResourceShadowDiscriminator.equalsIntent(shadow1.getIntent(), shadow2.getIntent()); }
private PrismObject<ShadowType> findProjectionOnResource(String resourceOid) throws ObjectNotFoundException, SchemaException { F focusType = getObject().asObjectable(); for (PrismObject<ShadowType> shadow: getLinkTargets()) { if (resourceOid.equals(shadow.asObjectable().getResourceRef().getOid())) { return shadow; } } return null; }
private boolean matches(PrismReferenceValue refVal, PrismObject<ShadowType> linkTarget) throws ObjectNotFoundException, SchemaException { ShadowType linkTargetType = linkTarget.asObjectable(); if (resourceOid != null) { if (!resourceOid.equals(linkTargetType.getResourceRef().getOid())) { return false; } } if (dead != null) { if (dead && !ShadowUtil.isDead(linkTargetType)) { return false; } else if (!dead && ShadowUtil.isDead(linkTargetType)) { return false; } } // TODO: more criteria return true; }
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()); }
protected <F extends FocusType> PrismReferenceValue getLinkRef(PrismObject<F> focus, String resourceOid) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException { F focusType = focus.asObjectable(); for (ObjectReferenceType linkRefType: focusType.getLinkRef()) { String linkTargetOid = linkRefType.getOid(); assertFalse("No linkRef oid", StringUtils.isBlank(linkTargetOid)); PrismObject<ShadowType> account = getShadowModel(linkTargetOid, GetOperationOptions.createNoFetch(), false); if (resourceOid.equals(account.asObjectable().getResourceRef().getOid())) { // This is noFetch. Therefore there is no fetchResult return linkRefType.asReferenceValue(); } } AssertJUnit.fail("Account for resource "+resourceOid+" not found in "+focus); return null; // Never reached. But compiler complains about missing return }
/** * Strict mathcing. E.g. null discriminator kind is intepreted as ACCOUNT and it must match the kind * in the shadow. */ public static boolean matches(ShadowType shadowType, ResourceShadowDiscriminator discr) { if (shadowType == null) { return false; } if (!discr.getResourceOid().equals(shadowType.getResourceRef().getOid())) { return false; } if (!MiscUtil.equals(discr.getKind(), shadowType.getKind())) { return false; } return ResourceShadowDiscriminator.equalsIntent(shadowType.getIntent(), discr.getIntent()); }
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); }
protected void modifyAccountShadowReplace(String accountOid, ItemPath propertyPath, Task task, OperationResult result, Object... newRealValue) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException { PrismObject<ShadowType> shadow = repositoryService.getObject(ShadowType.class, accountOid, null, result); String resourceOid = shadow.asObjectable().getResourceRef().getOid(); PrismObject<ResourceType> resource = provisioningService.getObject(ResourceType.class, resourceOid, null, task, result); ObjectDelta<ShadowType> objectDelta = createModifyAccountShadowReplaceDelta(accountOid, resource, propertyPath, newRealValue); Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta); modelService.executeChanges(deltas, null, task, result); }
public ShadowAsserter<RA> assertResource(String expectedResourceOid) { ObjectReferenceType resourceRef = getObject().asObjectable().getResourceRef(); if (resourceRef == null) { fail("No resourceRef in "+desc()); } assertEquals("Wrong resourceRef OID in "+desc(), expectedResourceOid, resourceRef.getOid()); return this; }
private ResourceType resolveResource(ShadowType shadow, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException { if (shadow.getResource() != null) { return shadow.getResource(); } ObjectReferenceType ref = shadow.getResourceRef(); if (ref == null) { throw new ExpressionEvaluationException("Resource shadow object " + shadow + " doesn't have defined resource."); } if (ref.getOid() == null) { throw new ExpressionEvaluationException("Resource shadow object " + shadow + " defines null resource OID."); } return modelObjectResolver.getObjectSimple(ResourceType.class, ref.getOid(), null, null, result); }
protected <F extends FocusType> String getLinkRefOid(PrismObject<F> focus, String resourceOid, ShadowKindType kind, String intent) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException { F focusType = focus.asObjectable(); for (ObjectReferenceType linkRefType: focusType.getLinkRef()) { String linkTargetOid = linkRefType.getOid(); assertFalse("No linkRef oid", StringUtils.isBlank(linkTargetOid)); PrismObject<ShadowType> account = getShadowModel(linkTargetOid, GetOperationOptions.createNoFetch(), false); ShadowType shadowType = account.asObjectable(); if (kind != null && !kind.equals(shadowType.getKind())) { continue; } if (!MiscUtil.equals(intent, shadowType.getIntent())) { continue; } if (resourceOid.equals(shadowType.getResourceRef().getOid())) { // This is noFetch. Therefore there is no fetchResult return linkTargetOid; } } AssertJUnit.fail("Linked shadow for resource "+resourceOid+", kind "+kind+" and intent "+intent+" not found in "+focus); return null; // Never reached. But compiler complains about missing return }
/** * Interprets ResourceShadowDiscriminator as a pattern. E.g. null discriminator kind is * interpreted to match any shadow kind. */ public static boolean matchesPattern(ShadowType shadowType, ShadowDiscriminatorType discr) { if (shadowType == null) { return false; } if (!discr.getResourceRef().getOid().equals(shadowType.getResourceRef().getOid())) { return false; } if (discr.getKind() != null && !MiscUtil.equals(discr.getKind(), shadowType.getKind())) { return false; } if (discr.getIntent() == null) { return true; } return ResourceShadowDiscriminator.equalsIntent(shadowType.getIntent(), discr.getIntent()); }
private ObjectQuery createQueryBySecondaryIdentifier(ShadowType shadow) throws SchemaException { // TODO TODO TODO set matching rule instead of null in equlas filter Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(shadow); S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class); q = q.block(); if (secondaryIdentifiers.isEmpty()) { for (ResourceAttribute<?> primaryIdentifier: ShadowUtil.getPrimaryIdentifiers(shadow)) { q = q.itemAs(primaryIdentifier).or(); } } else { // secondary identifiers connected by 'or' clause for (ResourceAttribute<?> secondaryIdentifier : secondaryIdentifiers) { q = q.itemAs(secondaryIdentifier).or(); } } q = q.none().endBlock().and(); // resource + object class q = q.item(ShadowType.F_RESOURCE_REF).ref(shadow.getResourceRef().getOid()).and(); return q.item(ShadowType.F_OBJECT_CLASS).eq(shadow.getObjectClass()).build(); }
private LensProjectionContext fillContextWithDummyElaineAccount( LensContext<UserType> context, String dummyName, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, IOException, ExpressionEvaluationException { String resourceOid = getDummyOid(dummyName); String accountOid = getDummuAccountOid(dummyName,"e"); PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_ELAINE_TEMPLATE_FILE); ShadowType accountType = account.asObjectable(); accountType.setOid(accountOid); accountType.getResourceRef().setOid(resourceOid); provisioningService.applyDefinition(account, task, result); return fillContextWithAccount(context, account, task, result); }
@Override public boolean handle(PrismObject<ObjectType> prismObject, OperationResult parentResult) { ObjectType objectType = prismObject.asObjectable(); objects.add(objectType); display("Found object", objectType); assertTrue(objectType instanceof ShadowType); ShadowType shadow = (ShadowType) objectType; assertNotNull(shadow.getOid()); assertNotNull(shadow.getName()); assertEquals(new QName(resourceNamespace, OBJECT_CLASS_INETORGPERSON_NAME), shadow.getObjectClass()); assertEquals(RESOURCE_OPENDJ_OID, shadow.getResourceRef().getOid()); String idPrimaryVal = getAttributeValue(shadow, getPrimaryIdentifierQName()); assertNotNull("No primary identifier ("+getPrimaryIdentifierQName().getLocalPart()+")", idPrimaryVal); String idSecondaryVal = getAttributeValue(shadow, getSecondaryIdentifierQName()); assertNotNull("No secondary ("+getSecondaryIdentifierQName().getLocalPart()+")", idSecondaryVal); assertEquals("Wrong shadow name", idSecondaryVal.toLowerCase(), shadow.getName().getOrig().toLowerCase()); assertNotNull("Missing LDAP uid", getAttributeValue(shadow, new QName(resourceNamespace, "uid"))); assertNotNull("Missing LDAP cn", getAttributeValue(shadow, new QName(resourceNamespace, "cn"))); assertNotNull("Missing LDAP sn", getAttributeValue(shadow, new QName(resourceNamespace, "sn"))); assertNotNull("Missing activation", shadow.getActivation()); assertNotNull("Missing activation status", shadow.getActivation().getAdministrativeStatus()); assertEquals("Not enabled", ActivationStatusType.ENABLED, shadow.getActivation().getAdministrativeStatus()); return true; } };
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()); }
@Override public boolean handle(PrismObject<ObjectType> prismObject, OperationResult parentResult) { ObjectType objectType = prismObject.asObjectable(); objects.add(objectType); display("Found object", objectType); assertTrue(objectType instanceof ShadowType); ShadowType shadow = (ShadowType) objectType; assertNotNull(shadow.getOid()); assertNotNull(shadow.getName()); assertEquals(RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS, shadow.getObjectClass()); assertEquals(RESOURCE_OPENDJ_OID, shadow.getResourceRef().getOid()); String icfUid = getAttributeValue(shadow, getOpenDjPrimaryIdentifierQName()); assertNotNull("No ICF UID", icfUid); String icfName = getNormalizedAttributeValue(shadow, refinedAccountDefinition, getOpenDjSecondaryIdentifierQName()); assertNotNull("No ICF NAME", icfName); try { PrismAsserts.assertEquals("Wrong shadow name", caseIgnoreMatchingRule, shadow.getName().getOrig(), icfName); } catch (SchemaException e) { throw new IllegalArgumentException(e.getMessage(),e); } assertNotNull("Missing LDAP uid", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "uid"))); assertNotNull("Missing LDAP cn", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "cn"))); assertNotNull("Missing LDAP sn", getAttributeValue(shadow, new QName(ResourceTypeUtil.getResourceNamespace(resourceTypeOpenDjrepo), "sn"))); assertNotNull("Missing activation", shadow.getActivation()); assertNotNull("Missing activation status", shadow.getActivation().getAdministrativeStatus()); return true; } };
protected LensProjectionContext fillContextWithAccount(LensContext<UserType> context, PrismObject<ShadowType> account, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { ShadowType accountType = account.asObjectable(); String resourceOid = accountType.getResourceRef().getOid(); ResourceType resourceType = provisioningService.getObject(ResourceType.class, resourceOid, null, task, result).asObjectable(); applyResourceSchema(accountType, resourceType); ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(resourceOid, ShadowKindType.ACCOUNT, ShadowUtil.getIntent(accountType)); LensProjectionContext accountSyncContext = context.findOrCreateProjectionContext(rat); accountSyncContext.setOid(account.getOid()); accountSyncContext.setLoadedObject(account); accountSyncContext.setResource(resourceType); accountSyncContext.setExists(true); context.rememberResource(resourceType); return accountSyncContext; }
@Test public void test110GetAccountJack() throws Exception { final String TEST_NAME = "test110GetAccountJack"; TestUtil.displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); // WHEN TestUtil.displayWhen(TEST_NAME); PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, getAccountJackOid(), null, task, result); // THEN TestUtil.displayThen(TEST_NAME); assertSuccess(result); assertNotNull(shadow); display("Shadow after", shadow); ShadowType shadowType = shadow.asObjectable(); PrismAsserts.assertEqualsPolyString("Wrong name", "jack", shadow.getName()); assertNotNull(shadow.getOid()); assertEquals(RESOURCE_CSV_ACCOUNT_OBJECTCLASS, shadowType.getObjectClass()); assertEquals(getResourceOid(), shadowType.getResourceRef().getOid()); assertAccountJackAttributes(shadowType); assertNotNull("Missing activation", shadowType.getActivation()); assertNotNull("Missing activation status", shadowType.getActivation().getAdministrativeStatus()); assertEquals("Not enabled", ActivationStatusType.ENABLED, shadowType.getActivation().getAdministrativeStatus()); PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, shadow.getOid(), null, result); ShadowType repoShadowType = repoShadow.asObjectable(); assertEquals(RESOURCE_CSV_ACCOUNT_OBJECTCLASS, repoShadowType.getObjectClass()); assertEquals(getResourceOid(), repoShadowType.getResourceRef().getOid()); assertAccountJackAttributesRepo(shadowType); }
private PrismObject<ShadowType> checkWallyAccount(PrismObject<ResourceType> resource, DummyResource dummy, String resourceDesc, String expectedFullName, String shipName, String quote) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, ExpressionEvaluationException, InterruptedException { PrismObject<ShadowType> accountShadowWally = findAccountByUsername(ACCOUNT_WALLY_DUMMY_USERNAME, resource); display("Account shadow wally ("+resourceDesc+")", accountShadowWally); assertEquals("Wrong resourceRef in wally account ("+resourceDesc+")", resource.getOid(), accountShadowWally.asObjectable().getResourceRef().getOid()); if (expectedFullName != null) { IntegrationTestTools.assertAttribute(accountShadowWally.asObjectable(), resource.asObjectable(), DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, expectedFullName); } DummyAccount dummyAccount = dummy.getAccountByUsername(ACCOUNT_WALLY_DUMMY_USERNAME); display("Account wally ("+resourceDesc+")", dummyAccount); assertNotNull("No dummy account ("+resourceDesc+")", dummyAccount); if (expectedFullName != null) { assertEquals("Wrong dummy account fullname ("+resourceDesc+")", expectedFullName, dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME)); } if (shipName != null){ assertEquals("Wrong dummy account shipName ("+resourceDesc+")", shipName, dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME)); } if (quote != null){ assertEquals("Wrong dummy account quote ("+resourceDesc+")", quote, dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME)); } return accountShadowWally; }