private PrismObject<ShadowType> fetchShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task task, OperationResult result) { try { return provisioningService.getObject(ShadowType.class, shadow.getOid(), SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), task, result); } catch (ObjectNotFoundException | CommunicationException | SchemaException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException | RuntimeException | Error e) { checkResult.recordError(ShadowStatistics.CANNOT_FETCH_RESOURCE_OBJECT, new SystemException("The resource object couldn't be fetched", e)); return null; } }
private <F extends ObjectType, T extends ObjectType> String addProvisioningObject(PrismObject<T> object, LensContext<F> context, LensElementContext<T> objectContext, ProvisioningOperationOptions options, ResourceType resource, Task task, OperationResult result) throws ObjectNotFoundException, ObjectAlreadyExistsException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, PolicyViolationException { if (object.canRepresent(ShadowType.class)) { ShadowType shadow = (ShadowType) object.asObjectable(); String resourceOid = ShadowUtil.getResourceOid(shadow); if (resourceOid == null) { throw new IllegalArgumentException("Resource OID is null in shadow"); } } OperationProvisioningScriptsType scripts = null; if (object.canRepresent(ShadowType.class)) { scripts = prepareScripts(object, context, objectContext, ProvisioningOperationTypeType.ADD, resource, task, result); } ModelImplUtils.setRequestee(task, context); String oid = provisioning.addObject(object, scripts, options, task, result); ModelImplUtils.clearRequestee(task); return oid; }
/** * Looks for conflicting account on the resource (not just repository). We will get conflicting shadow. * But a side-effect of this search is that the shadow for the conflicting account is created in the repo. */ private List<PrismObject<ShadowType>> findConflictingShadowsOnResource(ObjectQuery query, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, ConfigurationException, SchemaException, SecurityViolationException, ExpressionEvaluationException { final List<PrismObject<ShadowType>> foundAccount = new ArrayList<>(); // noDiscovery option to avoid calling notifyChange from ShadowManager (in case that new resource object is discovered) Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()); provisioningService.searchObjectsIterative(ShadowType.class, query, options, (object,result) -> foundAccount.add(object), task, parentResult); return foundAccount; }
private <F extends ObjectType, T extends ObjectType> PrismObject<T> deleteProvisioningObject( Class<T> objectTypeClass, String oid, LensContext<F> context, LensElementContext<T> objectContext, ProvisioningOperationOptions options, ResourceType resource, Task task, OperationResult result) throws ObjectNotFoundException, ObjectAlreadyExistsException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, PolicyViolationException { PrismObject<T> shadowToModify = null; OperationProvisioningScriptsType scripts = null; try { GetOperationOptions rootOpts = GetOperationOptions.createNoFetch(); rootOpts.setPointInTimeType(PointInTimeType.FUTURE); shadowToModify = provisioning.getObject(objectTypeClass, oid, SelectorOptions.createCollection(rootOpts), task, result); } catch (ObjectNotFoundException ex) { // this is almost OK, mute the error and try to delete account (it // will fail if something is wrong) result.muteLastSubresultError(); } if (ShadowType.class.isAssignableFrom(objectTypeClass)) { scripts = prepareScripts(shadowToModify, context, objectContext, ProvisioningOperationTypeType.DELETE, resource, task, result); } ModelImplUtils.setRequestee(task, context); PrismObject<T> objectAfterModification = provisioning.deleteObject(objectTypeClass, oid, options, scripts, task, result); ModelImplUtils.clearRequestee(task); return objectAfterModification; }
SearchResultMetadata searchMetadata = provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, task, result); PrismObject<ShadowType> accountNew = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, taskManager.createTaskInstance(), result);
@Test public void test199AddAccount() throws Exception { final String TEST_NAME = "test199AddAccount"; TestUtil.displayTestTitle(TEST_NAME); // GIVEN Task syncTask = taskManager.createTaskInstance(TestDummySecurity.class.getName() + "." + TEST_NAME); OperationResult result = new OperationResult(TestDummySecurity.class.getName() + "." + TEST_NAME); syncServiceMock.reset(); PrismObject<ShadowType> account = prismContext.parseObject(ACCOUNT_WILL_FILE); account.checkConsistence(); setAttribute(account, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_QUOTE_NAME, "At the moment?"); setAttribute(account, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "Eunuch"); display("Adding shadow", account); // WHEN provisioningService.addObject(account, null, null, syncTask, result); // THEN PrismObject<ShadowType> accountProvisioning = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, syncTask, result); display("Account provisioning", accountProvisioning); willIcfUid = getIcfUid(accountProvisioning); }
private void fixProvisioningTypeInDelta(ObjectDelta delta, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException { if (delta != null && delta.getObjectTypeClass() != null && (ShadowType.class.isAssignableFrom(delta.getObjectTypeClass()) || ResourceType.class.isAssignableFrom(delta.getObjectTypeClass()))) { // TODO exception can be thrown here (MID-4391) e.g. if resource does not exist any more; consider what to do // Currently we are on the safe side by making whole conversion fail getProvisioningService().applyDefinition(delta, task, result); } }
@Override protected boolean handleObject(PrismObject<ShadowType> object, Task workerTask, OperationResult result) throws CommonException { LOGGER.trace("Refreshing {}", object); provisioningService.refreshShadow(object, null, workerTask, result); LOGGER.trace("Refreshed {}", object); return true; } };
System.out.println(object.asPrismObject().debugDump()); String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, taskManager.createTaskInstance(), result); assertEquals(ACCOUNT_SEARCH_ITERATIVE_OID, addedObjectOid); ObjectQuery query = getQueryConverter().createObjectQuery(ShadowType.class, queryType); provisioningService.searchObjectsIterative(ShadowType.class, query, null, new ResultHandler<ShadowType>() {
@Test public void test703ConfiguredCapabilityNoDelete() throws Exception{ final String TEST_NAME = "test703ConfiguredCapabilityNoDelete"; Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); addResourceFromFile(new File(TEST_DIR, "/resource-opendj-no-delete.xml"), IntegrationTestTools.CONNECTOR_LDAP_TYPE, true, result); try { provisioningService.deleteObject(ShadowType.class, ACCOUNT_WILL_OID, null, null, task, result); AssertJUnit .fail("Expected unsupported operation exception, but haven't got one."); } catch (UnsupportedOperationException ex) { // this is expected.. } }
public <O extends ObjectType> Integer countObjects(Class<O> type, ObjectQuery query, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException { if (ObjectTypes.isClassManagedByProvisioning(type)) { return provisioning.countObjects(type, query, options, task, parentResult); } else { return cacheRepositoryService.countObjects(type, query, options, parentResult); } }
@Override public Object executeAdHocProvisioningScript(String resourceOid, String language, String code) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectAlreadyExistsException { OperationProvisioningScriptType script = new OperationProvisioningScriptType(); script.setCode(code); script.setLanguage(language); script.setHost(ProvisioningScriptHostType.RESOURCE); return provisioningService.executeScript(resourceOid, script, getCurrentTask(), getCurrentResult()); }
protected void testComparePassword(final String TEST_NAME, String tag, String shadowOid, String expectedPassword, ItemComparisonResult expectedResult) throws Exception { Task task = createTask(TEST_NAME+".tag"); OperationResult result = task.getResult(); syncServiceMock.reset(); // WHEN (match) displayWhen(TEST_NAME); ItemComparisonResult comparisonResult = provisioningService.compare(ShadowType.class, shadowOid, SchemaConstants.PATH_PASSWORD_VALUE, expectedPassword, task, result); // THEN (match) displayThen(TEST_NAME); assertSuccess(result); display("Comparison result ("+tag+")", comparisonResult); assertEquals("Wrong comparison result ("+tag+")", expectedResult, comparisonResult); syncServiceMock.assertNoNotifcations(); }
SearchResultMetadata searchMetadata = provisioningService.searchObjectsIterative(ShadowType.class, query, null, handler, task, result); PrismObject<ShadowType> accountNew = provisioningService.getObject(ShadowType.class, ACCOUNT_WILL_OID, null, taskManager.createTaskInstance(), result);
@Test public void test900DeleteResource() throws Exception { final String TEST_NAME = "test900DeleteResource"; displayTestTitle(TEST_NAME); // GIVEN Task task = taskManager.createTaskInstance(TestDummyResourceAndSchemaCaching.class.getName() + "." + TEST_NAME); OperationResult result = task.getResult(); // WHEN provisioningService.deleteObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, task, result); // THEN result.computeStatus(); TestUtil.assertSuccess(result); try { repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result); AssertJUnit.fail("Resource not gone from repo"); } catch (ObjectNotFoundException e) { // This is expected } try { provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result); AssertJUnit.fail("Resource not gone from provisioning"); } catch (ObjectNotFoundException e) { // This is expected } }
@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()); }
protected void fixProvisioningTypeInDelta(ObjectDelta<O> delta, Objectable object, Task task, OperationResult result) { if (delta != null && delta.getObjectTypeClass() != null && (ShadowType.class.isAssignableFrom(delta.getObjectTypeClass()) || ResourceType.class.isAssignableFrom(delta.getObjectTypeClass()))) { try { lensContext.getProvisioningService().applyDefinition(delta, object, task, result); } catch (Exception e) { LOGGER.warn("Error applying provisioning definitions to delta {}: {}", delta, e.getMessage()); // In case of error just go on. Maybe we do not have correct definition here. But at least we can // display the GUI pages and maybe we can also salvage the operation. result.recordWarning(e); } } }
/** * Attempt to refresh shadow with failed operation. Nothing should happen. */ @Test public void test179RefreshAccountMorganFailed() throws Exception { final String TEST_NAME = "test179RefreshAccountMorganFailed"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); clockForward("PT17M"); syncServiceMock.reset(); dummyResource.setBreakMode(BreakMode.NETWORK); PrismObject<ShadowType> shadowRepoBefore = getShadowRepo(shadowMorganOid); // WHEN displayWhen(TEST_NAME); provisioningService.refreshShadow(shadowRepoBefore, null, task, result); // THEN displayThen(TEST_NAME); display("Result", result); assertSuccess(result); syncServiceMock.assertNoNotifcations(); assertMorganDeleteFailed(); }
@Test public void test140AddDeleteAccountSparrow() throws Exception { final String TEST_NAME = "test140AddDeleteAccountSparrow"; displayTestTitle(TEST_NAME); // GIVEN OperationResult result = new OperationResult(TestOpenDjNegative.class.getName() + "." + TEST_NAME); try { provisioningService.deleteObject(ShadowType.class, ACCOUNT_SPARROW_OID, null, null, taskManager.createTaskInstance(), result); AssertJUnit.fail("addObject succeeded unexpectedly"); } catch (ConfigurationException e) { // This is expected display("Expected exception", e); } result.computeStatus(); TestUtil.assertFailure(result); }
@Test public void test117CountNullQueryResource() throws Exception { displayTestTitle("test117CountNullQueryResource"); // GIVEN OperationResult result = new OperationResult(TestDummy.class.getName() + ".test117CountNullQueryResource"); // WHEN int count = provisioningService.countObjects(ResourceType.class, null, null, null, result); // THEN result.computeStatus(); display("countObjects result", result); TestUtil.assertSuccess(result); display("Counted " + count + " resources"); assertEquals("Wrong count", 1, count); assertSteadyResource(); }