Java Code Examples for org.ldaptive.LdapEntry#addAttribute()

The following examples show how to use org.ldaptive.LdapEntry#addAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserMapperTest.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMappingFromLdapAttributesToUser() throws Exception {
  final LdapEntry entry = new LdapEntry("uid=user123,dc=codenvy,dc=com");
  entry.addAttribute(new LdapAttribute("uid", "user123"));
  entry.addAttribute(new LdapAttribute("cn", "name"));
  entry.addAttribute(new LdapAttribute("mail", "[email protected]"));
  entry.addAttribute(new LdapAttribute("sn", "LastName"));

  final UserMapper userMapper = new UserMapper("uid", "cn", "mail");

  final UserImpl user = userMapper.apply(entry);
  assertEquals(user, new UserImpl("user123", "[email protected]", "name"));
}
 
Example 2
Source File: ProfileMapperTest.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMappingFromLdapAttributesToProfile() throws Exception {
  final LdapEntry entry = new LdapEntry("uid=user123,dc=codenvy,dc=com");
  entry.addAttribute(new LdapAttribute("uid", "user123"));
  entry.addAttribute(new LdapAttribute("cn", "name"));
  entry.addAttribute(new LdapAttribute("mail", "[email protected]"));
  entry.addAttribute(new LdapAttribute("sn", "LastName"));
  entry.addAttribute(new LdapAttribute("givenName", "FirstName"));
  entry.addAttribute(new LdapAttribute("telephoneNumber", "0123456789"));

  @SuppressWarnings("unchecked") // all the values are strings
  final ProfileMapper profileMapper =
      new ProfileMapper(
          "uid",
          new Pair[] {
            Pair.of("lastName", "sn"),
            Pair.of("firstName", "givenName"),
            Pair.of("phone", "telephoneNumber")
          });

  final ProfileImpl profile = profileMapper.apply(entry);
  assertEquals(
      profile,
      new ProfileImpl(
          "user123",
          ImmutableMap.of(
              "lastName", "LastName",
              "firstName", "FirstName",
              "phone", "0123456789")));
}
 
Example 3
Source File: LdapSynchronizerTest.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
private static LdapEntry createUserEntry(String id, String name, String email, String firstName) {
  final LdapEntry newEntry = new LdapEntry("uid=" + id + ",dc=codenvy,dc=com");
  newEntry.addAttribute(new LdapAttribute("uid", id));
  newEntry.addAttribute(new LdapAttribute("cn", name));
  newEntry.addAttribute(new LdapAttribute("mail", email));
  newEntry.addAttribute(new LdapAttribute("givenName", firstName));
  return newEntry;
}
 
Example 4
Source File: LdapSpec.java    From bdt with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param userUid The new user
 * @param userPassword The password for the new user
 * @param userGroup [optional] The group for the new user to be assigned to
 * @throws org.ldaptive.LdapException
 * @throws java.security.NoSuchAlgorithmException
 */
@When("^I create LDAP user '(.+?)' with password '(.+?)'( and assign it to LDAP group '(.+?)')?$")
public void createLDAPUser(String userUid, String userPassword, String userGroup) throws LdapException, NoSuchAlgorithmException {
    String userDn = "uid=" + userUid + "," + ThreadProperty.get("LDAP_USER_DN");
    int userUidNumber = this.commonspec.getLdapUtils().getLDAPMaxUidNumber() + 1;
    String groupName;
    if (userGroup == null) {
        groupName = "stratio";
    } else if (userGroup.equalsIgnoreCase("admin")) {
        groupName = ThreadProperty.get("LDAP_ADMIN_GROUP");
    } else {
        groupName = userGroup;
    }
    int groupGidNumber = this.commonspec.getLdapUtils().getLDAPgidNumber(groupName);
    this.assignLDAPuserToGroup(userUid, groupName);

    LdapEntry newUser = new LdapEntry(userDn);
    newUser.addAttribute(new LdapAttribute("objectClass", "inetOrgPerson", "posixAccount", "shadowAccount"));
    newUser.addAttribute(new LdapAttribute("cn", userUid));
    newUser.addAttribute(new LdapAttribute("sn", userUid));
    newUser.addAttribute(new LdapAttribute("gidNumber", String.valueOf(groupGidNumber)));
    newUser.addAttribute(new LdapAttribute("homeDirectory", "/home/" + userUid));
    newUser.addAttribute(new LdapAttribute("uidNumber", String.valueOf(userUidNumber)));
    newUser.addAttribute(new LdapAttribute("uid", userUid));
    this.commonspec.getLdapUtils().add(newUser);

    AttributeModification newAttr = new AttributeModification(AttributeModificationType.ADD, new LdapAttribute("userPassword", this.commonspec.getLdapUtils().hashPassword(userPassword)));
    this.commonspec.getLdapUtils().modify(userDn, newAttr);
}
 
Example 5
Source File: LdapSpec.java    From bdt with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param groupCn The new group
 * @throws LdapException
 * @throws NoSuchAlgorithmException
 */
@When("^I create LDAP group '(.+?)'$")
public void createLDAPGroup(String groupCn) throws LdapException {
    String groupDn = "cn=" + groupCn + "," + ThreadProperty.get("LDAP_GROUP_DN");
    int groupGidNumber = this.commonspec.getLdapUtils().getLDAPMaxGidNumber() + 1;

    LdapEntry newGroup = new LdapEntry(groupDn);
    newGroup.addAttribute(new LdapAttribute("objectClass", "groupOfNames", "posixGroup"));
    newGroup.addAttribute(new LdapAttribute("cn", groupCn));
    newGroup.addAttribute(new LdapAttribute("gidNumber", String.valueOf(groupGidNumber)));
    newGroup.addAttribute(new LdapAttribute("member", "uid=fake," + ThreadProperty.get("LDAP_USER_DN")));
    newGroup.addAttribute(new LdapAttribute("description", groupCn + " group"));
    newGroup.addAttribute(new LdapAttribute("memberUid", "uid=fake," + ThreadProperty.get("LDAP_USER_DN")));
    this.commonspec.getLdapUtils().add(newGroup);
}