Пример #1
0
  @Test
  public void test110ChangeModifyObject() throws Exception {
    final String TEST_NAME = "test110ChangeModifyObject";
    TestUtil.displayTestTile(this, TEST_NAME);

    OperationResult result = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    Collection<ResourceAttribute<?>> identifiers = addSampleResourceObject("john", "John", "Smith");

    Set<Operation> changes = new HashSet<Operation>();

    changes.add(createAddAttributeChange("employeeNumber", "123123123"));
    changes.add(createReplaceAttributeChange("sn", "Smith007"));
    changes.add(createAddAttributeChange("street", "Wall Street"));
    changes.add(createDeleteAttributeChange("givenName", "John"));

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findObjectClassDefinition(
            ProvisioningTestUtil.OBJECT_CLASS_INETORGPERSON_NAME);

    cc.modifyObject(accountDefinition, identifiers, changes, result);

    ResourceObjectIdentification identification =
        new ResourceObjectIdentification(accountDefinition, identifiers);
    PrismObject<ShadowType> shadow = cc.fetchObject(ShadowType.class, identification, null, result);
    ResourceAttributeContainer resObj = ShadowUtil.getAttributesContainer(shadow);

    AssertJUnit.assertNull(
        resObj.findAttribute(
            new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "givenName")));

    String addedEmployeeNumber =
        resObj
            .findAttribute(
                new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "employeeNumber"))
            .getValue(String.class)
            .getValue();
    String changedSn =
        resObj
            .findAttribute(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "sn"))
            .getValues(String.class)
            .iterator()
            .next()
            .getValue();
    String addedStreet =
        resObj
            .findAttribute(new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "street"))
            .getValues(String.class)
            .iterator()
            .next()
            .getValue();

    System.out.println("changed employee number: " + addedEmployeeNumber);
    System.out.println("changed sn: " + changedSn);
    System.out.println("added street: " + addedStreet);

    AssertJUnit.assertEquals("123123123", addedEmployeeNumber);
    AssertJUnit.assertEquals("Smith007", changedSn);
    AssertJUnit.assertEquals("Wall Street", addedStreet);
  }
Пример #2
0
  // This obviously does not work with LDAP connector
  @Test(enabled = false)
  public void testDisableAccount() throws Exception {
    TestUtil.displayTestTile(this, "testDisableAccount");

    // GIVEN
    OperationResult result = new OperationResult(this.getClass().getName() + ".testDisableAccount");

    Collection<ResourceAttribute<?>> identifiers =
        addSampleResourceObject("blackbeard", "Edward", "Teach");

    // Check precondition
    String entryUuid = getEntryUuid(identifiers);
    SearchResultEntry ldapEntryBefore = openDJController.searchAndAssertByEntryUuid(entryUuid);
    assertTrue("The account is not enabled", openDJController.isAccountEnabled(ldapEntryBefore));

    // WHEN

    Set<Operation> changes = new HashSet<Operation>();
    changes.add(createActivationChange(ActivationStatusType.DISABLED));

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceSchema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);

    cc.modifyObject(accountDefinition, identifiers, changes, result);

    // THEN

    SearchResultEntry ldapEntryAfter = openDJController.searchAndAssertByEntryUuid(entryUuid);
    assertFalse("The account was not disabled", openDJController.isAccountEnabled(ldapEntryAfter));
  }
Пример #3
0
  @Test
  public void test610ChangePassword() throws Exception {
    final String TEST_NAME = "test610ChangePassword";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    ResourceAttributeContainer resourceObject =
        createResourceObject("uid=drake,ou=People,dc=example,dc=com", "Sir Francis Drake", "Drake");
    PrismObject<ShadowType> shadow = wrapInShadow(ShadowType.class, resourceObject);

    OperationResult addResult = new OperationResult(this.getClass().getName() + "." + TEST_NAME);

    // Add a testing object
    cc.addObject(shadow, null, addResult);

    String entryUuid = (String) resourceObject.getIdentifier().getValue().getValue();
    SearchResultEntry entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry before change", entry);
    String passwordBefore = OpenDJController.getAttributeValue(entry, "userPassword");
    // We have set no password during create, therefore the password should
    // be empty
    assertNull(passwordBefore);

    ObjectClassComplexTypeDefinition accountDefinition =
        resourceObject.getDefinition().getComplexTypeDefinition();

    Collection<ResourceAttribute<?>> identifiers = resourceObject.getIdentifiers();
    // Determine object class from the schema

    OperationResult result = new OperationResult(this.getClass().getName() + ".testFetchObject");

    // WHEN

    Set<Operation> changes = new HashSet<Operation>();
    ProtectedStringType passPs = protector.encryptString("salalala");

    ItemDeltaType propMod = new ItemDeltaType();
    // create modification path
    Document doc = DOMUtil.getDocument();
    ItemPathType path = new ItemPathType("credentials/password/value");
    //		PropertyPath propPath = new PropertyPath(new
    // PropertyPath(ResourceObjectShadowType.F_CREDENTIALS), CredentialsType.F_PASSWORD);
    propMod.setPath(path);

    // set the replace value
    MapXNode passPsXnode = prismContext.getBeanConverter().marshalProtectedDataType(passPs);
    RawType value = new RawType(passPsXnode, prismContext);
    propMod.getValue().add(value);

    // set the modificaion type
    propMod.setModificationType(ModificationTypeType.REPLACE);

    PropertyDelta passDelta =
        (PropertyDelta) DeltaConvertor.createItemDelta(propMod, shadow.getDefinition());
    PropertyModificationOperation passwordModification =
        new PropertyModificationOperation(passDelta);
    changes.add(passwordModification);

    //		PasswordChangeOperation passwordChange = new PasswordChangeOperation(passPs);
    //		changes.add(passwordChange);
    cc.modifyObject(accountDefinition, identifiers, changes, result);

    // THEN

    entry = openDJController.searchAndAssertByEntryUuid(entryUuid);
    display("Entry after change", entry);

    String passwordAfter = OpenDJController.getAttributeValue(entry, "userPassword");
    assertNotNull(passwordAfter);

    System.out.println("Account password: " + passwordAfter);
  }