Search in sources :

Example 16 with LdapName

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

the class BeanTest method testCompanyLdap.

@Test
public void testCompanyLdap() throws InvalidNameException {
    final CompanyOrg companyLdap = new CompanyOrg("dn", "name");
    companyLdap.getCompanyTree().contains(companyLdap);
    check(companyLdap, CompanyOrg::setLdapName, CompanyOrg::getLdapName, new LdapName(""));
    check(companyLdap, CompanyOrg::setCompanyTree, CompanyOrg::getCompanyTree, Collections.emptyList());
    Assertions.assertEquals("name".hashCode(), companyLdap.hashCode());
    Assertions.assertEquals(companyLdap, companyLdap);
    Assertions.assertFalse(companyLdap.equals(null));
    Assertions.assertFalse(companyLdap.equals(new CompanyOrg("dn", "name2")));
    Assertions.assertTrue(companyLdap.equals(new CompanyOrg("dn", "name")));
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.jupiter.api.Test)

Example 17 with LdapName

use of javax.naming.ldap.LdapName in project teiid by teiid.

the class LDAPQueryExecution method convertSingleValue.

private Object convertSingleValue(Column modelElement, String modelAttrName, Class<?> modelAttrClass, Object objResult) throws TranslatorException, InvalidNameException {
    if (objResult == null) {
        return null;
    }
    // return null.
    if (!(objResult instanceof String)) {
        return objResult;
    }
    String strResult = (String) objResult;
    // There is no way to differentiate between being unset and being the empty string.
    if (strResult.equals("")) {
        // $NON-NLS-1$
        return null;
    }
    // MPW: 3-11-07: Added support for java.lang.Integer conversion.
    if (TypeFacility.RUNTIME_TYPES.TIMESTAMP.equals(modelAttrClass)) {
        String timestampFormat = modelElement.getFormat();
        if (timestampFormat == null) {
            timestampFormat = LDAPConnectorConstants.ldapTimestampFormat;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(timestampFormat);
        try {
            Date dateResult = dateFormat.parse(strResult);
            Timestamp tsResult = new Timestamp(dateResult.getTime());
            return tsResult;
        } catch (ParseException pe) {
            // $NON-NLS-1$
            throw new TranslatorException(pe, LDAPPlugin.Util.getString("LDAPSyncQueryExecution.timestampParseFailed", modelAttrName));
        }
    // TODO: Extend support for more types in the future.
    // Specifically, add support for byte arrays, since that's actually supported
    // in the underlying data source.
    }
    // extract rdn
    String type = modelElement.getProperty(LDAPExecutionFactory.RDN_TYPE, false);
    if (type != null) {
        String prefix = modelElement.getProperty(LDAPExecutionFactory.DN_PREFIX, false);
        LdapName name = new LdapName(strResult);
        if (prefix != null) {
            if (!name.getPrefix(name.size() - 1).toString().equals(prefix)) {
                throw new InvalidNameException();
            }
        } else if (name.size() > 1) {
            throw new InvalidNameException();
        }
        Rdn rdn = name.getRdn(name.size() - 1);
        if (!rdn.getType().equals(type)) {
            throw new InvalidNameException();
        }
        return rdn.getValue();
    }
    // the Teiid type conversion logic will handle refine from here if necessary
    return strResult;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) TranslatorException(org.teiid.translator.TranslatorException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Timestamp(java.sql.Timestamp) Rdn(javax.naming.ldap.Rdn) Date(java.util.Date) LdapName(javax.naming.ldap.LdapName)

Example 18 with LdapName

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

the class DnTest method testGetPrefixName.

/**
 * Test for DIRSERVER-191
 */
@Test
public void testGetPrefixName() 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.getPrefix(0).toString(), aName.getAncestorOf("cn=four,cn=three,cn=two,cn=one").toString());
    assertEquals(jName.getPrefix(1).toString(), aName.getAncestorOf("cn=four,cn=three,cn=two").toString());
    assertEquals(jName.getPrefix(2).toString(), aName.getAncestorOf("cn=four,cn=three").toString());
    assertEquals(jName.getPrefix(3).toString(), aName.getAncestorOf("cn=four").toString());
    assertEquals(jName.getPrefix(4).toString(), aName.getAncestorOf("").toString());
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Example 19 with LdapName

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

the class DnTest method testAddAllName.

/**
 * Test for DIRSERVER-191
 */
@Test
public void testAddAllName() 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(new LdapName("cn=seven,cn=six")));
    assertNotSame(aName, aName.add(new Dn("cn=seven,cn=six")));
    assertNotSame(jName.toString(), aName.toString());
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Example 20 with LdapName

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

the class DnTest method testGetSuffix.

/**
 * Test for DIRSERVER-191
 */
@Test
public void testGetSuffix() 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.getSuffix(0).toString(), aName.getDescendantOf("").toString());
    assertEquals(jName.getSuffix(1).toString(), aName.getDescendantOf("cn=one").toString());
    assertEquals(jName.getSuffix(2).toString(), aName.getDescendantOf("cn=two,cn=one").toString());
    assertEquals(jName.getSuffix(3).toString(), aName.getDescendantOf("cn=three,cn=two,cn=one").toString());
    assertEquals(jName.getSuffix(4).toString(), aName.getDescendantOf("cn=four,cn=three,cn=two,cn=one").toString());
}
Also used : LdapName(javax.naming.ldap.LdapName) Test(org.junit.Test)

Aggregations

LdapName (javax.naming.ldap.LdapName)86 Rdn (javax.naming.ldap.Rdn)43 InvalidNameException (javax.naming.InvalidNameException)27 Attribute (javax.naming.directory.Attribute)18 NamingException (javax.naming.NamingException)16 Attributes (javax.naming.directory.Attributes)12 SearchResult (javax.naming.directory.SearchResult)10 Test (org.junit.Test)10 IOException (java.io.IOException)6 X509Certificate (java.security.cert.X509Certificate)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 Test (org.junit.jupiter.api.Test)5 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