Search in sources :

Example 66 with LdapName

use of javax.naming.ldap.LdapName in project spring-security by spring-projects.

the class FilterBasedLdapUserSearchTests method subTreeSearchSucceeds.

@Test
public void subTreeSearchSucceeds() throws Exception {
    // Don't set the searchBase, so search from the root.
    FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("", "(cn={0})", this.contextSource);
    locator.setSearchSubtree(true);
    DirContextOperations ben = locator.searchForUser("Ben Alex");
    assertThat(ben.getStringAttribute("uid")).isEqualTo("ben");
    assertThat(ben.getDn()).isEqualTo(new LdapName("uid=ben,ou=people"));
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) LdapName(javax.naming.ldap.LdapName) Test(org.junit.jupiter.api.Test)

Example 67 with LdapName

use of javax.naming.ldap.LdapName in project spring-security by spring-projects.

the class FilterBasedLdapUserSearchTests method basicSearchSucceeds.

@Test
public void basicSearchSucceeds() throws Exception {
    FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", this.contextSource);
    locator.setSearchSubtree(false);
    locator.setSearchTimeLimit(0);
    locator.setDerefLinkFlag(false);
    DirContextOperations bob = locator.searchForUser("bob");
    assertThat(bob.getStringAttribute("uid")).isEqualTo("bob");
    assertThat(bob.getDn()).isEqualTo(new LdapName("uid=bob,ou=people"));
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) LdapName(javax.naming.ldap.LdapName) Test(org.junit.jupiter.api.Test)

Example 68 with LdapName

use of javax.naming.ldap.LdapName in project spring-security by spring-projects.

the class FilterBasedLdapUserSearchTests method searchForNameWithCommaSucceeds.

@Test
public void searchForNameWithCommaSucceeds() throws Exception {
    FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=people", "(uid={0})", this.contextSource);
    locator.setSearchSubtree(false);
    DirContextOperations jerry = locator.searchForUser("jerry");
    assertThat(jerry.getStringAttribute("uid")).isEqualTo("jerry");
    assertThat(jerry.getDn()).isEqualTo(new LdapName("cn=mouse\\, jerry,ou=people"));
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) LdapName(javax.naming.ldap.LdapName) Test(org.junit.jupiter.api.Test)

Example 69 with LdapName

use of javax.naming.ldap.LdapName in project tests by datanucleus.

the class LDAPUtilTest method testLdapName.

public void testLdapName() throws Exception {
    LdapName dn = new LdapName("cn=a,ou=b,dc=c");
    // getRdn()
    assertEquals("cn=a", dn.getRdn(dn.size() - 1).toString());
    // getSuffix()
    assertEquals("cn=a,ou=b,dc=c", dn.getSuffix(0).toString());
    assertEquals("cn=a,ou=b", dn.getSuffix(1).toString());
    assertEquals("cn=a", dn.getSuffix(2).toString());
    assertEquals("", dn.getSuffix(3).toString());
    assertEquals("", dn.getSuffix(dn.size()).toString());
    // getPrefix
    assertEquals("", dn.getPrefix(0).toString());
    assertEquals("dc=c", dn.getPrefix(1).toString());
    assertEquals("ou=b,dc=c", dn.getPrefix(2).toString());
    assertEquals("cn=a,ou=b,dc=c", dn.getPrefix(3).toString());
}
Also used : LdapName(javax.naming.ldap.LdapName)

Example 70 with LdapName

use of javax.naming.ldap.LdapName in project directory-ldap-api by apache.

the class DnTest method testAddAllIntName.

/**
 * Test for DIRSERVER-191
 */
@Test
public void testAddAllIntName() throws LdapException, InvalidNameException {
    LdapName jName = new LdapName("cn=four,cn=three,cn=two,cn=one");
    Dn aName = new Dn("cn=four,cn=three,cn=two,cn=one");
    assertSame(jName, jName.addAll(0, new LdapName("cn=zero,cn=zero.5")));
    assertNotSame(aName, aName.add(new Dn("cn=zero,cn=zero.5")));
    assertNotSame(jName.toString(), aName.toString());
    assertSame(jName, jName.addAll(2, new LdapName("cn=zero,cn=zero.5")));
    assertNotSame(aName, aName.add(new Dn("cn=zero,cn=zero.5")));
    assertNotSame(jName.toString(), aName.toString());
    assertSame(jName, jName.addAll(jName.size(), new LdapName("cn=zero,cn=zero.5")));
    assertNotSame(aName, aName.add(new Dn("cn=zero,cn=zero.5")));
    assertNotSame(jName.toString(), aName.toString());
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Aggregations

LdapName (javax.naming.ldap.LdapName)88 Rdn (javax.naming.ldap.Rdn)44 InvalidNameException (javax.naming.InvalidNameException)27 Attribute (javax.naming.directory.Attribute)18 NamingException (javax.naming.NamingException)17 Attributes (javax.naming.directory.Attributes)12 SearchResult (javax.naming.directory.SearchResult)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)8 X509Certificate (java.security.cert.X509Certificate)6 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 Test (org.junit.jupiter.api.Test)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 HashSet (java.util.HashSet)4 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 TreeSet (java.util.TreeSet)4 SearchControls (javax.naming.directory.SearchControls)4 SSLException (javax.net.ssl.SSLException)4