Example usage for javax.naming.ldap LdapName LdapName

List of usage examples for javax.naming.ldap LdapName LdapName

Introduction

In this page you can find the example usage for javax.naming.ldap LdapName LdapName.

Prototype

public LdapName(List<Rdn> rdns) 

Source Link

Document

Constructs an LDAP name given its parsed RDN components.

Usage

From source file:org.sipfoundry.sipxconfig.bulk.ldap.UserMapper.java

public Collection<String> getGroupNames(SearchResult sr) throws NamingException {
    Set<String> groupNames = new HashSet<String>();
    // group names in the current entry
    Attributes attrs = sr.getAttributes();
    Set<String> entryGroups = replaceWhitespace(getValues(attrs, Index.USER_GROUP));
    if (entryGroups != null) {
        groupNames.addAll(entryGroups);//from  w w w .j  ava2 s .  c om
    }

    // group names found in distinguished name
    if (sr.isRelative()) {
        String name = sr.getName();
        LdapName ldapName = new LdapName(name);
        List<Rdn> rdns = ldapName.getRdns();
        for (Rdn rdn : rdns) {
            Attributes rdnsAttributes = rdn.toAttributes();
            Set<String> rdnsGroups = replaceWhitespace(getValues(rdnsAttributes, Index.USER_GROUP));
            if (rdnsGroups != null) {
                groupNames.addAll(rdnsGroups);
            }

        }
    }
    //only if there is no already defined group, add the default user group
    if (groupNames.isEmpty()) {
        String defaultGroupName = getAttrMap().getDefaultGroupName();
        if (defaultGroupName != null) {
            groupNames.add(defaultGroupName);
        }
    }
    return groupNames;
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testNewLdapNameFromLdapName() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_DN_STRING);

    LdapName result = LdapUtils.newLdapName(ldapName);
    assertThat(result).isEqualTo(ldapName);
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testNewLdapNameFromCompositeName() throws InvalidNameException {
    LdapName result = LdapUtils.newLdapName(new CompositeName(EXPECTED_DN_STRING));
    assertThat(result).isEqualTo(new LdapName(EXPECTED_DN_STRING));
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testRemoveFirst() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
    LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=I,OU=M"));

    assertThat(result).isNotSameAs(ldapName);
    assertThat(result).isEqualTo(new LdapName("cn=john.doe, OU=Users,OU=SE,OU=G"));
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testRemoveFirstNoMatch() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
    LdapName result = LdapUtils.removeFirst(ldapName, new LdapName("OU=oooooo,OU=M"));

    assertThat(result).isNotSameAs(ldapName);
    assertThat(result).isEqualTo(ldapName);
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testRemoveFirstEmptyBase() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
    LdapName result = LdapUtils.removeFirst(ldapName, LdapUtils.emptyLdapName());

    assertThat(result).isNotSameAs(ldapName);
    assertThat(result).isEqualTo(ldapName);
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testGetValueNamed() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
    assertThat("john.doe").isEqualTo(LdapUtils.getValue(ldapName, "cn"));
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testGetValueNamedReturnesFirstFound() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
    assertThat("M").isEqualTo(LdapUtils.getValue(ldapName, "ou"));
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testGetValueNamedWithMultivalue() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_MULTIVALUE_DN_STRING);
    assertThat("GR").isEqualTo(LdapUtils.getValue(ldapName, "o"));
}

From source file:org.springframework.ldap.support.LdapUtilsTest.java

@Test
public void testGetValueIndexed() throws InvalidNameException {
    LdapName ldapName = new LdapName(EXPECTED_DN_STRING);
    assertThat("G").isEqualTo(LdapUtils.getValue(ldapName, 2));
}