use of com.unboundid.ldap.sdk.controls.PreReadResponseControl in project ldapsdk by pingidentity.
the class TransactionExtendedOperationHandlerTestCase method testTransactionWithControls.
/**
* Provides a test case for a completely successful transaction that includes
* request and response controls for the associated operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testTransactionWithControls() throws Exception {
final TestUnsolicitedNotificationHandler unsolicitedNotificationHandler = new TestUnsolicitedNotificationHandler();
final LDAPConnectionOptions connectionOptions = new LDAPConnectionOptions();
connectionOptions.setUnsolicitedNotificationHandler(unsolicitedNotificationHandler);
final InMemoryDirectoryServer ds = getTestDS(true, true);
final LDAPConnection conn = ds.getConnection(connectionOptions);
assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final StartTransactionExtendedResult startTxnResult = (StartTransactionExtendedResult) conn.processExtendedOperation(new StartTransactionExtendedRequest());
assertResultCodeEquals(startTxnResult, ResultCode.SUCCESS);
final ASN1OctetString txnID = startTxnResult.getTransactionID();
assertNotNull(txnID);
final TransactionSpecificationRequestControl txnControl = new TransactionSpecificationRequestControl(txnID);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final AddRequest addRequest = new AddRequest("dn: ou=test,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: test");
final PostReadRequestControl postReadRequestControl = new PostReadRequestControl("*", "+");
addRequest.setControls(txnControl, postReadRequestControl);
assertResultCodeEquals(conn, addRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final ModifyRequest modifyRequest = new ModifyRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "changeType: modify", "replace: description", "description: foo");
final PreReadRequestControl preReadRequestControl = new PreReadRequestControl("*", "+");
modifyRequest.setControls(txnControl, preReadRequestControl, postReadRequestControl);
assertResultCodeEquals(conn, modifyRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest("uid=test.user,ou=People,dc=example,dc=com", "uid=test.user", false, "ou=test,dc=example,dc=com");
modifyDNRequest.setControls(txnControl, preReadRequestControl, postReadRequestControl);
assertResultCodeEquals(conn, modifyDNRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final DeleteRequest deleteRequest = new DeleteRequest("ou=People,dc=example,dc=com");
deleteRequest.setControls(txnControl, preReadRequestControl);
assertResultCodeEquals(conn, deleteRequest, ResultCode.SUCCESS);
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=People,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=People,dc=example,dc=com");
ds.assertEntryMissing("ou=test,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=test,dc=example,dc=com");
final EndTransactionExtendedResult endTxnResult = (EndTransactionExtendedResult) conn.processExtendedOperation(new EndTransactionExtendedRequest(txnID, true));
assertResultCodeEquals(endTxnResult, ResultCode.SUCCESS);
assertTrue(endTxnResult.getFailedOpMessageID() < 0);
assertNotNull(endTxnResult.getOperationResponseControls());
assertFalse(endTxnResult.getOperationResponseControls().isEmpty());
ds.assertEntryExists("dc=example,dc=com");
ds.assertEntryExists("ou=test,dc=example,dc=com");
ds.assertEntryExists("uid=test.user,ou=test,dc=example,dc=com");
ds.assertEntryMissing("ou=People,dc=example,dc=com");
ds.assertEntryMissing("uid=test.user,ou=People,dc=example,dc=com");
final Control[] addControls = endTxnResult.getOperationResponseControls(addRequest.getLastMessageID());
assertNotNull(addControls);
assertEquals(addControls.length, 1);
assertTrue(addControls[0] instanceof PostReadResponseControl);
final Control[] modifyControls = endTxnResult.getOperationResponseControls(modifyRequest.getLastMessageID());
assertNotNull(modifyControls);
assertEquals(modifyControls.length, 2);
assertTrue(modifyControls[0] instanceof PreReadResponseControl);
assertTrue(modifyControls[1] instanceof PostReadResponseControl);
final Control[] modifyDNControls = endTxnResult.getOperationResponseControls(modifyDNRequest.getLastMessageID());
assertNotNull(modifyDNControls);
assertEquals(modifyDNControls.length, 2);
assertTrue(modifyDNControls[0] instanceof PreReadResponseControl);
assertTrue(modifyDNControls[1] instanceof PostReadResponseControl);
final Control[] deleteControls = endTxnResult.getOperationResponseControls(deleteRequest.getLastMessageID());
assertNotNull(deleteControls);
assertEquals(deleteControls.length, 1);
assertTrue(deleteControls[0] instanceof PreReadResponseControl);
conn.close();
assertEquals(unsolicitedNotificationHandler.getNotificationCount(), 0);
}
use of com.unboundid.ldap.sdk.controls.PreReadResponseControl in project ldapsdk by pingidentity.
the class InMemoryDirectoryControlsTestCase method testReadEntryControls.
/**
* Provides test coverage for the pre-read and post-read controls.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testReadEntryControls() throws Exception {
final InMemoryDirectoryServer ds = getTestDS(true, true);
final LDAPConnection conn = ds.getConnection();
conn.add("dn: ou=Users,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: Users");
final PreReadRequestControl preReadUserAttrs = new PreReadRequestControl();
final PreReadRequestControl preReadAllAttrs = new PreReadRequestControl("*", "+");
final PreReadRequestControl preReadSpecifiedAttrs = new PreReadRequestControl("objectClass", "cn", "entryUUID");
final PostReadRequestControl postReadUserAttrs = new PostReadRequestControl();
final PostReadRequestControl postReadAllAttrs = new PostReadRequestControl("*", "+");
final PostReadRequestControl postReadSpecifiedAttrs = new PostReadRequestControl("objectClass", "cn", "entryUUID");
// Test an add with a post-read control that should return all user
// attributes.
AddRequest addRequest = new AddRequest(generateUserEntry("test.1", "ou=People,dc=example,dc=com", "Test", "1", "password", new Attribute("description", "foo")));
addRequest.setControls(postReadUserAttrs);
LDAPResult addResult = conn.add(addRequest);
assertEquals(addResult.getResultCode(), ResultCode.SUCCESS);
PostReadResponseControl postReadResponse = PostReadResponseControl.get(addResult);
assertNotNull(postReadResponse);
Entry postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.1,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 1"));
assertTrue(postReadEntry.hasAttributeValue("uid", "test.1"));
assertTrue(postReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(postReadEntry.hasAttributeValue("sn", "1"));
assertTrue(postReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(postReadEntry.hasAttributeValue("description", "foo"));
assertFalse(postReadEntry.hasAttribute("entryDN"));
assertFalse(postReadEntry.hasAttribute("entryUUID"));
assertFalse(postReadEntry.hasAttribute("creatorsName"));
assertFalse(postReadEntry.hasAttribute("createTimestamp"));
assertFalse(postReadEntry.hasAttribute("modifiersName"));
assertFalse(postReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(postReadEntry.hasAttribute("subschemaSubentry"));
// Test an add with a post-read control that should return all user and
// operational attributes.
addRequest = new AddRequest(generateUserEntry("test.2", "ou=People,dc=example,dc=com", "Test", "2", "password", new Attribute("description", "foo")));
addRequest.setControls(postReadAllAttrs);
addResult = conn.add(addRequest);
assertEquals(addResult.getResultCode(), ResultCode.SUCCESS);
postReadResponse = PostReadResponseControl.get(addResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.2,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 2"));
assertTrue(postReadEntry.hasAttributeValue("uid", "test.2"));
assertTrue(postReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(postReadEntry.hasAttributeValue("sn", "2"));
assertTrue(postReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(postReadEntry.hasAttributeValue("description", "foo"));
assertTrue(postReadEntry.hasAttribute("entryDN"));
assertTrue(postReadEntry.hasAttribute("entryUUID"));
assertTrue(postReadEntry.hasAttribute("creatorsName"));
assertTrue(postReadEntry.hasAttribute("createTimestamp"));
assertTrue(postReadEntry.hasAttribute("modifiersName"));
assertTrue(postReadEntry.hasAttribute("modifyTimestamp"));
assertTrue(postReadEntry.hasAttribute("subschemaSubentry"));
// Test an add with a post-read control that should return only a specified
// set of attributes.
addRequest = new AddRequest(generateUserEntry("test.3", "ou=People,dc=example,dc=com", "Test", "3", "password", new Attribute("description", "foo")));
addRequest.setControls(postReadSpecifiedAttrs);
addResult = conn.add(addRequest);
assertEquals(addResult.getResultCode(), ResultCode.SUCCESS);
postReadResponse = PostReadResponseControl.get(addResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.3,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 3"));
assertFalse(postReadEntry.hasAttribute("uid"));
assertFalse(postReadEntry.hasAttribute("givenName"));
assertFalse(postReadEntry.hasAttribute("sn"));
assertFalse(postReadEntry.hasAttribute("userPassword"));
assertFalse(postReadEntry.hasAttribute("description"));
assertFalse(postReadEntry.hasAttribute("entryDN"));
assertTrue(postReadEntry.hasAttribute("entryUUID"));
assertFalse(postReadEntry.hasAttribute("creatorsName"));
assertFalse(postReadEntry.hasAttribute("createTimestamp"));
assertFalse(postReadEntry.hasAttribute("modifiersName"));
assertFalse(postReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(postReadEntry.hasAttribute("subschemaSubentry"));
// Test a modify with pre-read and post-read controls that should return all
// user attributes.
ModifyRequest modifyRequest = new ModifyRequest("dn: uid=test.1,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: bar");
modifyRequest.setControls(preReadUserAttrs, postReadUserAttrs);
LDAPResult modifyResult = conn.modify(modifyRequest);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
PreReadResponseControl preReadResponse = PreReadResponseControl.get(modifyResult);
assertNotNull(preReadResponse);
Entry preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.1,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 1"));
assertTrue(preReadEntry.hasAttributeValue("uid", "test.1"));
assertTrue(preReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(preReadEntry.hasAttributeValue("sn", "1"));
assertTrue(preReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(preReadEntry.hasAttributeValue("description", "foo"));
assertFalse(preReadEntry.hasAttribute("entryDN"));
assertFalse(preReadEntry.hasAttribute("entryUUID"));
assertFalse(preReadEntry.hasAttribute("creatorsName"));
assertFalse(preReadEntry.hasAttribute("createTimestamp"));
assertFalse(preReadEntry.hasAttribute("modifiersName"));
assertFalse(preReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(preReadEntry.hasAttribute("subschemaSubentry"));
postReadResponse = PostReadResponseControl.get(modifyResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.1,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 1"));
assertTrue(postReadEntry.hasAttributeValue("uid", "test.1"));
assertTrue(postReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(postReadEntry.hasAttributeValue("sn", "1"));
assertTrue(postReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(postReadEntry.hasAttributeValue("description", "bar"));
assertFalse(postReadEntry.hasAttribute("entryDN"));
assertFalse(postReadEntry.hasAttribute("entryUUID"));
assertFalse(postReadEntry.hasAttribute("creatorsName"));
assertFalse(postReadEntry.hasAttribute("createTimestamp"));
assertFalse(postReadEntry.hasAttribute("modifiersName"));
assertFalse(postReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(postReadEntry.hasAttribute("subschemaSubentry"));
// Test a modify with pre-read and post-read controls that should return all
// user and operational attributes. Sleep before processing the modify so
// that we can ensure that the pre-read and post-read versions of the entry
// will have different modifyTimestamp values.
Thread.sleep(20L);
modifyRequest = new ModifyRequest("dn: uid=test.2,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: bar");
modifyRequest.setControls(preReadAllAttrs, postReadAllAttrs);
modifyResult = conn.modify(modifyRequest);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(modifyResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.2,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 2"));
assertTrue(preReadEntry.hasAttributeValue("uid", "test.2"));
assertTrue(preReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(preReadEntry.hasAttributeValue("sn", "2"));
assertTrue(preReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(preReadEntry.hasAttributeValue("description", "foo"));
assertTrue(preReadEntry.hasAttribute("entryDN"));
assertTrue(preReadEntry.hasAttribute("entryUUID"));
assertTrue(preReadEntry.hasAttribute("creatorsName"));
assertTrue(preReadEntry.hasAttribute("createTimestamp"));
assertTrue(preReadEntry.hasAttribute("modifiersName"));
assertTrue(preReadEntry.hasAttribute("modifyTimestamp"));
assertTrue(preReadEntry.hasAttribute("subschemaSubentry"));
postReadResponse = PostReadResponseControl.get(modifyResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.2,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 2"));
assertTrue(postReadEntry.hasAttributeValue("uid", "test.2"));
assertTrue(postReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(postReadEntry.hasAttributeValue("sn", "2"));
assertTrue(postReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(postReadEntry.hasAttributeValue("description", "bar"));
assertTrue(postReadEntry.hasAttribute("entryDN"));
assertTrue(postReadEntry.hasAttribute("entryUUID"));
assertTrue(postReadEntry.hasAttribute("creatorsName"));
assertTrue(postReadEntry.hasAttribute("createTimestamp"));
assertTrue(postReadEntry.hasAttribute("modifiersName"));
assertTrue(postReadEntry.hasAttribute("modifyTimestamp"));
assertTrue(postReadEntry.hasAttribute("subschemaSubentry"));
final Date preReadModifyTimestamp = preReadEntry.getAttributeValueAsDate("modifyTimestamp");
final Date postReadModifyTimestamp = postReadEntry.getAttributeValueAsDate("modifyTimestamp");
assertNotNull(preReadModifyTimestamp);
assertNotNull(postReadModifyTimestamp);
assertFalse(preReadModifyTimestamp.equals(postReadModifyTimestamp));
// Test a modify with pre-read and post-read controls that should return
// only a specified set of attributes.
modifyRequest = new ModifyRequest("dn: uid=test.3,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: bar");
modifyRequest.setControls(preReadSpecifiedAttrs, postReadSpecifiedAttrs);
modifyResult = conn.modify(modifyRequest);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(modifyResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.3,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 3"));
assertFalse(preReadEntry.hasAttributeValue("uid", "test.3"));
assertFalse(preReadEntry.hasAttributeValue("givenName", "Test"));
assertFalse(preReadEntry.hasAttributeValue("sn", "3"));
assertFalse(preReadEntry.hasAttributeValue("userPassword", "password"));
assertFalse(preReadEntry.hasAttributeValue("description", "foo"));
assertFalse(preReadEntry.hasAttribute("entryDN"));
assertTrue(preReadEntry.hasAttribute("entryUUID"));
assertFalse(preReadEntry.hasAttribute("creatorsName"));
assertFalse(preReadEntry.hasAttribute("createTimestamp"));
assertFalse(preReadEntry.hasAttribute("modifiersName"));
assertFalse(preReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(preReadEntry.hasAttribute("subschemaSubentry"));
postReadResponse = PostReadResponseControl.get(modifyResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.3,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 3"));
assertFalse(postReadEntry.hasAttributeValue("uid", "test.3"));
assertFalse(postReadEntry.hasAttributeValue("givenName", "Test"));
assertFalse(postReadEntry.hasAttributeValue("sn", "3"));
assertFalse(postReadEntry.hasAttributeValue("userPassword", "password"));
assertFalse(postReadEntry.hasAttributeValue("description", "bar"));
assertFalse(postReadEntry.hasAttribute("entryDN"));
assertTrue(postReadEntry.hasAttribute("entryUUID"));
assertFalse(postReadEntry.hasAttribute("creatorsName"));
assertFalse(postReadEntry.hasAttribute("createTimestamp"));
assertFalse(postReadEntry.hasAttribute("modifiersName"));
assertFalse(postReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(postReadEntry.hasAttribute("subschemaSubentry"));
// Test a modify DN with pre-read and post-read controls that should return
// all user attributes.
ModifyDNRequest modifyDNRequest = new ModifyDNRequest("uid=test.1,ou=People,dc=example,dc=com", "cn=Test 1", false);
modifyDNRequest.setControls(preReadUserAttrs, postReadUserAttrs);
LDAPResult modifyDNResult = conn.modifyDN(modifyDNRequest);
assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(modifyDNResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.1,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 1"));
assertTrue(preReadEntry.hasAttributeValue("uid", "test.1"));
assertTrue(preReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(preReadEntry.hasAttributeValue("sn", "1"));
assertTrue(preReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(preReadEntry.hasAttributeValue("description", "bar"));
assertFalse(preReadEntry.hasAttribute("entryDN"));
assertFalse(preReadEntry.hasAttribute("entryUUID"));
assertFalse(preReadEntry.hasAttribute("creatorsName"));
assertFalse(preReadEntry.hasAttribute("createTimestamp"));
assertFalse(preReadEntry.hasAttribute("modifiersName"));
assertFalse(preReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(preReadEntry.hasAttribute("subschemaSubentry"));
postReadResponse = PostReadResponseControl.get(modifyDNResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("cn=Test 1,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 1"));
assertTrue(postReadEntry.hasAttributeValue("uid", "test.1"));
assertTrue(postReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(postReadEntry.hasAttributeValue("sn", "1"));
assertTrue(postReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(postReadEntry.hasAttributeValue("description", "bar"));
assertFalse(postReadEntry.hasAttribute("entryDN"));
assertFalse(postReadEntry.hasAttribute("entryUUID"));
assertFalse(postReadEntry.hasAttribute("creatorsName"));
assertFalse(postReadEntry.hasAttribute("createTimestamp"));
assertFalse(postReadEntry.hasAttribute("modifiersName"));
assertFalse(postReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(postReadEntry.hasAttribute("subschemaSubentry"));
// Test a modify DN with pre-read and post-read controls that should return
// all user and operational attributes.
modifyDNRequest = new ModifyDNRequest("uid=test.2,ou=People,dc=example,dc=com", "uid=test.two", true);
modifyDNRequest.setControls(preReadAllAttrs, postReadAllAttrs);
modifyDNResult = conn.modifyDN(modifyDNRequest);
assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(modifyDNResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.2,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 2"));
assertTrue(preReadEntry.hasAttributeValue("uid", "test.2"));
assertFalse(preReadEntry.hasAttributeValue("uid", "test.two"));
assertTrue(preReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(preReadEntry.hasAttributeValue("sn", "2"));
assertTrue(preReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(preReadEntry.hasAttributeValue("description", "bar"));
assertTrue(preReadEntry.hasAttribute("entryDN"));
assertTrue(preReadEntry.hasAttribute("entryUUID"));
assertTrue(preReadEntry.hasAttribute("creatorsName"));
assertTrue(preReadEntry.hasAttribute("createTimestamp"));
assertTrue(preReadEntry.hasAttribute("modifiersName"));
assertTrue(preReadEntry.hasAttribute("modifyTimestamp"));
assertTrue(preReadEntry.hasAttribute("subschemaSubentry"));
postReadResponse = PostReadResponseControl.get(modifyDNResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.two,ou=People,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 2"));
assertFalse(postReadEntry.hasAttributeValue("uid", "test.2"));
assertTrue(postReadEntry.hasAttributeValue("uid", "test.two"));
assertTrue(postReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(postReadEntry.hasAttributeValue("sn", "2"));
assertTrue(postReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(postReadEntry.hasAttributeValue("description", "bar"));
assertTrue(postReadEntry.hasAttribute("entryDN"));
assertTrue(postReadEntry.hasAttribute("entryUUID"));
assertTrue(postReadEntry.hasAttribute("creatorsName"));
assertTrue(postReadEntry.hasAttribute("createTimestamp"));
assertTrue(postReadEntry.hasAttribute("modifiersName"));
assertTrue(postReadEntry.hasAttribute("modifyTimestamp"));
assertTrue(postReadEntry.hasAttribute("subschemaSubentry"));
// Test a modify DN with pre-read and post-read controls that should return
// only a specified set of attributes.
modifyDNRequest = new ModifyDNRequest("uid=test.3,ou=People,dc=example,dc=com", "uid=test.3", true, "ou=Users,dc=example,dc=com");
modifyDNRequest.setControls(preReadSpecifiedAttrs, postReadSpecifiedAttrs);
modifyDNResult = conn.modifyDN(modifyDNRequest);
assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(modifyDNResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.3,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 3"));
assertFalse(preReadEntry.hasAttribute("uid"));
assertFalse(preReadEntry.hasAttribute("givenName"));
assertFalse(preReadEntry.hasAttribute("sn"));
assertFalse(preReadEntry.hasAttribute("userPassword"));
assertFalse(preReadEntry.hasAttribute("description"));
assertFalse(preReadEntry.hasAttribute("entryDN"));
assertTrue(preReadEntry.hasAttribute("entryUUID"));
assertFalse(preReadEntry.hasAttribute("creatorsName"));
assertFalse(preReadEntry.hasAttribute("createTimestamp"));
assertFalse(preReadEntry.hasAttribute("modifiersName"));
assertFalse(preReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(preReadEntry.hasAttribute("subschemaSubentry"));
postReadResponse = PostReadResponseControl.get(modifyDNResult);
assertNotNull(postReadResponse);
postReadEntry = postReadResponse.getEntry();
assertEquals(postReadEntry.getParsedDN(), new DN("uid=test.3,ou=Users,dc=example,dc=com"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(postReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(postReadEntry.hasAttributeValue("cn", "Test 3"));
assertFalse(postReadEntry.hasAttribute("uid"));
assertFalse(postReadEntry.hasAttribute("givenName"));
assertFalse(postReadEntry.hasAttribute("sn"));
assertFalse(postReadEntry.hasAttribute("userPassword"));
assertFalse(postReadEntry.hasAttribute("description"));
assertFalse(postReadEntry.hasAttribute("entryDN"));
assertTrue(postReadEntry.hasAttribute("entryUUID"));
assertFalse(postReadEntry.hasAttribute("creatorsName"));
assertFalse(postReadEntry.hasAttribute("createTimestamp"));
assertFalse(postReadEntry.hasAttribute("modifiersName"));
assertFalse(postReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(postReadEntry.hasAttribute("subschemaSubentry"));
// Test a delete with a pre-read control that should return all user
// attributes.
DeleteRequest deleteRequest = new DeleteRequest("cn=Test 1,ou=People,dc=example,dc=com");
deleteRequest.setControls(preReadUserAttrs);
LDAPResult deleteResult = conn.delete(deleteRequest);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(deleteResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("cn=Test 1,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 1"));
assertTrue(preReadEntry.hasAttributeValue("uid", "test.1"));
assertTrue(preReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(preReadEntry.hasAttributeValue("sn", "1"));
assertTrue(preReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(preReadEntry.hasAttributeValue("description", "bar"));
assertFalse(preReadEntry.hasAttribute("entryDN"));
assertFalse(preReadEntry.hasAttribute("entryUUID"));
assertFalse(preReadEntry.hasAttribute("creatorsName"));
assertFalse(preReadEntry.hasAttribute("createTimestamp"));
assertFalse(preReadEntry.hasAttribute("modifiersName"));
assertFalse(preReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(preReadEntry.hasAttribute("subschemaSubentry"));
// Test a delete with a pre-read control that should return all user and
// operational attributes.
deleteRequest = new DeleteRequest("uid=test.two,ou=People,dc=example,dc=com");
deleteRequest.setControls(preReadAllAttrs);
deleteResult = conn.delete(deleteRequest);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(deleteResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.two,ou=People,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 2"));
assertFalse(preReadEntry.hasAttributeValue("uid", "test.2"));
assertTrue(preReadEntry.hasAttributeValue("uid", "test.two"));
assertTrue(preReadEntry.hasAttributeValue("givenName", "Test"));
assertTrue(preReadEntry.hasAttributeValue("sn", "2"));
assertTrue(preReadEntry.hasAttributeValue("userPassword", "password"));
assertTrue(preReadEntry.hasAttributeValue("description", "bar"));
assertTrue(preReadEntry.hasAttribute("entryDN"));
assertTrue(preReadEntry.hasAttribute("entryUUID"));
assertTrue(preReadEntry.hasAttribute("creatorsName"));
assertTrue(preReadEntry.hasAttribute("createTimestamp"));
assertTrue(preReadEntry.hasAttribute("modifiersName"));
assertTrue(preReadEntry.hasAttribute("modifyTimestamp"));
assertTrue(preReadEntry.hasAttribute("subschemaSubentry"));
// Test a delete with a pre-read control that should return only a specified
// set of attributes.
deleteRequest = new DeleteRequest("uid=test.3,ou=Users,dc=example,dc=com");
deleteRequest.setControls(preReadSpecifiedAttrs);
deleteResult = conn.delete(deleteRequest);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
preReadResponse = PreReadResponseControl.get(deleteResult);
assertNotNull(preReadResponse);
preReadEntry = preReadResponse.getEntry();
assertEquals(preReadEntry.getParsedDN(), new DN("uid=test.3,ou=Users,dc=example,dc=com"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "top"));
assertTrue(preReadEntry.hasAttributeValue("objectClass", "inetOrgPerson"));
assertTrue(preReadEntry.hasAttributeValue("cn", "Test 3"));
assertFalse(preReadEntry.hasAttribute("uid"));
assertFalse(preReadEntry.hasAttribute("givenName"));
assertFalse(preReadEntry.hasAttribute("sn"));
assertFalse(preReadEntry.hasAttribute("userPassword"));
assertFalse(preReadEntry.hasAttribute("description"));
assertFalse(preReadEntry.hasAttribute("entryDN"));
assertTrue(preReadEntry.hasAttribute("entryUUID"));
assertFalse(preReadEntry.hasAttribute("creatorsName"));
assertFalse(preReadEntry.hasAttribute("createTimestamp"));
assertFalse(preReadEntry.hasAttribute("modifiersName"));
assertFalse(preReadEntry.hasAttribute("modifyTimestamp"));
assertFalse(preReadEntry.hasAttribute("subschemaSubentry"));
conn.close();
}
use of com.unboundid.ldap.sdk.controls.PreReadResponseControl in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerLDAPInterfaceTestCase method testModify.
/**
* Provides test coverage for the methods that can be used to process modify
* operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModify() throws Exception {
ds.restoreSnapshot(snapshot);
// Test the method that takes a DN and a single modification.
LDAPResult modifyResult = ds.modify("dc=example,dc=com", new Modification(ModificationType.REPLACE, "description", "mod 1"));
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a DN and an array of modifications.
modifyResult = ds.modify("dc=example,dc=com", new Modification(ModificationType.DELETE, "description", "mod 1"), new Modification(ModificationType.ADD, "description", "mod 2"));
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a DN and a list of modifications.
modifyResult = ds.modify("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.DELETE, "description", "mod 2"), new Modification(ModificationType.ADD, "description", "mod 3")));
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes an LDIF representation of the modification.
modifyResult = ds.modify("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: mod 4");
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a modify request, with controls.
final ModifyRequest modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: mod 5");
modifyRequest.addControl(new PreReadRequestControl("*", "+"));
modifyRequest.addControl(new PostReadRequestControl("*", "+"));
modifyResult = ds.modify(modifyRequest);
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
assertTrue(modifyResult.hasResponseControl(PreReadResponseControl.PRE_READ_RESPONSE_OID));
final PreReadResponseControl preReadResponse = PreReadResponseControl.get(modifyResult);
assertNotNull(preReadResponse);
assertTrue(preReadResponse.getEntry().hasAttributeValue("description", "mod 4"));
assertTrue(modifyResult.hasResponseControl(PostReadResponseControl.POST_READ_RESPONSE_OID));
final PostReadResponseControl postReadResponse = PostReadResponseControl.get(modifyResult);
assertNotNull(postReadResponse);
assertTrue(postReadResponse.getEntry().hasAttributeValue("description", "mod 5"));
// Test the method that takes a read-only modify request, with controls.
final ReadOnlyModifyRequest readOnlyModifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: mod 6");
modifyResult = ds.modify(readOnlyModifyRequest);
assertNotNull(modifyResult);
assertEquals(modifyResult.getResultCode(), ResultCode.SUCCESS);
}
use of com.unboundid.ldap.sdk.controls.PreReadResponseControl in project ldapsdk by pingidentity.
the class ResultUtilsTestCase method getFormatResponseControlData.
/**
* Retrieves a set of data for testing the {@code formatResponseControl}
* method.
*
* @return The test data.
*
* @throws Exception If an unexpected problem occurs.
*/
@DataProvider(name = "formatResponseControlData")
public Iterator<Object[]> getFormatResponseControlData() throws Exception {
final LinkedList<Object[]> resultList = new LinkedList<Object[]>();
// A generic response control with no value.
resultList.add(new Object[] { new Control("1.2.3.4"), Arrays.asList("# Response Control:", "# OID: 1.2.3.4", "# Is Critical: false") });
// A generic response control with a value.
resultList.add(new Object[] { new Control("1.2.3.4", true, new ASN1OctetString("control value")), Arrays.asList("# Response Control:", "# OID: 1.2.3.4", "# Is Critical: true", "# Raw Value:", "# 63 6f 6e 74 72 6f 6c 20 76 61 6c 75 " + "65 control value") });
// A valid authorization identity response control.
resultList.add(new Object[] { new AuthorizationIdentityResponseControl("u:test.user"), Arrays.asList("# Authorization Identity Response Control:", "# OID: " + AuthorizationIdentityResponseControl.AUTHORIZATION_IDENTITY_RESPONSE_OID, "# Authorization ID: u:test.user") });
// An invalid authorization identity response control.
resultList.add(new Object[] { new Control(AuthorizationIdentityResponseControl.AUTHORIZATION_IDENTITY_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + AuthorizationIdentityResponseControl.AUTHORIZATION_IDENTITY_RESPONSE_OID, "# Is Critical: false") });
// A valid content synchronization done response control.
resultList.add(new Object[] { new ContentSyncDoneControl(new ASN1OctetString("cookie"), true), Arrays.asList("# Content Synchronization Done Response Control:", "# OID: " + ContentSyncDoneControl.SYNC_DONE_OID, "# Refresh Deletes: true", "# Cookie Data:", "# 63 6f 6f 6b 69 " + "65 cookie") });
// An invalid content synchronization done response control.
resultList.add(new Object[] { new Control(ContentSyncDoneControl.SYNC_DONE_OID), Arrays.asList("# Response Control:", "# OID: " + ContentSyncDoneControl.SYNC_DONE_OID, "# Is Critical: false") });
// A valid content synchronization state response control.
final UUID uuid = CryptoHelper.getRandomUUID();
resultList.add(new Object[] { new ContentSyncStateControl(ContentSyncState.MODIFY, uuid, new ASN1OctetString("cookie")), Arrays.asList("# Content Synchronization State Response Control:", "# OID: " + ContentSyncStateControl.SYNC_STATE_OID, "# Entry UUID: " + uuid.toString(), "# Synchronization State: MODIFY", "# Cookie Data:", "# 63 6f 6f 6b 69 " + "65 cookie") });
// An invalid content synchronization state response control.
resultList.add(new Object[] { new Control(ContentSyncStateControl.SYNC_STATE_OID), Arrays.asList("# Response Control:", "# OID: " + ContentSyncStateControl.SYNC_STATE_OID, "# Is Critical: false") });
// A valid entry change notification control.
resultList.add(new Object[] { new EntryChangeNotificationControl(PersistentSearchChangeType.MODIFY_DN, "ou=People,dc=example,dc=com", 123456789L), Arrays.asList("# Entry Change Notification Control:", "# OID: " + EntryChangeNotificationControl.ENTRY_CHANGE_NOTIFICATION_OID, "# Change Type: moddn", "# Change Number: 123456789", "# Previous DN: ou=People,dc=example,dc=com") });
// An invalid entry change notification control.
resultList.add(new Object[] { new Control(EntryChangeNotificationControl.ENTRY_CHANGE_NOTIFICATION_OID), Arrays.asList("# Response Control:", "# OID: " + EntryChangeNotificationControl.ENTRY_CHANGE_NOTIFICATION_OID, "# Is Critical: false") });
// A valid password expired control.
resultList.add(new Object[] { new PasswordExpiredControl(), Arrays.asList("# Password Expired Response Control:", "# OID: " + PasswordExpiredControl.PASSWORD_EXPIRED_OID) });
// An invalid password expired control.
resultList.add(new Object[] { new Control(PasswordExpiredControl.PASSWORD_EXPIRED_OID, false, new ASN1OctetString("control value")), Arrays.asList("# Response Control:", "# OID: " + PasswordExpiredControl.PASSWORD_EXPIRED_OID, "# Is Critical: false", "# Raw Value:", "# 63 6f 6e 74 72 6f 6c 20 76 61 6c 75 " + "65 control value") });
// A valid password expiring control.
resultList.add(new Object[] { new PasswordExpiringControl(12345), Arrays.asList("# Password Expiring Response Control:", "# OID: " + PasswordExpiringControl.PASSWORD_EXPIRING_OID, "# Seconds Until Expiration: 12345") });
// An invalid password expiring control.
resultList.add(new Object[] { new Control(PasswordExpiringControl.PASSWORD_EXPIRING_OID), Arrays.asList("# Response Control:", "# OID: " + PasswordExpiringControl.PASSWORD_EXPIRING_OID, "# Is Critical: false") });
// A valid post-read response control.
resultList.add(new Object[] { new PostReadResponseControl(new ReadOnlyEntry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example")), Arrays.asList("# Post-Read Response Control:", "# OID: " + PostReadResponseControl.POST_READ_RESPONSE_OID, "# Post-Read Entry:", "# dn: dc=example,dc=com", "# objectClass: top", "# objectClass: domain", "# dc: example") });
// An invalid post-read response control.
resultList.add(new Object[] { new Control(PostReadResponseControl.POST_READ_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + PostReadResponseControl.POST_READ_RESPONSE_OID, "# Is Critical: false") });
// A valid pre-read response control.
resultList.add(new Object[] { new PreReadResponseControl(new ReadOnlyEntry("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example")), Arrays.asList("# Pre-Read Response Control:", "# OID: " + PreReadResponseControl.PRE_READ_RESPONSE_OID, "# Pre-Read Entry:", "# dn: dc=example,dc=com", "# objectClass: top", "# objectClass: domain", "# dc: example") });
// An invalid pre-read response control.
resultList.add(new Object[] { new Control(PreReadResponseControl.PRE_READ_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + PreReadResponseControl.PRE_READ_RESPONSE_OID, "# Is Critical: false") });
// A valid server-side sort response control.
resultList.add(new Object[] { new ServerSideSortResponseControl(ResultCode.INVALID_ATTRIBUTE_SYNTAX, "objectClass", false), Arrays.asList("# Server-Side Sort Response Control:", "# OID: " + ServerSideSortResponseControl.SERVER_SIDE_SORT_RESPONSE_OID, "# Result Code: 21 (invalid attribute syntax)", "# Attribute Name: objectClass") });
// An invalid server-side sort response control.
resultList.add(new Object[] { new Control(ServerSideSortResponseControl.SERVER_SIDE_SORT_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + ServerSideSortResponseControl.SERVER_SIDE_SORT_RESPONSE_OID, "# Is Critical: false") });
// A valid simple paged results response control.
resultList.add(new Object[] { new SimplePagedResultsControl(12345, new ASN1OctetString("cookie")), Arrays.asList("# Simple Paged Results Response Control:", "# OID: " + SimplePagedResultsControl.PAGED_RESULTS_OID, "# Estimated Total Result Set Size: 12345", "# Cookie Data:", "# 63 6f 6f 6b 69 " + "65 cookie") });
// An invalid simple paged results response control.
resultList.add(new Object[] { new Control(SimplePagedResultsControl.PAGED_RESULTS_OID), Arrays.asList("# Response Control:", "# OID: " + SimplePagedResultsControl.PAGED_RESULTS_OID, "# Is Critical: false") });
// A valid virtual list view response control.
resultList.add(new Object[] { new VirtualListViewResponseControl(12345, 67890, ResultCode.SUCCESS, new ASN1OctetString("cookie")), Arrays.asList("# Virtual List View Response Control:", "# OID: " + VirtualListViewResponseControl.VIRTUAL_LIST_VIEW_RESPONSE_OID, "# Result Code: 0 (success)", "# Estimated Content Count: 67890", "# Target Position: 12345", "# Context ID:", "# 63 6f 6f 6b 69 " + "65 cookie") });
// An invalid virtual list view response control.
resultList.add(new Object[] { new Control(VirtualListViewResponseControl.VIRTUAL_LIST_VIEW_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + VirtualListViewResponseControl.VIRTUAL_LIST_VIEW_RESPONSE_OID, "# Is Critical: false") });
// A valid account usable response control that indicates the account is
// usable.
resultList.add(new Object[] { new AccountUsableResponseControl(12345), Arrays.asList("# Account Usable Response Control:", "# OID: " + AccountUsableResponseControl.ACCOUNT_USABLE_RESPONSE_OID, "# Account Is Usable: true", "# Password Is Expired: false", "# Must Change Password: false", "# Account Is Inactive: false", "# Seconds Until Password Expiration: 12345") });
// A valid account usable response control that indicates the account is not
// usable.
resultList.add(new Object[] { new AccountUsableResponseControl(true, true, true, 12345, 67890), Arrays.asList("# Account Usable Response Control:", "# OID: " + AccountUsableResponseControl.ACCOUNT_USABLE_RESPONSE_OID, "# Account Is Usable: false", "# Unusable Reasons:", "# The account has been locked or deactivated.", "# The password must be changed before any " + "other operations will be allowed.", "# The password is expired.", "# 12345 grace logins are available.", "# The account will be automatically unlocked " + "in 67890 seconds.", "# Password Is Expired: true", "# Must Change Password: true", "# Account Is Inactive: true", "# Remaining Grace Logins: 12345", "# Seconds Until Account Unlock: 67890") });
// An invalid account usable response control.
resultList.add(new Object[] { new Control(AccountUsableResponseControl.ACCOUNT_USABLE_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + AccountUsableResponseControl.ACCOUNT_USABLE_RESPONSE_OID, "# Is Critical: false") });
// A valid assured replication response control that indicates the account
// is usable.
resultList.add(new Object[] { new AssuredReplicationResponseControl(AssuredReplicationLocalLevel.PROCESSED_ALL_SERVERS, true, "local message", AssuredReplicationRemoteLevel.RECEIVED_ANY_REMOTE_LOCATION, false, "remote message", "csn", Arrays.asList(new AssuredReplicationServerResult(AssuredReplicationServerResultCode.COMPLETE, (short) 12345, (short) 12346), new AssuredReplicationServerResult(AssuredReplicationServerResultCode.TIMEOUT, (short) 12347, (short) 12348))), Arrays.asList("# Assured Replication Response Control:", "# OID: " + AssuredReplicationResponseControl.ASSURED_REPLICATION_RESPONSE_OID, "# Change Sequence Number: csn", "# Local Assurance Level: PROCESSED_ALL_SERVERS", "# Local Assurance Satisfied: true", "# Local Assurance Message: local message", "# Remote Assurance Level: " + "RECEIVED_ANY_REMOTE_LOCATION", "# Remote Assurance Satisfied: false", "# Remote Assurance Message: remote message", "# Server Result:", "# Server Result Code: COMPLETE", "# Replication Server ID: 12345", "# Replica ID: 12346", "# Server Result:", "# Server Result Code: TIMEOUT", "# Replication Server ID: 12347", "# Replica ID: 12348") });
// An invalid assured replication response control.
resultList.add(new Object[] { new Control(AssuredReplicationResponseControl.ASSURED_REPLICATION_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + AssuredReplicationResponseControl.ASSURED_REPLICATION_RESPONSE_OID, "# Is Critical: false") });
// A valid generate password response control without a password expiration
// time.
resultList.add(new Object[] { new GeneratePasswordResponseControl("generated-password", false, (Long) null), Arrays.asList("# Generate Password Response Control:", "# OID: " + GeneratePasswordResponseControl.GENERATE_PASSWORD_RESPONSE_OID, "# Generated Password: generated-password", "# Must Change Password: false") });
// A valid generate password response control with a password expiration
// time.
resultList.add(new Object[] { new GeneratePasswordResponseControl("generated-password", true, 86400L), Arrays.asList("# Generate Password Response Control:", "# OID: " + GeneratePasswordResponseControl.GENERATE_PASSWORD_RESPONSE_OID, "# Generated Password: generated-password", "# Must Change Password: true", "# Seconds Until Expiration: 86400") });
// An invalid generate password response control.
resultList.add(new Object[] { new Control(GeneratePasswordResponseControl.GENERATE_PASSWORD_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + GeneratePasswordResponseControl.GENERATE_PASSWORD_RESPONSE_OID, "# Is Critical: false") });
// A valid get authorization entry response control for an unauthenticated
// connection.
resultList.add(new Object[] { new GetAuthorizationEntryResponseControl(false, true, "dn:", null, null, null), Arrays.asList("# Get Authorization Entry Response Control:", "# OID: " + GetAuthorizationEntryResponseControl.GET_AUTHORIZATION_ENTRY_RESPONSE_OID, "# Is Authenticated: false") });
// A valid get authorization entry response control for an authenticated
// connection in which the authentication and authorization identities
// match.
resultList.add(new Object[] { new GetAuthorizationEntryResponseControl(true, true, "u:test.user", 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"), null, null), Arrays.asList("# Get Authorization Entry Response Control:", "# OID: " + GetAuthorizationEntryResponseControl.GET_AUTHORIZATION_ENTRY_RESPONSE_OID, "# Is Authenticated: true", "# Authentication and Authorization Identities " + "Match: true", "# Authentication Identity ID: u:test.user", "# Authentication Identity Entry:", "# 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") });
// A valid get authorization entry response control for an authenticated
// connection in which the authentication and authorization identities
// differ.
resultList.add(new Object[] { new GetAuthorizationEntryResponseControl(true, false, "u:test.user", 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"), "u:another.user", new ReadOnlyEntry("dn: uid=another.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: another.user", "givenName: Another", "sn: User", "cn: Another User")), Arrays.asList("# Get Authorization Entry Response Control:", "# OID: " + GetAuthorizationEntryResponseControl.GET_AUTHORIZATION_ENTRY_RESPONSE_OID, "# Is Authenticated: true", "# Authentication and Authorization Identities " + "Match: false", "# Authentication Identity ID: u:test.user", "# Authentication Identity Entry:", "# 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", "# Authorization Identity ID: u:another.user", "# Authorization Identity Entry:", "# dn: uid=another.user,ou=People,dc=example," + "dc=com", "# objectClass: top", "# objectClass: person", "# objectClass: organizationalPerson", "# objectClass: inetOrgPerson", "# uid: another.user", "# givenName: Another", "# sn: User", "# cn: Another User") });
// An invalid get authorization identity response control.
resultList.add(new Object[] { new Control(GetAuthorizationEntryResponseControl.GET_AUTHORIZATION_ENTRY_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + GetAuthorizationEntryResponseControl.GET_AUTHORIZATION_ENTRY_RESPONSE_OID, "# Is Critical: false") });
// A valid get backend set ID response control with a single backend set ID.
resultList.add(new Object[] { new GetBackendSetIDResponseControl("rpID", "bsID"), Arrays.asList("# Get Backend Set ID Response Control:", "# OID: " + GetBackendSetIDResponseControl.GET_BACKEND_SET_ID_RESPONSE_OID, "# Entry-Balancing Request Processor ID: rpID", "# Backend Set ID: bsID") });
// A valid get backend set ID response control with multiple backend set
// IDs.
resultList.add(new Object[] { new GetBackendSetIDResponseControl("rpID", Arrays.asList("bs1", "bs2")), Arrays.asList("# Get Backend Set ID Response Control:", "# OID: " + GetBackendSetIDResponseControl.GET_BACKEND_SET_ID_RESPONSE_OID, "# Entry-Balancing Request Processor ID: rpID", "# Backend Set ID: bs1", "# Backend Set ID: bs2") });
// An invalid get backend set ID response control.
resultList.add(new Object[] { new Control(GetBackendSetIDResponseControl.GET_BACKEND_SET_ID_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + GetBackendSetIDResponseControl.GET_BACKEND_SET_ID_RESPONSE_OID, "# Is Critical: false") });
// A valid get password policy state issues response control without any
// issues.
resultList.add(new Object[] { new GetPasswordPolicyStateIssuesResponseControl(null, null, null), Arrays.asList("# Get Password Policy State Issues Response Control:", "# OID: " + GetPasswordPolicyStateIssuesResponseControl.GET_PASSWORD_POLICY_STATE_ISSUES_RESPONSE_OID) });
// A valid get password policy state issues response control with multiple
// notices, warnings, and errors, and an authentication failure reason
resultList.add(new Object[] { new GetPasswordPolicyStateIssuesResponseControl(Arrays.asList(new PasswordPolicyStateAccountUsabilityNotice(PasswordPolicyStateAccountUsabilityNotice.NOTICE_TYPE_IN_MINIMUM_PASSWORD_AGE, PasswordPolicyStateAccountUsabilityNotice.NOTICE_NAME_IN_MINIMUM_PASSWORD_AGE, "You can't change your password yet"), new PasswordPolicyStateAccountUsabilityNotice(PasswordPolicyStateAccountUsabilityNotice.NOTICE_TYPE_OUTSTANDING_RETIRED_PASSWORD, PasswordPolicyStateAccountUsabilityNotice.NOTICE_NAME_OUTSTANDING_RETIRED_PASSWORD, "You have a valid retired password")), Arrays.asList(new PasswordPolicyStateAccountUsabilityWarning(PasswordPolicyStateAccountUsabilityWarning.WARNING_TYPE_ACCOUNT_EXPIRING, PasswordPolicyStateAccountUsabilityWarning.WARNING_NAME_ACCOUNT_EXPIRING, "Your account will expire soon"), new PasswordPolicyStateAccountUsabilityWarning(PasswordPolicyStateAccountUsabilityWarning.WARNING_TYPE_PASSWORD_EXPIRING, PasswordPolicyStateAccountUsabilityWarning.WARNING_NAME_PASSWORD_EXPIRING, "Your password will expire soon")), Arrays.asList(new PasswordPolicyStateAccountUsabilityError(PasswordPolicyStateAccountUsabilityError.ERROR_TYPE_ACCOUNT_DISABLED, PasswordPolicyStateAccountUsabilityError.ERROR_NAME_ACCOUNT_DISABLED, "Your account is disabled"), new PasswordPolicyStateAccountUsabilityError(PasswordPolicyStateAccountUsabilityError.ERROR_TYPE_ACCOUNT_EXPIRED, PasswordPolicyStateAccountUsabilityError.ERROR_NAME_ACCOUNT_EXPIRED, "Your account is expired")), new AuthenticationFailureReason(AuthenticationFailureReason.FAILURE_TYPE_ACCOUNT_NOT_USABLE, AuthenticationFailureReason.FAILURE_NAME_ACCOUNT_NOT_USABLE, "Your account is not usable")), Arrays.asList("# Get Password Policy State Issues Response Control:", "# OID: " + GetPasswordPolicyStateIssuesResponseControl.GET_PASSWORD_POLICY_STATE_ISSUES_RESPONSE_OID, "# Authentication Failure Reason:", "# Failure Type: account-not-usable", "# Failure Message: Your account is not usable", "# Account Usability Error:", "# Error Name: account-disabled", "# Error Message: Your account is disabled", "# Account Usability Error:", "# Error Name: account-expired", "# Error Message: Your account is expired", "# Account Usability Warning:", "# Warning Name: account-expiring", "# Warning Message: Your account will expire " + "soon", "# Account Usability Warning:", "# Warning Name: password-expiring", "# Warning Message: Your password will " + "expire soon", "# Account Usability Notice:", "# Notice Name: in-minimum-password-age", "# Notice Message: You can't change your " + "password yet", "# Account Usability Notice:", "# Notice Name: outstanding-retired-password", "# Notice Message: You have a valid retired " + "password") });
// An invalid get password policy state issues response control.
resultList.add(new Object[] { new Control(GetPasswordPolicyStateIssuesResponseControl.GET_PASSWORD_POLICY_STATE_ISSUES_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + GetPasswordPolicyStateIssuesResponseControl.GET_PASSWORD_POLICY_STATE_ISSUES_RESPONSE_OID, "# Is Critical: false") });
// A valid get recent login history response control without any successful
// or failed attempts.
resultList.add(new Object[] { new GetRecentLoginHistoryResponseControl(new RecentLoginHistory(null, null)), Arrays.asList("# Get Recent Login History Response Control:", "# OID: " + GetRecentLoginHistoryResponseControl.GET_RECENT_LOGIN_HISTORY_RESPONSE_OID, "# No Successful Attempts", "# No Failed Attempts") });
// A valid get recent login history response control with both successful
// and failed attempts.
final long currentTime = System.currentTimeMillis();
final TreeSet<RecentLoginHistoryAttempt> successes = new TreeSet<>();
successes.add(new RecentLoginHistoryAttempt(true, currentTime, "simple", "1.2.3.4", null, 0L));
final TreeSet<RecentLoginHistoryAttempt> failures = new TreeSet<>();
failures.add(new RecentLoginHistoryAttempt(false, (currentTime - 5_000L), "simple", "1.2.3.4", "invalid-credentials", 1L));
RecentLoginHistory recentLoginHistory = new RecentLoginHistory(successes, failures);
resultList.add(new Object[] { new GetRecentLoginHistoryResponseControl(recentLoginHistory), Arrays.asList("# Get Recent Login History Response Control:", "# OID: " + GetRecentLoginHistoryResponseControl.GET_RECENT_LOGIN_HISTORY_RESPONSE_OID, "# Successful Attempt:", "# Timestamp: " + StaticUtils.encodeRFC3339Time(currentTime), "# Authentication Method: simple", "# Client IP Address: 1.2.3.4", "# Additional Attempt Count: 0", "# Failed Attempt:", "# Timestamp: " + StaticUtils.encodeRFC3339Time(currentTime - 5_000L), "# Authentication Method: simple", "# Client IP Address: 1.2.3.4", "# Failure Reason: invalid-credentials", "# Additional Attempt Count: 1") });
// An invalid recent login history response control.
resultList.add(new Object[] { new Control(GetRecentLoginHistoryResponseControl.GET_RECENT_LOGIN_HISTORY_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + GetRecentLoginHistoryResponseControl.GET_RECENT_LOGIN_HISTORY_RESPONSE_OID, "# Is Critical: false") });
// A valid get server ID response control.
resultList.add(new Object[] { new GetServerIDResponseControl("serverID"), Arrays.asList("# Get Server ID Response Control:", "# OID: " + GetServerIDResponseControl.GET_SERVER_ID_RESPONSE_OID, "# Server ID: serverID") });
// An invalid get server ID response control.
resultList.add(new Object[] { new Control(GetServerIDResponseControl.GET_SERVER_ID_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + GetServerIDResponseControl.GET_SERVER_ID_RESPONSE_OID, "# Is Critical: false") });
// A valid get user resource limits response control with a minimal set of
// fields and unlimited values where possible.
resultList.add(new Object[] { new GetUserResourceLimitsResponseControl(0L, 0L, 0L, 0L, null, null), Arrays.asList("# Get User Resource Limits Response Control:", "# OID: " + GetUserResourceLimitsResponseControl.GET_USER_RESOURCE_LIMITS_RESPONSE_OID, "# Size Limit: Unlimited", "# Time Limit: Unlimited", "# Idle Time Limit: Unlimited", "# Lookthrough Limit: Unlimited") });
// A valid get user resource limits response control with all fields and
// definite limits.
resultList.add(new Object[] { new GetUserResourceLimitsResponseControl(12345L, 67890L, 98765L, 54321L, "uid=equivalent.user,ou=People,dc=example,dc=com", "CCP", Arrays.asList("cn=Group 1,ou=Groups,dc=example,dc=com", "cn=Group 2,ou=Groups,dc=example,dc=com"), Arrays.asList("bypass-read-acl", "config-read"), Arrays.asList(new Attribute("other-attr-1", "value1"), new Attribute("other-attr-2", "value2"))), Arrays.asList("# Get User Resource Limits Response Control:", "# OID: " + GetUserResourceLimitsResponseControl.GET_USER_RESOURCE_LIMITS_RESPONSE_OID, "# Size Limit: 12345", "# Time Limit: 67890 seconds", "# Idle Time Limit: 98765 seconds", "# Lookthrough Limit: 54321", "# Equivalent Authorization User DN: " + "uid=equivalent.user,ou=People,dc=example,dc=com", "# Client Connection Policy Name: CCP", "# Group DNs:", "# cn=Group 1,ou=Groups,dc=example,dc=com", "# cn=Group 2,ou=Groups,dc=example,dc=com", "# Privileges:", "# bypass-read-acl", "# config-read", "# Other Attributes:", "# other-attr-1: value1", "# other-attr-2: value2") });
// An invalid get user resource limits response control.
resultList.add(new Object[] { new Control(GetUserResourceLimitsResponseControl.GET_USER_RESOURCE_LIMITS_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + GetUserResourceLimitsResponseControl.GET_USER_RESOURCE_LIMITS_RESPONSE_OID, "# Is Critical: false") });
// A valid intermediate client response control.
resultList.add(new Object[] { new IntermediateClientResponseControl(new IntermediateClientResponseValue(new IntermediateClientResponseValue(null, "upstream.server.address", false, "upstreamServerName", "upstreamSessionID", "upstreamResponseID"), "intermediate.server.address", true, "intermediateServerName", "intermediateSessionID", "intermediateResponseID")), Arrays.asList("# Intermediate Client Response Control:", "# OID: " + IntermediateClientResponseControl.INTERMEDIATE_CLIENT_RESPONSE_OID, "# Upstream Server Address: " + "intermediate.server.address", "# Upstream Server Secure: true", "# Server Name: intermediateServerName", "# Server Session ID: intermediateSessionID", "# Server Response ID: intermediateResponseID", "# Upstream Response:", "# Upstream Server Address: " + "upstream.server.address", "# Upstream Server Secure: false", "# Server Name: upstreamServerName", "# Server Session ID: upstreamSessionID", "# Server Response ID: upstreamResponseID") });
// An invalid intermediate client response control.
resultList.add(new Object[] { new Control(IntermediateClientResponseControl.INTERMEDIATE_CLIENT_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + IntermediateClientResponseControl.INTERMEDIATE_CLIENT_RESPONSE_OID, "# Is Critical: false") });
// A valid join result control.
resultList.add(new Object[] { new JoinResultControl(ResultCode.SUCCESS, "diag", "dc=example,dc=com", Arrays.asList("ldap://ds1.example.com:389/dc=example,dc=com", "ldap://ds2.example.com:389/dc=example,dc=com"), Arrays.asList(new JoinedEntry(new ReadOnlyEntry("dn: ou=joined 1,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: joined 1"), Arrays.asList(new JoinedEntry(new ReadOnlyEntry("dn: ou=joined 1a,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: joined 1a"), null), new JoinedEntry(new ReadOnlyEntry("dn: ou=joined 1b,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: joined 1b"), null))), new JoinedEntry(new ReadOnlyEntry("dn: ou=joined 2,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: joined 2"), Arrays.asList(new JoinedEntry(new ReadOnlyEntry("dn: ou=joined 2a,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: joined 2a"), null), new JoinedEntry(new ReadOnlyEntry("dn: ou=joined 2b,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: joined 2b"), null))))), Arrays.asList("# Join Result Control:", "# OID: " + JoinResultControl.JOIN_RESULT_OID, "# Join Result Code: 0 (success)", "# Join Diagnostic Message: diag", "# Join Matched DN: dc=example,dc=com", "# Join Referral URL: " + "ldap://ds1.example.com:389/dc=example,dc=com", "# Join Referral URL: " + "ldap://ds2.example.com:389/dc=example,dc=com", "# Joined With Entry:", "# dn: ou=joined 1,dc=example,dc=com", "# objectClass: top", "# objectClass: organizationalUnit", "# ou: joined 1", "# Joined With Entry:", "# dn: ou=joined 1a,dc=example,dc=com", "# objectClass: top", "# objectClass: organizationalUnit", "# ou: joined 1a", "# Joined With Entry:", "# dn: ou=joined 1b,dc=example,dc=com", "# objectClass: top", "# objectClass: organizationalUnit", "# ou: joined 1b", "# Joined With Entry:", "# dn: ou=joined 2,dc=example,dc=com", "# objectClass: top", "# objectClass: organizationalUnit", "# ou: joined 2", "# Joined With Entry:", "# dn: ou=joined 2a,dc=example,dc=com", "# objectClass: top", "# objectClass: organizationalUnit", "# ou: joined 2a", "# Joined With Entry:", "# dn: ou=joined 2b,dc=example,dc=com", "# objectClass: top", "# objectClass: organizationalUnit", "# ou: joined 2b") });
// An invalid join result control.
resultList.add(new Object[] { new Control(JoinResultControl.JOIN_RESULT_OID), Arrays.asList("# Response Control:", "# OID: " + JoinResultControl.JOIN_RESULT_OID, "# Is Critical: false") });
// A valid matching entry count response control for an examined count.
resultList.add(new Object[] { MatchingEntryCountResponseControl.createExactCountResponse(12345, true, true, true, false, true, Filter.createEqualityFilter("objectClass", "person"), Arrays.asList("debug message 1", "debug message 2")), Arrays.asList("# Matching Entry Count Response Control:", "# OID: " + MatchingEntryCountResponseControl.MATCHING_ENTRY_COUNT_RESPONSE_OID, "# Count Type: Examined", "# Count Value: 12345", "# Search Is Indexed: true", "# Short Circuited: true", "# Fully Indexed: false", "# Candidates Are in Scope: true", "# Remaining Filter: (objectClass=person)", "# Debug Info:", "# debug message 1", "# debug message 2") });
// A valid matching entry count response control for an unexamined count.
resultList.add(new Object[] { MatchingEntryCountResponseControl.createExactCountResponse(67890, false, true, Arrays.asList("debug message 1", "debug message 2")), Arrays.asList("# Matching Entry Count Response Control:", "# OID: " + MatchingEntryCountResponseControl.MATCHING_ENTRY_COUNT_RESPONSE_OID, "# Count Type: Unexamined", "# Count Value: 67890", "# Search Is Indexed: true", "# Debug Info:", "# debug message 1", "# debug message 2") });
// A valid matching entry count response control for an upper bound count.
resultList.add(new Object[] { MatchingEntryCountResponseControl.createUpperBoundResponse(98765, false, Arrays.asList("debug message 1", "debug message 2")), Arrays.asList("# Matching Entry Count Response Control:", "# OID: " + MatchingEntryCountResponseControl.MATCHING_ENTRY_COUNT_RESPONSE_OID, "# Count Type: Upper Bound", "# Count Value: 98765", "# Search Is Indexed: false", "# Debug Info:", "# debug message 1", "# debug message 2") });
// A valid matching entry count response control for an unknown count.
resultList.add(new Object[] { MatchingEntryCountResponseControl.createUnknownCountResponse(Arrays.asList("debug message 1", "debug message 2")), Arrays.asList("# Matching Entry Count Response Control:", "# OID: " + MatchingEntryCountResponseControl.MATCHING_ENTRY_COUNT_RESPONSE_OID, "# Count Type: Unknown", "# Search Is Indexed: false", "# Debug Info:", "# debug message 1", "# debug message 2") });
// An invalid matching entry count response control.
resultList.add(new Object[] { new Control(MatchingEntryCountResponseControl.MATCHING_ENTRY_COUNT_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + MatchingEntryCountResponseControl.MATCHING_ENTRY_COUNT_RESPONSE_OID, "# Is Critical: false") });
// A valid password policy response control for a password that is about to
// expire.
resultList.add(new Object[] { new PasswordPolicyResponseControl(PasswordPolicyWarningType.TIME_BEFORE_EXPIRATION, 12345, null), Arrays.asList("# Password Policy Response Control:", "# OID: " + PasswordPolicyResponseControl.PASSWORD_POLICY_RESPONSE_OID, "# Error Type: None", "# Warning Type: time before expiration", "# Warning Value: 12345") });
// A valid password policy response control for an account that is locked.
resultList.add(new Object[] { new PasswordPolicyResponseControl(null, -1, PasswordPolicyErrorType.ACCOUNT_LOCKED), Arrays.asList("# Password Policy Response Control:", "# OID: " + PasswordPolicyResponseControl.PASSWORD_POLICY_RESPONSE_OID, "# Error Type: account locked", "# Warning Type: None") });
// An invalid password policy response control.
resultList.add(new Object[] { new Control(PasswordPolicyResponseControl.PASSWORD_POLICY_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + PasswordPolicyResponseControl.PASSWORD_POLICY_RESPONSE_OID, "# Is Critical: false") });
// A valid password validation details response control for a validation
// details response.
final LinkedHashMap<String, String> r1Map = new LinkedHashMap<String, String>(2);
r1Map.put("prop1a", "value1a");
r1Map.put("prop1b", "value1b");
final LinkedHashMap<String, String> r2Map = new LinkedHashMap<String, String>(2);
r2Map.put("prop2a", "value2a");
r2Map.put("prop2b", "value2b");
resultList.add(new Object[] { new PasswordValidationDetailsResponseControl(PasswordValidationDetailsResponseType.VALIDATION_DETAILS, Arrays.asList(new PasswordQualityRequirementValidationResult(new PasswordQualityRequirement("Requirement 1", "first-requirement", r1Map), true, "Requirement 1 was satisfied"), new PasswordQualityRequirementValidationResult(new PasswordQualityRequirement("Requirement 2", "second-requirement", r2Map), false, "Requirement 2 was not satisfied")), false, true, 12345), Arrays.asList("# Password Validation Details Response Control:", "# OID: " + PasswordValidationDetailsResponseControl.PASSWORD_VALIDATION_DETAILS_RESPONSE_OID, "# Result Type: Validation Result", "# Password Quality Requirement Validation " + "Result:", "# Password Quality Requirement " + "Description: Requirement 1", "# Client-Side Validation Type: " + "first-requirement", "# Client-Side Validation Property: " + "prop1a=value1a", "# Client-Side Validation Property: " + "prop1b=value1b", "# Requirement Satisfied: true", "# Additional Validation Info: " + "Requirement 1 was satisfied", "# Password Quality Requirement Validation " + "Result:", "# Password Quality Requirement " + "Description: Requirement 2", "# Client-Side Validation Type: " + "second-requirement", "# Client-Side Validation Property: " + "prop2a=value2a", "# Client-Side Validation Property: " + "prop2b=value2b", "# Requirement Satisfied: false", "# Additional Validation Info: " + "Requirement 2 was not satisfied", "# Missing Current Password: false", "# Must Change Password: true", "# Seconds Until Expiration: 12345") });
// A valid password validation details response control for a "no password
// provided" response.
resultList.add(new Object[] { new PasswordValidationDetailsResponseControl(PasswordValidationDetailsResponseType.NO_PASSWORD_PROVIDED, null, true, false, null), Arrays.asList("# Password Validation Details Response Control:", "# OID: " + PasswordValidationDetailsResponseControl.PASSWORD_VALIDATION_DETAILS_RESPONSE_OID, "# Result Type: No Password Provided", "# Missing Current Password: true", "# Must Change Password: false") });
// A valid password validation details response control for a "multiple
// passwords provided" response.
resultList.add(new Object[] { new PasswordValidationDetailsResponseControl(PasswordValidationDetailsResponseType.MULTIPLE_PASSWORDS_PROVIDED, null, true, false, null), Arrays.asList("# Password Validation Details Response Control:", "# OID: " + PasswordValidationDetailsResponseControl.PASSWORD_VALIDATION_DETAILS_RESPONSE_OID, "# Result Type: Multiple Passwords Provided", "# Missing Current Password: true", "# Must Change Password: false") });
// A valid password validation details response control for a "no validation
// attempted" response.
resultList.add(new Object[] { new PasswordValidationDetailsResponseControl(PasswordValidationDetailsResponseType.NO_VALIDATION_ATTEMPTED, null, true, false, null), Arrays.asList("# Password Validation Details Response Control:", "# OID: " + PasswordValidationDetailsResponseControl.PASSWORD_VALIDATION_DETAILS_RESPONSE_OID, "# Result Type: No Validation Attempted", "# Missing Current Password: true", "# Must Change Password: false") });
// An invalid password validation details response control.
resultList.add(new Object[] { new Control(PasswordValidationDetailsResponseControl.PASSWORD_VALIDATION_DETAILS_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + PasswordValidationDetailsResponseControl.PASSWORD_VALIDATION_DETAILS_RESPONSE_OID, "# Is Critical: false") });
// A valid soft delete response control.
resultList.add(new Object[] { new SoftDeleteResponseControl("ou=test+entryUUID=" + uuid.toString() + ",dc=example,dc=com"), Arrays.asList("# Soft Delete Response Control:", "# OID: " + SoftDeleteResponseControl.SOFT_DELETE_RESPONSE_OID, "# Soft-Deleted Entry DN: ou=test+entryUUID=" + uuid.toString() + ",dc=example,dc=com") });
// An invalid soft delete response control.
resultList.add(new Object[] { new Control(SoftDeleteResponseControl.SOFT_DELETE_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + SoftDeleteResponseControl.SOFT_DELETE_RESPONSE_OID, "# Is Critical: false") });
// A valid transaction settings response control.
resultList.add(new Object[] { new TransactionSettingsResponseControl(12345, true), Arrays.asList("# Transaction Settings Response Control:", "# OID: " + TransactionSettingsResponseControl.TRANSACTION_SETTINGS_RESPONSE_OID, "# Number of Lock Conflicts: 12345", "# Backend Lock Acquired: true") });
// An invalid transaction settings response control.
resultList.add(new Object[] { new Control(TransactionSettingsResponseControl.TRANSACTION_SETTINGS_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + TransactionSettingsResponseControl.TRANSACTION_SETTINGS_RESPONSE_OID, "# Is Critical: false") });
// A valid uniqueness response control in which all of the tests passed.
resultList.add(new Object[] { new UniquenessResponseControl("all-passed", true, true, null), Arrays.asList("# Uniqueness Response Control:", "# OID: " + UniquenessResponseControl.UNIQUENESS_RESPONSE_OID, "# Uniqueness ID: all-passed", "# Pre-Commit Validation Status: Passed", "# Post-Commit Validation Status: Passed") });
// A valid uniqueness response control in which the pre-commit attempt
// failed.
resultList.add(new Object[] { new UniquenessResponseControl("pre-commit-failed", false, null, "The pre-commit attempt failed"), Arrays.asList("# Uniqueness Response Control:", "# OID: " + UniquenessResponseControl.UNIQUENESS_RESPONSE_OID, "# Uniqueness ID: pre-commit-failed", "# Pre-Commit Validation Status: Failed", "# Post-Commit Validation Status: Not Attempted", "# Message: The pre-commit attempt failed") });
// A valid uniqueness response control in which the pre-commit attempt
// passed but the post-commit attempt failed.
resultList.add(new Object[] { new UniquenessResponseControl("post-commit-failed", true, false, "The post-commit attempt failed"), Arrays.asList("# Uniqueness Response Control:", "# OID: " + UniquenessResponseControl.UNIQUENESS_RESPONSE_OID, "# Uniqueness ID: post-commit-failed", "# Pre-Commit Validation Status: Passed", "# Post-Commit Validation Status: Failed", "# Message: The post-commit attempt failed") });
// A valid uniqueness response control in which no validation was attempted.
resultList.add(new Object[] { new UniquenessResponseControl("not-attempted", null, null, "No validation was attempted"), Arrays.asList("# Uniqueness Response Control:", "# OID: " + UniquenessResponseControl.UNIQUENESS_RESPONSE_OID, "# Uniqueness ID: not-attempted", "# Pre-Commit Validation Status: Not Attempted", "# Post-Commit Validation Status: Not Attempted", "# Message: No validation was attempted") });
// An invalid uniqueness response control.
resultList.add(new Object[] { new Control(UniquenessResponseControl.UNIQUENESS_RESPONSE_OID), Arrays.asList("# Response Control:", "# OID: " + UniquenessResponseControl.UNIQUENESS_RESPONSE_OID, "# Is Critical: false") });
return resultList.iterator();
}
use of com.unboundid.ldap.sdk.controls.PreReadResponseControl in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerLDAPInterfaceTestCase method testDelete.
/**
* Provides test coverage for the methods that can be used to process delete
* operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDelete() throws Exception {
ds.restoreSnapshot(snapshot);
// Test the method that takes a DN.
LDAPResult deleteResult = ds.delete("uid=test.user,ou=People,dc=example,dc=com");
assertNotNull(deleteResult);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a delete request object, including controls.
final DeleteRequest deleteRequest = new DeleteRequest("ou=People,dc=example,dc=com");
deleteRequest.addControl(new AssertionRequestControl("(objectClass=top)"));
deleteRequest.addControl(new PreReadRequestControl("*", "+"));
deleteResult = ds.delete(deleteRequest);
assertNotNull(deleteResult);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
assertTrue(deleteResult.hasResponseControl(PreReadResponseControl.PRE_READ_RESPONSE_OID));
final PreReadResponseControl preReadResponse = PreReadResponseControl.get(deleteResult);
assertNotNull(preReadResponse);
assertTrue(preReadResponse.getEntry().hasAttribute("ou"));
assertTrue(preReadResponse.getEntry().hasAttribute("objectClass"));
assertTrue(preReadResponse.getEntry().hasAttribute("entryDN"));
assertTrue(preReadResponse.getEntry().hasAttribute("entryUUID"));
// Test the method that takes a read-only delete request object with a
// failed request.
ReadOnlyDeleteRequest readOnlyDeleteRequest = new DeleteRequest("ou=missing,dc=example,dc=com");
try {
ds.delete(readOnlyDeleteRequest);
fail("Expected an exception when trying to process a delete request " + "targeting a nonexistent entry.");
} catch (final LDAPException le) {
// This was expected.
assertEquals(le.getResultCode(), ResultCode.NO_SUCH_OBJECT);
}
// Test the method that takes a read-only delete request object with a
// successful request.
readOnlyDeleteRequest = new DeleteRequest("dc=example,dc=com");
deleteResult = ds.delete(readOnlyDeleteRequest);
assertNotNull(deleteResult);
assertEquals(deleteResult.getResultCode(), ResultCode.SUCCESS);
}
Aggregations