use of com.unboundid.ldap.sdk.controls.PreReadRequestControl in project ldapsdk by pingidentity.
the class InMemoryRequestHandler method handlePreReadControl.
/**
* Checks to see if the provided control map includes a pre-read request
* control, and if so then generates the appropriate response control that
* should be returned to the client.
*
* @param m The map of request controls, indexed by OID.
* @param e The entry as it appeared before the operation.
*
* @return The pre-read response control that should be returned to the
* client, or {@code null} if there is none.
*/
@Nullable()
private PreReadResponseControl handlePreReadControl(@NotNull final Map<String, Control> m, @NotNull final Entry e) {
final PreReadRequestControl c = (PreReadRequestControl) m.get(PreReadRequestControl.PRE_READ_REQUEST_OID);
if (c == null) {
return null;
}
final SearchEntryParer parer = new SearchEntryParer(Arrays.asList(c.getAttributes()), schemaRef.get());
final Entry trimmedEntry = parer.pareEntry(e);
return new PreReadResponseControl(new ReadOnlyEntry(trimmedEntry));
}
use of com.unboundid.ldap.sdk.controls.PreReadRequestControl in project ldapsdk by pingidentity.
the class InMemoryDirectoryServerLDAPInterfaceTestCase method testModifyDN.
/**
* Provides test coverage for the methods that can be used to process modify
* DN operations.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testModifyDN() throws Exception {
ds.restoreSnapshot(snapshot);
ds.add("dn: ou=Users,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: Users");
// Test the method that takes a DN, new RDN, and deleteOldRDN flag.
LDAPResult modifyDNResult = ds.modifyDN("uid=test.user,ou=People,dc=example,dc=com", "uid=test.2", true);
assertNotNull(modifyDNResult);
assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a DN, new RDN, deleteOldRDN flag and a new
// superior DN.
modifyDNResult = ds.modifyDN("uid=test.2,ou=People,dc=example,dc=com", "uid=test.2", false, "ou=Users,dc=example,dc=com");
assertNotNull(modifyDNResult);
assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
// Test the method that takes a modify DN request, with controls.
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest("uid=test.2,ou=Users,dc=example,dc=com", "uid=test.3", true);
modifyDNRequest.addControl(new PreReadRequestControl("*", "+"));
modifyDNRequest.addControl(new PostReadRequestControl("*", "+"));
modifyDNResult = ds.modifyDN(modifyDNRequest);
assertNotNull(modifyDNResult);
assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
assertTrue(modifyDNResult.hasResponseControl(PreReadResponseControl.PRE_READ_RESPONSE_OID));
final PreReadResponseControl preReadResponse = PreReadResponseControl.get(modifyDNResult);
assertNotNull(preReadResponse);
assertTrue(preReadResponse.getEntry().hasAttributeValue("uid", "test.2"));
assertTrue(modifyDNResult.hasResponseControl(PostReadResponseControl.POST_READ_RESPONSE_OID));
final PostReadResponseControl postReadResponse = PostReadResponseControl.get(modifyDNResult);
assertNotNull(postReadResponse);
assertTrue(postReadResponse.getEntry().hasAttributeValue("uid", "test.3"));
// Test the method that takes a read-only modify DN request.
final ReadOnlyModifyDNRequest readOnlyModifyDNRequest = new ModifyDNRequest("uid=test.3,ou=Users,dc=example,dc=com", "uid=test.4", true);
modifyDNResult = ds.modifyDN(readOnlyModifyDNRequest);
assertNotNull(modifyDNResult);
assertEquals(modifyDNResult.getResultCode(), ResultCode.SUCCESS);
}
use of com.unboundid.ldap.sdk.controls.PreReadRequestControl in project ldapsdk by pingidentity.
the class RequestControlPreProcessorTestCase method testPreReadControl.
/**
* Provides test coverage for the pre-read control.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testPreReadControl() throws Exception {
final String oid = PreReadRequestControl.PRE_READ_REQUEST_OID;
final Control vc = new PreReadRequestControl(true);
final Control vn = new PreReadRequestControl(false);
final Control ic = new Control(oid, true, new ASN1OctetString("foo"));
final Control in = new Control(oid, false, new ASN1OctetString("foo"));
final Class<?> c = PreReadRequestControl.class;
// Test with acceptable operation types.
for (final byte opType : Arrays.asList(LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_REQUEST)) {
// A valid critical control.
ensureControlHandled(opType, Arrays.asList(vc), oid, c);
// A valid non-critical control.
ensureControlHandled(opType, Arrays.asList(vn), oid, c);
// Multiple instances of the control.
ensureException(opType, Arrays.asList(vc, vn));
// Malformed critical control.
ensureException(opType, Arrays.asList(ic));
// Malformed non-critical control.
ensureException(opType, Arrays.asList(in));
}
// Test with unacceptable operation types.
for (final byte opType : Arrays.asList(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_ADD_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_BIND_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_EXTENDED_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST, LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST)) {
// A valid critical control.
ensureException(opType, Arrays.asList(vc));
// A valid non-critical control.
ensureControlIgnored(opType, Arrays.asList(vn), oid);
// Malformed critical control.
ensureException(opType, Arrays.asList(ic));
// Malformed non-critical control.
ensureControlIgnored(opType, Arrays.asList(in), oid);
}
}
use of com.unboundid.ldap.sdk.controls.PreReadRequestControl 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.PreReadRequestControl 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();
}
Aggregations