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();
}
}
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")));
}
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());
}
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);
}
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());
}
Aggregations