Search in sources :

Example 71 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 72 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 73 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 74 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 75 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)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