Search in sources :

Example 21 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class PersistUtilsTestCase method testGetEntriesAsObjects.

/**
 * Provides test coverage for the {@code getEntriesAsObjects} method.
 * <BR><BR>
 * Access to a directory server instance is required for complete processing.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testGetEntriesAsObjects() throws Exception {
    if (!isDirectoryInstanceAvailable()) {
        return;
    }
    LDAPConnection conn = getAdminConnection();
    conn.add(getTestBaseDN(), getBaseEntryAttributes());
    try {
        final LDAPPersister<TestOrganizationalUnit> persister = LDAPPersister.getInstance(TestOrganizationalUnit.class);
        TestOrganizationalUnit ou = new TestOrganizationalUnit();
        ou.setName("test1");
        ou.setDescription("testLDAPOperations");
        LDAPResult addResult = persister.add(ou, conn, getTestBaseDN());
        assertEquals(addResult.getResultCode(), ResultCode.SUCCESS);
        assertEquals(ou.getLDAPEntry(), new ReadOnlyEntry("dn: ou=test1," + getTestBaseDN(), "objectClass: organizationalUnit", "ou: test1", "description: testLDAPOperations"));
        ou = new TestOrganizationalUnit();
        ou.setName("test2");
        ou.setDescription("testLDAPOperations");
        addResult = persister.add(ou, conn, getTestBaseDN());
        assertEquals(addResult.getResultCode(), ResultCode.SUCCESS);
        assertEquals(ou.getLDAPEntry(), new ReadOnlyEntry("dn: ou=test2," + getTestBaseDN(), "objectClass: organizationalUnit", "ou: test2", "description: testLDAPOperations"));
        DN[] dns = { new DN("ou=test1," + getTestBaseDN()), new DN("ou=test2," + getTestBaseDN()) };
        PersistedObjects<TestOrganizationalUnit> results = PersistUtils.getEntriesAsObjects(dns, TestOrganizationalUnit.class, conn);
        assertNotNull(results);
        ou = results.next();
        assertNotNull(ou);
        assertNotNull(ou.getLDAPEntry());
        assertEquals(ou.getLDAPEntry().getParsedDN(), new DN("ou=test1," + getTestBaseDN()));
        ou = results.next();
        assertNotNull(ou);
        assertNotNull(ou.getLDAPEntry());
        assertEquals(ou.getLDAPEntry().getParsedDN(), new DN("ou=test2," + getTestBaseDN()));
        ou = results.next();
        assertNull(ou);
    } finally {
        DeleteRequest deleteRequest = new DeleteRequest(getTestBaseDN(), new Control[] { new SubtreeDeleteRequestControl() });
        conn.delete(deleteRequest);
        conn.close();
    }
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) DN(com.unboundid.ldap.sdk.DN) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) SubtreeDeleteRequestControl(com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl) Test(org.testng.annotations.Test)

Example 22 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class InMemoryDirectoryServerPasswordTestCase method testUnencodedPasswordWithEncoders.

/**
 * Tests the behavior with an unencoded password.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testUnencodedPasswordWithEncoders() throws Exception {
    final ReadOnlyEntry userEntry = new ReadOnlyEntry("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User", "userPassword: password");
    final MessageDigest sha1Digest = CryptoHelper.getMessageDigest("SHA-1");
    final List<InMemoryPasswordEncoder> passwordEncoders = Arrays.asList(new ClearInMemoryPasswordEncoder("{CLEAR}", null), new ClearInMemoryPasswordEncoder("{HEX}", HexPasswordEncoderOutputFormatter.getLowercaseInstance()), new ClearInMemoryPasswordEncoder("{BASE64}", Base64PasswordEncoderOutputFormatter.getInstance()), new UnsaltedMessageDigestInMemoryPasswordEncoder("{SHA}", Base64PasswordEncoderOutputFormatter.getInstance(), sha1Digest));
    final InMemoryDirectoryServerPassword password = new InMemoryDirectoryServerPassword(new ASN1OctetString("password"), userEntry, "userPassword", passwordEncoders);
    assertNotNull(password.getStoredPassword());
    assertTrue(password.getStoredPassword().equalsIgnoreType(new ASN1OctetString("password")));
    assertNotNull(password.getAttributeName());
    assertEquals(password.getAttributeName(), "userPassword");
    assertFalse(password.isEncoded());
    assertNull(password.getPasswordEncoder());
    assertNotNull(password.getClearPassword());
    assertTrue(password.getClearPassword().equalsIgnoreType(new ASN1OctetString("password")));
    assertTrue(password.matchesClearPassword(new ASN1OctetString("password")));
    assertFalse(password.matchesClearPassword(new ASN1OctetString("wrong")));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) MessageDigest(java.security.MessageDigest) Test(org.testng.annotations.Test)

Example 23 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class InMemoryDirectoryServerConfigTestCase method testRootDSEEntry.

/**
 * Tests the behavior of the methods that make it possible to get and set a
 * specific root DSE entry.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testRootDSEEntry() throws Exception {
    final InMemoryDirectoryServerConfig cfg = new InMemoryDirectoryServerConfig("dc=example,dc=com");
    assertNull(cfg.getRootDSEEntry());
    cfg.setRootDSEEntry(new Entry("dn: ", "objectClass: top", "objectClass: rootDSE", "description: Test root DSE"));
    assertNotNull(cfg.getRootDSEEntry());
    assertEquals(cfg.getRootDSEEntry(), new ReadOnlyEntry("dn: ", "objectClass: top", "objectClass: rootDSE", "description: Test root DSE"));
    cfg.setRootDSEEntry(null);
    assertNull(cfg.getRootDSEEntry());
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Test(org.testng.annotations.Test)

Example 24 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class SaltedMessageDigestInMemoryPasswordEncoderTestCase method testValidatePreEncodedPasswordWithInvalidLength.

/**
 * Tests the behavior when trying to validate an encoded password whose length
 * does not match the digest length.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testValidatePreEncodedPasswordWithInvalidLength() throws Exception {
    final SaltedMessageDigestInMemoryPasswordEncoder encoder = new SaltedMessageDigestInMemoryPasswordEncoder("{SSHA256}", HexPasswordEncoderOutputFormatter.getLowercaseInstance(), CryptoHelper.getMessageDigest("SHA-256"), 16, true, true);
    final ReadOnlyEntry userEntry = new ReadOnlyEntry("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "Cn: Test User", "userPassword: password");
    final List<Modification> mods = Collections.emptyList();
    encoder.ensurePreEncodedPasswordAppearsValid(new ASN1OctetString("{SSHA256}abcdef"), userEntry, mods);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Modification(com.unboundid.ldap.sdk.Modification) Test(org.testng.annotations.Test)

Example 25 with ReadOnlyEntry

use of com.unboundid.ldap.sdk.ReadOnlyEntry in project ldapsdk by pingidentity.

the class SaltedMessageDigestInMemoryPasswordEncoderTestCase method testSHA512WithNoFormatting.

/**
 * Tests the behavior with a 512-bit SHA-2 digest using no output formatting.
 * The salt will be appended to the clear-text password but prepended to the
 * message digest.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSHA512WithNoFormatting() throws Exception {
    final SaltedMessageDigestInMemoryPasswordEncoder encoder = new SaltedMessageDigestInMemoryPasswordEncoder("{SSHA512}", null, CryptoHelper.getMessageDigest("SHA-512"), 32, true, false);
    assertNotNull(encoder.getPrefix());
    assertEquals(encoder.getPrefix(), "{SSHA512}");
    assertNull(encoder.getOutputFormatter());
    assertNotNull(encoder.getDigestAlgorithm());
    assertEquals(encoder.getDigestAlgorithm(), "SHA-512");
    assertEquals(encoder.getDigestLengthBytes(), 64);
    assertEquals(encoder.getNumSaltBytes(), 32);
    assertTrue(encoder.isSaltAfterClearPassword());
    assertFalse(encoder.isSaltAfterMessageDigest());
    final ASN1OctetString clearPassword = new ASN1OctetString("password");
    final ReadOnlyEntry userEntry = new ReadOnlyEntry("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "Cn: Test User", "userPassword: password");
    final List<Modification> mods = Collections.emptyList();
    final ASN1OctetString encodedPassword = encoder.encodePassword(clearPassword, userEntry, mods);
    assertNotNull(encodedPassword);
    assertTrue(encoder.passwordStartsWithPrefix(new ASN1OctetString("{SSHA512}")));
    encoder.ensurePreEncodedPasswordAppearsValid(encodedPassword, userEntry, mods);
    assertTrue(encoder.clearPasswordMatchesEncodedPassword(clearPassword, encodedPassword, userEntry));
    assertFalse(encoder.clearPasswordMatchesEncodedPassword(new ASN1OctetString("wrong"), encodedPassword, userEntry));
    assertFalse(encoder.clearPasswordMatchesEncodedPassword(new ASN1OctetString("Password"), encodedPassword, userEntry));
    assertNotNull(encoder.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Modification(com.unboundid.ldap.sdk.Modification) Test(org.testng.annotations.Test)

Aggregations

ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)94 Test (org.testng.annotations.Test)64 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)41 Entry (com.unboundid.ldap.sdk.Entry)29 DN (com.unboundid.ldap.sdk.DN)27 Attribute (com.unboundid.ldap.sdk.Attribute)25 Modification (com.unboundid.ldap.sdk.Modification)21 LDAPException (com.unboundid.ldap.sdk.LDAPException)18 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)16 Control (com.unboundid.ldap.sdk.Control)14 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)14 NotNull (com.unboundid.util.NotNull)14 RDN (com.unboundid.ldap.sdk.RDN)12 ArrayList (java.util.ArrayList)12 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)9 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)8 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)8 Schema (com.unboundid.ldap.sdk.schema.Schema)8 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)7 ServerSideSortResponseControl (com.unboundid.ldap.sdk.controls.ServerSideSortResponseControl)7