@Test
  public void testReadAlterAttributes() {
    final OracleAttributesReader reader =
        new OracleAttributesReader(TestHelpers.createDummyMessages());
    OracleUserAttributes.Builder caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    Set<Attribute> attributes = new HashSet<Attribute>();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_LOCAL));
    attributes.add(AttributeBuilder.buildPassword("myPassword".toCharArray()));
    reader.readAlterAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertEquals(OracleAuthentication.LOCAL, caAttributes.getAuth());
    Assert.assertNotNull("Password must not be null", caAttributes.getPassword());

    // verify that password is not set for alter when not set
    caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    attributes.clear();
    attributes.add(AttributeBuilder.buildPasswordExpired(true));
    reader.readAlterAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertNull("Password must be null", caAttributes.getPassword());

    // try to update authentication to null
    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME));
    attributes.add(AttributeBuilder.buildPassword("myPassword".toCharArray()));
    try {
      reader.readAlterAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Create attributes must fail for null authentication");
    } catch (IllegalArgumentException e) {
    }
  }
 static Attribute buildSingleAttribute(String name, Object value) {
   if (value != null) {
     return AttributeBuilder.build(name, value);
   } else {
     return AttributeBuilder.build(name);
   }
 }
  @Test // @Ignore
  public void testEnableDisable() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      // Delete the account if it already exists
      //
      deleteUser(TEST_USER, info);

      // Create the account
      //
      Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null);
      System.out.println(newUid.getValue() + " created");

      // Test disabling the user
      {
        ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
        builder.setUid(newUid);
        Attribute password =
            AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, Boolean.FALSE);
        builder.addAttribute(password);
        builder.addAttribute(new Name(TEST_USER));
        ConnectorObject newUser = builder.build();
        info.update(newUser.getObjectClass(), newUser.getAttributes(), null);

        Map map = new HashMap<String, Object>();
        map.put(
            OperationOptions.OP_ATTRIBUTES_TO_GET,
            new String[] {OperationalAttributes.ENABLE_NAME});
        OperationOptions options = new OperationOptions(map);

        ConnectorObject user = getUser(TEST_USER, options);
        Attribute enabled = user.getAttributeByName(OperationalAttributes.ENABLE_NAME);
        Assert.assertNotNull(enabled);
        Assert.assertFalse(AttributeUtil.getBooleanValue(enabled));
      }

      // Test enabling the user
      {
        ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
        builder.setUid(newUid);
        Attribute password =
            AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, Boolean.TRUE);
        builder.addAttribute(password);
        builder.addAttribute(new Name(TEST_USER));
        ConnectorObject newUser = builder.build();
        info.update(newUser.getObjectClass(), newUser.getAttributes(), null);

        Attribute enabled = newUser.getAttributeByName(OperationalAttributes.ENABLE_NAME);
        Assert.assertNotNull(enabled);
        Assert.assertTrue(AttributeUtil.getBooleanValue(enabled));
      }
    } finally {
      info.dispose();
    }
  }
  private void generateUsers() {
    for (int i = 0; i < getCreateUsersNumber(); i++) {
      Set<Attribute> attrs = new HashSet<Attribute>();
      attrs.add(AttributeBuilder.build(Name.NAME, formatName(i)));
      attrs.add(AttributeBuilder.buildPassword(SAMPLE_PASSWD.toCharArray()));

      facade.create(ObjectClass.ACCOUNT, attrs, null);
    }
  }
  private void generateGroup(List<String> usernames) {
    if (createGroup()) {
      Set<Attribute> attrs = new HashSet<Attribute>();
      attrs.add(AttributeBuilder.build(Name.NAME, TESTGROUP_NAME));
      attrs.add(AttributeBuilder.build(GroupAttribute.USERS.getName(), usernames));

      facade.create(ObjectClass.GROUP, attrs, null);
    }
  }
 private Set<Attribute> fillInSampleUser(final String testUser) {
   Set<Attribute> attrs = new HashSet<Attribute>();
   attrs.add(new Name(TEST_USER));
   attrs.add(AttributeBuilder.build(ATTR_FIRSTNAME, "SPML"));
   attrs.add(AttributeBuilder.build(ATTR_LASTNAME, "User"));
   attrs.add(AttributeBuilder.build(ATTR_FULLNAME, "SMPL User"));
   attrs.add(
       AttributeBuilder.build(
           OperationalAttributes.PASSWORD_NAME, new GuardedString("xyzzy".toCharArray())));
   return attrs;
 }
  @Test // @Ignore
  public void testModifyUser() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);

    try {
      // Delete the user
      //
      deleteUser(TEST_USER, info);

      Set<Attribute> attrs = fillInSampleUser(TEST_USER);
      info.create(ObjectClass.ACCOUNT, attrs, null);

      ConnectorObject user = getUser(TEST_USER);
      Set<Attribute> changed = new HashSet<Attribute>();
      changed.add(AttributeBuilder.build(ATTR_FIRSTNAME, "abel"));
      changed.add(user.getUid());
      info.update(ObjectClass.ACCOUNT, changed, null);

      ConnectorObject changedUser = getUser(TEST_USER);
      Attribute firstname = changedUser.getAttributeByName(ATTR_FIRSTNAME);
      displayUser(changedUser);
      Assert.assertNotNull(firstname);
      Assert.assertTrue(AttributeUtil.getStringValue(firstname).equalsIgnoreCase("abel"));
    } finally {
      info.dispose();
    }
  }
  private ConnectorObject getObjectToAuthenticate() {
    final String uidAttribute = freeIPAConfiguration.getUidAttribute();
    Map<String, ConnectorObject> entryDN2Object = new HashMap<String, ConnectorObject>();

    final Attribute attr = AttributeBuilder.build(uidAttribute, username);

    for (ConnectorObject object :
        LdapSearches.findObjects(
            freeIPAConnection,
            objectClass,
            LDAPConstants.USERS_DN_BASE_SUFFIX + "," + freeIPAConfiguration.getRootSuffix(),
            attr,
            "entryDN")) {
      String entryDN = object.getAttributeByName("entryDN").getValue().get(0).toString();
      entryDN2Object.put(entryDN, object);
    }

    // If we found more than one authentication candidates, no need to continue
    if (entryDN2Object.size() > 1) {
      throw new ConnectorSecurityException(
          freeIPAConnection.format("moreThanOneEntryMatched", null, username));
    }

    return !entryDN2Object.isEmpty() ? entryDN2Object.values().iterator().next() : null;
  }
  @Test // @Ignore
  public void testChangePassword() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      // Delete the account if it already exists
      //
      deleteUser(TEST_USER, info);

      // Create the account
      //
      Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null);
      System.out.println(newUid.getValue() + " created");

      ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
      builder.setUid(newUid);
      Attribute password =
          AttributeBuilder.build(
              OperationalAttributes.PASSWORD_NAME, new GuardedString("xyzzy123".toCharArray()));
      builder.addAttribute(password);
      builder.addAttribute(new Name(TEST_USER));
      ConnectorObject newUser = builder.build();
      info.update(newUser.getObjectClass(), newUser.getAttributes(), null);
    } finally {
      info.dispose();
    }
  }
예제 #10
0
 static {
   boolean enabled = true;
   for (int i = 0; i < 100; i++) {
     ConnectorObjectBuilder builder = new ConnectorObjectBuilder();
     builder.setUid(String.valueOf(i));
     builder.setName(String.format("user%03d", i));
     builder.addAttribute(AttributeBuilder.buildEnabled(enabled));
     Map<String, Object> mapAttribute = new HashMap<String, Object>();
     mapAttribute.put("email", "*****@*****.**");
     mapAttribute.put("primary", true);
     mapAttribute.put("usage", Arrays.asList("home", "work"));
     builder.addAttribute(AttributeBuilder.build("emails", mapAttribute));
     ConnectorObject co = builder.build();
     collection.put(co.getName().getNameValue(), co);
     enabled = !enabled;
   }
 }
 /**
  * @param propertySetName
  * @return The set <CODE>Set<Attribute></CODE> of attributes
  */
 public Set<Attribute> getAttributeSet(final String propertySetName) {
   Map<String, Object> propMap = getPropertyMap(propertySetName);
   assertNotNull(propMap);
   Set<Attribute> attrSet = new LinkedHashSet<Attribute>();
   for (Entry<String, Object> entry : propMap.entrySet()) {
     final String key = entry.getKey();
     final Object value = entry.getValue();
     if (value.getClass().isArray()) {
       Object[] array = (Object[]) value;
       List<?> list = Arrays.asList(array);
       attrSet.add(AttributeBuilder.build(key, list));
     } else if (value instanceof Collection<?>) {
       attrSet.add(AttributeBuilder.build(key, (Collection<?>) value));
     } else {
       attrSet.add(AttributeBuilder.build(key, value));
     }
   }
   return attrSet;
 }
  @Test // @Ignore
  public void testGetSpecifiedUser() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      deleteUser(TEST_USER, info);

      info.create(ObjectClass.ACCOUNT, attrs, null);

      ConnectorObject user = getUser(TEST_USER);
      Assert.assertNotNull(user);

      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Uid.NAME, "asdhjfdaslfh alsk fhasldk ")),
          handler,
          null);
      Assert.assertFalse(handler.iterator().hasNext());

      handler = new TestHandler();
      String[] attributesToGet = {"firstname"};
      Map<String, Object> optionsMap = new HashMap<String, Object>();
      optionsMap.put(OperationOptions.OP_ATTRIBUTES_TO_GET, attributesToGet);
      OperationOptions options = new OperationOptions(optionsMap);
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Uid.NAME, TEST_USER)),
          handler,
          options);
      Assert.assertTrue(handler.iterator().hasNext());
      ConnectorObject object = handler.iterator().next();
      Assert.assertNotNull(object.getAttributeByName("firstname"));
      Assert.assertNull(object.getAttributeByName("lastname"));
    } finally {
      info.dispose();
    }
  }
  @Transactional(readOnly = true)
  @Override
  public void before(final PropagationTask task, final ConnectorObject beforeObj) {
    super.before(task, beforeObj);

    Provision provision = task.getResource().getProvision(anyTypeDAO.findGroup());
    if (AnyTypeKind.USER == task.getAnyTypeKind() && provision.getMapping() != null) {
      User user = userDAO.find(task.getAnyKey());
      if (user != null) {
        List<String> groupConnObjectLinks = new ArrayList<>();
        for (Group group : userDAO.findAllGroups(user)) {
          if (group.getResourceNames().contains(task.getResource().getKey())
              && StringUtils.isNotBlank(provision.getMapping().getConnObjectLink())) {

            LOG.debug("Evaluating connObjectLink for {}", group);

            JexlContext jexlContext = new MapContext();
            JexlUtils.addFieldsToContext(group, jexlContext);
            JexlUtils.addPlainAttrsToContext(group.getPlainAttrs(), jexlContext);
            JexlUtils.addDerAttrsToContext(group, jexlContext);

            String groupConnObjectLinkLink =
                JexlUtils.evaluate(provision.getMapping().getConnObjectLink(), jexlContext);
            LOG.debug("ConnObjectLink for {} is '{}'", group, groupConnObjectLinkLink);
            if (StringUtils.isNotBlank(groupConnObjectLinkLink)) {
              groupConnObjectLinks.add(groupConnObjectLinkLink);
            }
          }
        }
        LOG.debug("Group connObjectLinks to propagate for membership: {}", groupConnObjectLinks);

        Set<Attribute> attributes = new HashSet<>(task.getAttributes());

        Set<String> groups = new HashSet<>(groupConnObjectLinks);
        Attribute ldapGroups = AttributeUtil.find(getGroupMembershipAttrName(), attributes);

        if (ldapGroups != null) {
          for (Object obj : ldapGroups.getValue()) {
            groups.add(obj.toString());
          }
        }

        attributes.add(AttributeBuilder.build(getGroupMembershipAttrName(), groups));
        task.setAttributes(attributes);
      }
    } else {
      LOG.debug("Not about user, or group mapping missing for resource: not doing anything");
    }
  }
  /**
   * Test method for {@link
   * org.identityconnectors.oracle.OracleAttributesReader#readAuthAttributes(java.util.Set,
   * org.identityconnectors.oracle.OracleUserAttributes)}.
   */
  @Test
  public final void testReadCreateAuthAttributes() {
    final OracleAttributesReader reader =
        new OracleAttributesReader(TestHelpers.createDummyMessages());
    OracleUserAttributes.Builder caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    Set<Attribute> attributes = new HashSet<Attribute>();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_LOCAL));
    attributes.add(AttributeBuilder.buildPassword("myPassword".toCharArray()));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertEquals(OracleAuthentication.LOCAL, caAttributes.getAuth());
    Assert.assertNotNull("Password must not be null", caAttributes.getPassword());

    attributes.clear();
    caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertNull("Should not set authentication to any default value", caAttributes.getAuth());
    Assert.assertNull("Password must be null", caAttributes.getPassword());

    // Test for failures
    attributes.clear();
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, "invalid authentication"));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for invalid authentication");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_GLOBAL));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for missing global name");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(
        AttributeBuilder.build(
            OracleConstants.ORACLE_AUTHENTICATION_ATTR_NAME, OracleConstants.ORACLE_AUTH_GLOBAL));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_GLOBAL_ATTR_NAME, ""));

    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty global name");
    } catch (RuntimeException e) {
    }
  }
 @Test
 public void testNegative() throws Exception {
   SpmlConfiguration config = createConfiguration();
   config.setPassword(new GuardedString("bogus".toCharArray()));
   try {
     createConnector(config);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   config = createConfiguration();
   config.setPostConnectCommand(null);
   SpmlConnector info = createConnector(config);
   try {
     Set<Attribute> attrs = fillInSampleUser(TEST_USER);
     info.create(ObjectClass.ACCOUNT, attrs, null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   try {
     info.delete(ObjectClass.ACCOUNT, new Uid(TEST_USER), null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   try {
     Set<Attribute> attrs = fillInSampleUser(TEST_USER);
     info.update(ObjectClass.ACCOUNT, attrs, null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
   try {
     TestHandler handler = new TestHandler();
     TestHelpers.search(
         info,
         ObjectClass.ACCOUNT,
         new EqualsFilter(AttributeBuilder.build(Uid.NAME, "asdhjfdaslfh alsk fhasldk ")),
         handler,
         null);
     Assert.fail("expected exception");
   } catch (RuntimeException e) {
     // expected
   }
 }
  private ConnectorObject getUser(String accountId, OperationOptions options) throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);

    try {
      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(Name.NAME, accountId)),
          handler,
          options);
      if (!handler.iterator().hasNext()) return null;
      return handler.iterator().next();
    } catch (UnknownUidException e) {
      return null;
    } finally {
      info.dispose();
    }
  }
  /**
   * Test method for {@link
   * org.identityconnectors.oracle.OracleAttributesReader#readRestAttributes(java.util.Set,
   * org.identityconnectors.oracle.OracleUserAttributes)}.
   */
  @Test
  public final void testReadCreateRestAttributes() {
    final OracleAttributesReader reader =
        new OracleAttributesReader(TestHelpers.createDummyMessages());
    OracleUserAttributes.Builder caAttributes = new OracleUserAttributes.Builder();
    caAttributes.setUserName("testUser");
    Set<Attribute> attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.buildPasswordExpired(true));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_ATTR_NAME, "defts"));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_ATTR_NAME, "tempts"));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_PROFILE_ATTR_NAME, "myprofile"));
    attributes.add(AttributeBuilder.buildEnabled(true));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_QUOTA_ATTR_NAME, "30M"));
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_QUOTA_ATTR_NAME, "100M"));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertEquals("defts", caAttributes.getDefaultTableSpace());
    Assert.assertEquals(true, caAttributes.getExpirePassword());
    Assert.assertEquals("tempts", caAttributes.getTempTableSpace());
    Assert.assertEquals("myprofile", caAttributes.getProfile());
    Assert.assertEquals(true, caAttributes.getEnable());
    Assert.assertEquals("30M", caAttributes.getDefaultTSQuota());
    Assert.assertEquals("100M", caAttributes.getTempTSQuota());

    // Test for failures
    attributes.clear();
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_EXPIRED_NAME, "invalid"));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for invalid PASSWORD_EXPIRED_NAME");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(AttributeBuilder.build(OperationalAttributes.PASSWORD_EXPIRED_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null PASSWORD_EXPIRED_NAME");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_ATTR_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null ORACLE_DEF_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes.clear();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_ATTR_NAME, ""));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty ORACLE_DEF_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_ATTR_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null ORACLE_TEMP_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_ATTR_NAME, ""));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty ORACLE_TEMP_TS_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_PROFILE_ATTR_NAME));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for null ORACLE_PROFILE_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_PROFILE_ATTR_NAME, ""));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Must fail for empty ORACLE_PROFILE_ATTR_NAME");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_DEF_TS_QUOTA_ATTR_NAME));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    assertEquals("Must set 0 for null quota", "0", caAttributes.getDefaultTSQuota());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.build(OracleConstants.ORACLE_TEMP_TS_QUOTA_ATTR_NAME, ""));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    assertEquals("Must set 0 for null quota", "0", caAttributes.getTempTSQuota());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildLockOut(true));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertFalse("Enabled must be false for lock_out(true)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildLockOut(false));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertTrue("Enabled must be true for lock_out(false)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(false));
    attributes.add(AttributeBuilder.buildLockOut(true));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertFalse(
        "Enabled must be false for enabled(false) and lock_out(true)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(true));
    attributes.add(AttributeBuilder.buildLockOut(false));
    reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
    Assert.assertTrue(
        "Enabled must be true for enabled(true) and lock_out(false)", caAttributes.getEnable());

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(true));
    attributes.add(AttributeBuilder.buildLockOut(true));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Read attributes must fail for enabled(true) nad lockout(true)");
    } catch (RuntimeException e) {
    }

    attributes = new HashSet<Attribute>();
    caAttributes = new OracleUserAttributes.Builder();
    attributes.add(AttributeBuilder.buildEnabled(false));
    attributes.add(AttributeBuilder.buildLockOut(false));
    try {
      reader.readCreateAttributes(AttributeUtil.toMap(attributes), caAttributes);
      fail("Read attributes must fail for enabled(false) nad lockout(false)");
    } catch (RuntimeException e) {
    }
  }
  @Test
  public void testSimple() throws Exception {
    LdapConnection conn = newConnection(newConfiguration());
    String baseContext = conn.getConfiguration().getBaseContexts()[0];

    String entryDN = "uid=foobar," + baseContext;
    List<SyncDelta> result =
        doTest(
            conn,
            "dn: "
                + entryDN
                + "\n"
                + "changetype: add\n"
                + "objectClass: inetOrgPerson\n"
                + "objectClass: organizationalPerson\n"
                + "objectClass: person\n"
                + "objectClass: top\n"
                + "uid: foobar\n"
                + "cn: Foo Bar\n"
                + "sn: Bar\n",
            1);

    assertEquals(1, result.size());
    SyncDelta delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    ConnectorObject object = delta.getObject();
    assertEquals(new Uid(entryDN), object.getUid());
    assertEquals(new Name(entryDN), object.getName());
    assertEquals(AttributeBuilder.build("uid", "foobar"), object.getAttributeByName("uid"));
    assertEquals(AttributeBuilder.build("cn", "Foo Bar"), object.getAttributeByName("cn"));
    assertEquals(AttributeBuilder.build("sn", "Bar"), object.getAttributeByName("sn"));

    result =
        doTest(conn, "dn: " + entryDN + "\n" + "changeType: modrdn\n" + "newRdn: cn=Foo Bar", 1);
    entryDN = "cn=Foo Bar," + baseContext;

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(new Uid(entryDN), object.getUid());
    assertEquals(new Name(entryDN), object.getName());
    assertEquals(AttributeBuilder.build("uid", emptyList()), object.getAttributeByName("uid"));
    assertEquals(AttributeBuilder.build("cn", "Foo Bar"), object.getAttributeByName("cn"));
    assertEquals(AttributeBuilder.build("sn", "Bar"), object.getAttributeByName("sn"));

    result =
        doTest(
            conn,
            "dn: " + entryDN + "\n" + "changeType: modify\n" + "add: cn\n" + "cn: Dummy User",
            1);

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(
        AttributeBuilder.build("cn", "Foo Bar", "Dummy User"), object.getAttributeByName("cn"));

    result =
        doTest(
            conn,
            "dn: "
                + entryDN
                + "\n"
                + "changeType: modrdn\n"
                + "newRdn: cn=Dummy User\n"
                + "deleteOldRdn: FALSE",
            1);
    entryDN = "cn=Dummy User," + baseContext;

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(new Uid(entryDN), object.getUid());
    assertEquals(new Name(entryDN), object.getName());
    assertEquals(
        AttributeBuilder.build("cn", "Foo Bar", "Dummy User"), object.getAttributeByName("cn"));

    result =
        doTest(
            conn,
            "dn: " + entryDN + "\n" + "changeType: modify\n" + "delete: cn\n" + "cn: Foo Bar",
            1);

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.CREATE_OR_UPDATE, delta.getDeltaType());
    object = delta.getObject();
    assertEquals(AttributeBuilder.build("cn", "Dummy User"), object.getAttributeByName("cn"));

    result = doTest(conn, "dn: " + entryDN + "\n" + "changeType: delete", 1);

    assertEquals(1, result.size());
    delta = result.get(0);
    assertEquals(SyncDeltaType.DELETE, delta.getDeltaType());
    assertEquals(new Uid(entryDN), delta.getUid());
  }
  @Test // @Ignore
  public void testSearchSpecifiedUser() throws Exception {
    SpmlConfiguration config = createConfiguration();
    SpmlConnector info = createConnector(config);
    try {
      Set<Attribute> attrs = fillInSampleUser(TEST_USER);

      deleteUser(TEST_USER, info);
      Uid createdUserUid = info.create(ObjectClass.ACCOUNT, attrs, null);

      // Simple test of EqualsFilter
      //
      TestHandler handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      boolean found = false;
      int count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }
      Assert.assertTrue(count == 1);
      Assert.assertTrue(found);

      // Simple test of StartsWithFilter
      //
      handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new StartsWithFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      found = false;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        Assert.assertTrue(
            AttributeUtil.getStringValue(user.getAttributeByName(ATTR_LASTNAME))
                .startsWith("User"));
      }
      Assert.assertTrue(found);

      // Simple test of EndsWithFilter
      //
      handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new EndsWithFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      found = false;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        Assert.assertTrue(
            AttributeUtil.getStringValue(user.getAttributeByName(ATTR_LASTNAME)).endsWith("User"));
      }
      Assert.assertTrue(found);

      // Simple test of ContainsFilter
      //
      handler = new TestHandler();
      TestHelpers.search(
          info,
          ObjectClass.ACCOUNT,
          new ContainsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
          handler,
          null);
      found = false;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        Assert.assertTrue(
            AttributeUtil.getStringValue(user.getAttributeByName(ATTR_LASTNAME)).contains("User"));
      }
      Assert.assertTrue(found);

      // Simple test of EqualsFilter
      //
      {
        handler = new TestHandler();
        TestHelpers.search(
            info, ObjectClass.ACCOUNT, new EqualsFilter(createdUserUid), handler, null);
        found = false;
        count = 0;
        for (ConnectorObject user : handler) {
          if (TEST_USER.equals(user.getName().getNameValue())) found = true;
          count++;
        }
        Assert.assertTrue(count == 1);
        Assert.assertTrue(found);
      }

      // Test of And
      //
      handler = new TestHandler();
      Filter filter =
          new AndFilter(
              new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
              new EqualsFilter(AttributeBuilder.build(ATTR_FIRSTNAME, "SPML")));
      TestHelpers.search(info, ObjectClass.ACCOUNT, filter, handler, null);
      found = false;
      count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }

      Assert.assertTrue(count == 1);
      Assert.assertTrue(found);

      // Change the first name
      //
      ConnectorObject updateUser = getUser(TEST_USER);
      Set<Attribute> changed = new HashSet<Attribute>();
      changed.add(AttributeBuilder.build(ATTR_FIRSTNAME, "abel"));
      changed.add(updateUser.getUid());
      info.update(ObjectClass.ACCOUNT, changed, null);

      // Test of And, which should fail, since firstname has changed
      //
      handler = new TestHandler();
      filter =
          new AndFilter(
              new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
              new EqualsFilter(AttributeBuilder.build(ATTR_FIRSTNAME, "SPML")));
      TestHelpers.search(info, ObjectClass.ACCOUNT, filter, handler, null);
      found = false;
      count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }
      Assert.assertTrue(count == 0);
      Assert.assertTrue(!found);

      // Test of Or, which should succeed, since lastname has not changed
      //
      handler = new TestHandler();
      filter =
          new OrFilter(
              new EqualsFilter(AttributeBuilder.build(ATTR_LASTNAME, "User")),
              new EqualsFilter(AttributeBuilder.build(ATTR_FIRSTNAME, "SPML")));
      TestHelpers.search(info, ObjectClass.ACCOUNT, filter, handler, null);
      found = false;
      count = 0;
      for (ConnectorObject user : handler) {
        if (TEST_USER.equals(user.getName().getNameValue())) found = true;
        count++;
      }
      Assert.assertTrue(count > 0);
      Assert.assertTrue(found);

    } finally {
      info.dispose();
    }
  }