Search in sources :

Example 91 with LdapName

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

the class DnTest method testName.

/**
 * Test for DIRSERVER-191
 */
@Test
public void testName() throws LdapException, InvalidNameException {
    LdapName jName = new javax.naming.ldap.LdapName("cn=four,cn=three,cn=two,cn=one");
    Dn aName = new Dn("cn=four,cn=three,cn=two,cn=one");
    assertEquals(jName.toString(), "cn=four,cn=three,cn=two,cn=one");
    assertEquals(aName.toString(), "cn=four,cn=three,cn=two,cn=one");
    assertEquals(jName.toString(), aName.toString());
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Example 92 with LdapName

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

the class DnTest method testAddStringName.

/**
 * Test for DIRSERVER-191. The Dn is immutable, thus we can't add a new Rdn
 * to a Dn, it simply creates a new one.
 */
@Test
public void testAddStringName() 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.add("cn=five"));
    assertNotSame(aName, aName.add("cn=five"));
    assertNotSame(jName.toString(), aName.toString());
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Example 93 with LdapName

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

the class DnTest method testStartsWithName.

/**
 * Test for DIRSERVER-191
 */
@Test
public void testStartsWithName() 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");
    assertEquals(jName.startsWith(new LdapName("cn=seven,cn=six,cn=five")), aName.isDescendantOf(new Dn("cn=seven,cn=six,cn=five")));
    assertEquals(jName.startsWith(new LdapName("cn=three,cn=two,cn=one")), aName.isDescendantOf(new Dn("cn=three,cn=two,cn=one")));
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Example 94 with LdapName

use of javax.naming.ldap.LdapName in project Openfire by igniterealtime.

the class CertificateManagerTest method parse.

/**
 * @see <a href="https://stackoverflow.com/questions/2914521/how-to-extract-cn-from-x509certificate-in-java>https://stackoverflow.com/questions/2914521/how-to-extract-cn-from-x509certificate-in-java</a>
 */
public static Set<String> parse(String distinguishedName, String identifier) throws Exception {
    final Set<String> result = new HashSet<>();
    final LdapName ln = new LdapName(distinguishedName);
    for (final Rdn rdn : ln.getRdns()) {
        if (rdn.getType().equalsIgnoreCase(identifier)) {
            result.add(rdn.getValue().toString());
        }
    }
    return result;
}
Also used : Rdn(javax.naming.ldap.Rdn) LdapName(javax.naming.ldap.LdapName)

Example 95 with LdapName

use of javax.naming.ldap.LdapName in project Openfire by igniterealtime.

the class LdapManagerTest method testGetProviderURLTwoHosts.

/**
 * Test if {@link LdapManager#getProviderURL(LdapName)} generates a whitespace-separated value of URLs when
 * more than one connect-host is being provided..
 */
@Test
public void testGetProviderURLTwoHosts() throws Exception {
    // Setup fixture.
    final Map<String, String> properties = new HashMap<>();
    properties.put("ldap.host", "localhost example.org");
    properties.put("ldap.port", "389");
    final LdapManager manager = new LdapManager(properties);
    final LdapName name = new LdapName("ou=people,dc=example,dc=org");
    // Execute system under test.
    final String result = manager.getProviderURL(name);
    // Verify result.
    assertEquals("ldaps://localhost:389/ou=people,dc=example,dc=org ldaps://example.org:389/ou=people,dc=example,dc=org", result);
}
Also used : HashMap(java.util.HashMap) LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Aggregations

LdapName (javax.naming.ldap.LdapName)103 Rdn (javax.naming.ldap.Rdn)48 InvalidNameException (javax.naming.InvalidNameException)32 NamingException (javax.naming.NamingException)26 Attribute (javax.naming.directory.Attribute)22 Attributes (javax.naming.directory.Attributes)14 SearchResult (javax.naming.directory.SearchResult)14 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 LdapContext (javax.naming.ldap.LdapContext)9 IOException (java.io.IOException)7 List (java.util.List)7 X509Certificate (java.security.cert.X509Certificate)6 HashMap (java.util.HashMap)6 TreeSet (java.util.TreeSet)6 SearchControls (javax.naming.directory.SearchControls)6 HashSet (java.util.HashSet)5 NoSuchElementException (java.util.NoSuchElementException)5 InitialLdapContext (javax.naming.ldap.InitialLdapContext)5 X500Principal (javax.security.auth.x500.X500Principal)5