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; }
private String addAccount(File file) throws SchemaException, ObjectAlreadyExistsException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, IOException, ExpressionEvaluationException, PolicyViolationException { Task task = taskManager.createTaskInstance(TestDummyResourceAndSchemaCaching.class.getName() + ".addAccount"); OperationResult result = task.getResult(); PrismObject<ShadowType> account = PrismTestUtil.parseObject(file); String oid = provisioningService.addObject(account, null, null, task, result); result.computeStatus(); TestUtil.assertSuccess(result); return oid; }
@Test public void test125AddObjectNull() throws Exception { final String TEST_NAME = "test125AddObjectNull"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); String addedObjectOid = null; try { // WHEN addedObjectOid = provisioningService.addObject(null, null, null, task, result); Assert.fail("Expected IllegalArgumentException but haven't got one."); } catch(IllegalArgumentException ex){ assertEquals("Object to add must not be null.", ex.getMessage()); } assertShadows(1 + getNumberOfBaseContextShadows()); }
@Test public void test702ConfiguredCapabilityNoCreate() throws Exception{ final String TEST_NAME = "test702ConfiguredCapabilityNoCreate"; Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); addResourceFromFile(new File(TEST_DIR, "/resource-opendj-no-create.xml"), IntegrationTestTools.CONNECTOR_LDAP_TYPE, true, result); try { PrismObject<ShadowType> shadow = parseObjectType(ACCOUNT_WILL_FILE, ShadowType.class).asPrismObject(); provisioningService.addObject(shadow, null, null, task, result); AssertJUnit .fail("Expected unsupported operation exception, but haven't got one."); } catch (UnsupportedOperationException ex) { LOGGER.info("exception: {}", ex.getMessage(), ex); // this is expected.. } }
@Test public void test100AddAccountJack() throws Exception { final String TEST_NAME = "test100AddAccountJack"; TestUtil.displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ShadowType> shadowBefore = parseObject(getAccountJackFile()); // WHEN TestUtil.displayWhen(TEST_NAME); provisioningService.addObject(shadowBefore, null, null, task, result); // THEN TestUtil.displayThen(TEST_NAME); assertSuccess(result); }
@Test public void test100AddAccountDrink() throws Exception { final String TEST_NAME = "test100AddAccountDrink"; 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_DRINK_NAME, "water"); display("Adding shadow", account); try { // WHEN provisioningService.addObject(account, null, null, syncTask, result); AssertJUnit.fail("Unexpected success"); } catch (SecurityViolationException e) { // This is expected display("Expected exception", e); } }
provisioningService.addObject(account, null, null, task, result);
@Test public void test130AddAccountWill() throws Exception { final String TEST_NAME = "test130AddAccountWill"; displayTestTitle(TEST_NAME); // GIVEN OperationResult result = new OperationResult(TestOpenDjNegative.class.getName() + "." + TEST_NAME); ShadowType object = parseObjectType(ACCOUNT_WILL_FILE, ShadowType.class); display("Account to add", object); try { // WHEN String addedObjectOid = provisioningService.addObject(object.asPrismObject(), 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 test710AddResourceOpenDjBadCredentials() throws Exception { final String TEST_NAME = "test710AddResourceOpenDjBadCredentials"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_OPENDJ_BAD_CREDENTIALS_FILE); fillInConnectorRef(resource, IntegrationTestTools.CONNECTOR_LDAP_TYPE, result); // WHEN String addedObjectOid = provisioningService.addObject(resource, null, null, task, result); // THEN result.computeStatus(); display(result); assertSuccess(result); assertEquals("Wrong oid", RESOURCE_OPENDJ_BAD_CREDENTIALS_OID, addedObjectOid); }
@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); }
/** * The exception comes from the resource. There is no shadow for this object. */ @Test public void test300AddObjectObjectAlreadyExistResource() throws Exception { final String TEST_NAME = "test300AddObjectObjectAlreadyExistResource"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_SEARCH_FILE); display("Account to add", account); try { // WHEN provisioningService.addObject(account, null, null, task, result); AssertJUnit.fail("Expected addObject operation to fail but it was successful"); } catch (ObjectAlreadyExistsException e) { // This is expected display("Expected exception", e); // The exception should originate from the LDAP layers IntegrationTestTools.assertInMessageRecursive(e, "LDAP"); } // TODO: search to check that the shadow with the same NAME exists (search for OID will not do) }
@Test public void test720AddResourceOpenDjBadBindDn() throws Exception { final String TEST_NAME = "test720AddResourceOpenDjBadBindDn"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_OPENDJ_BAD_BIND_DN_FILE); fillInConnectorRef(resource, IntegrationTestTools.CONNECTOR_LDAP_TYPE, result); // WHEN String addedObjectOid = provisioningService.addObject(resource, null, null, task, result); // THEN result.computeStatus(); display(result); assertSuccess(result); assertEquals("Wrong oid", RESOURCE_OPENDJ_BAD_BIND_DN_OID, addedObjectOid); }
provisioningService.addObject(account, null, null, task, result);
private void testAddAccount(final String TEST_NAME, String username) throws Exception { Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); syncServiceMock.reset(); PrismObject<ShadowType> shadow = createAccountShadow(username); // WHEN provisioningService.addObject(shadow, null, null, task, result); result.computeStatus(); display("addObject result (expected failure)", result); TestUtil.assertSuccess(result); syncServiceMock.assertNotifySuccessOnly(); // checkConsistency(); assertSteadyResource(); }
@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()); }
@Test public void test414AddGroupCorsairsAssociateUser() throws Exception { final String TEST_NAME = "test414AddGroupCorsairsAssociateUser"; displayTestTitle(TEST_NAME); Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); ShadowType object = parseObjectType(GROUP_CORSAIRS_FILE, ShadowType.class); IntegrationTestTools.display("Adding object", object); // WHEN displayWhen(TEST_NAME); String addedObjectOid = provisioningService.addObject(object.asPrismObject(), null, null, task, result); // THEN displayThen(TEST_NAME); assertEquals(GROUP_CORSAIRS_OID, addedObjectOid); ShadowType shadowType = getShadowRepo(GROUP_CORSAIRS_OID).asObjectable(); PrismAsserts.assertEqualsPolyString("Wrong ICF name (repo)", GROUP_CORSAIRS_DN, shadowType.getName()); // Do NOT read provisioning shadow here. We want everything to be "fresh" assertShadows(22); }
@Test public void test200AddAccountNullAttributes() throws Exception { final String TEST_NAME = "test200AddAccountNullAttributes"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); syncServiceMock.reset(); ShadowType accountType = parseObjectType(ACCOUNT_WILL_FILE, ShadowType.class); PrismObject<ShadowType> account = accountType.asPrismObject(); account.checkConsistence(); account.removeContainer(ShadowType.F_ATTRIBUTES); display("Adding shadow", account); try { // WHEN displayWhen(TEST_NAME); provisioningService.addObject(account, null, null, task, result); assertNotReached(); } catch (SchemaException e) { // This is expected display("Expected exception", e); } displayThen(TEST_NAME); syncServiceMock.assertNotifyFailureOnly(); }
@Test public void test804AddAccountElizabeth() throws Exception { final String TEST_NAME = "test804AddAccountElizabeth"; displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); syncServiceMock.reset(); dummyResource.resetBreakMode(); PrismObject<ShadowType> account = prismContext.parseObject(ACCOUNT_ELIZABETH_FILE); account.checkConsistence(); display("Adding shadow", account); // WHEN displayWhen(TEST_NAME); provisioningService.addObject(account, null, null, task, result); // THEN displayThen(TEST_NAME); assertSuccess(result); account.checkConsistence(); dummyResourceCtl.assertAccountByUsername(ACCOUNT_ELIZABETH_USERNAME) .assertAttribute(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, ACCOUNT_ELIZABETH_FULLNAME); assertSteadyResources(); }
protected void testAddProtectedAccount(final String TEST_NAME, String username) throws Exception { Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); syncServiceMock.reset(); PrismObject<ShadowType> shadow = createAccountShadow(username); // WHEN try { provisioningService.addObject(shadow, null, null, task, result); AssertJUnit.fail("Expected security exception while adding '"+username+"' account"); } catch (SecurityViolationException e) { // This is expected display("Expected exception", e); } result.computeStatus(); display("addObject result (expected failure)", result); TestUtil.assertFailure(result); syncServiceMock.assertNotifyFailureOnly(); // checkConsistency(); assertSteadyResource(); }
provisioningService.addObject(resourceNew, null, ProvisioningOperationOptions.createOverwrite(true), task, result);