@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();
    }
  }
  @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();
    }
  }
 private void displayUser(ConnectorObject user) {
   Set<Attribute> attributes = user.getAttributes();
   for (Attribute attribute : attributes) {
     System.out.println(attribute.getName());
     List<Object> values = attribute.getValue();
     for (Object value : values) {
       System.out.println("    " + value.getClass().getName() + ":" + value);
     }
   }
 }
Exemplo n.º 4
0
 private List<Object> getValuesSorted(final ConnectorObject resource, final String field) {
   final Attribute value = AttributeUtil.find(field, resource.getAttributes());
   if (value == null || value.getValue() == null || value.getValue().isEmpty()) {
     return Collections.emptyList();
   } else if (value.getValue().size() > 1) {
     List<Object> results = new ArrayList<Object>(value.getValue());
     Collections.sort(results, VALUE_COMPARATOR);
     return results;
   } else {
     return value.getValue();
   }
 }