use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class MultiUpdateExtendedRequestTestCase method testBasicWithoutControls.
/**
* Provides basic test coverage for the multi-update extended request without
* any controls.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBasicWithoutControls() throws Exception {
final Control[] modDNControls = { new ManageDsaITRequestControl() };
MultiUpdateExtendedRequest r = new MultiUpdateExtendedRequest(MultiUpdateErrorBehavior.ATOMIC, new AddRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User", "userPassword: password"), new ModifyRequest("dn: uid=test.user,ou=People,dc=example,dc=com", "changetype: modify", "replace: description", "description: foo"), new ModifyDNRequest("uid=test.user,ou=People,dc=example,dc=com", "cn=Test User", false, modDNControls), new PasswordModifyExtendedRequest("dn:cn=Test User,ou=People,dc=example,dc=com", "password", "newPassword"), new DeleteRequest("cn=Test User,ou=People,dc=example,dc=com"));
r = new MultiUpdateExtendedRequest(r);
r = r.duplicate();
assertNotNull(r.getErrorBehavior());
assertEquals(r.getErrorBehavior(), MultiUpdateErrorBehavior.ATOMIC);
assertNotNull(r.getRequests());
assertEquals(r.getRequests().size(), 5);
assertEquals(r.getRequests().get(0).getOperationType(), OperationType.ADD);
assertNotNull(r.getRequests().get(0).getControls());
assertEquals(r.getRequests().get(0).getControls().length, 0);
assertEquals(r.getRequests().get(1).getOperationType(), OperationType.MODIFY);
assertNotNull(r.getRequests().get(1).getControls());
assertEquals(r.getRequests().get(1).getControls().length, 0);
assertEquals(r.getRequests().get(2).getOperationType(), OperationType.MODIFY_DN);
assertNotNull(r.getRequests().get(2).getControls());
assertEquals(r.getRequests().get(2).getControls().length, 1);
assertEquals(r.getRequests().get(3).getOperationType(), OperationType.EXTENDED);
assertNotNull(r.getRequests().get(3).getControls());
assertEquals(r.getRequests().get(3).getControls().length, 0);
assertEquals(r.getRequests().get(4).getOperationType(), OperationType.DELETE);
assertNotNull(r.getRequests().get(4).getControls());
assertEquals(r.getRequests().get(4).getControls().length, 0);
assertNotNull(r.getControls());
assertEquals(r.getControls().length, 0);
assertNotNull(r.getExtendedRequestName());
assertNotNull(r.toString());
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class LDIFModifyDNChangeRecordTestCase method testConstructor1WithNewSuperior.
/**
* Tests the first constructor with a non-{@code null} newSuperior DN.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructor1WithNewSuperior() throws Exception {
LDIFModifyDNChangeRecord r = new LDIFModifyDNChangeRecord("ou=People,dc=example,dc=com", "ou=Users", true, "o=example.com");
assertNotNull(r.getDN());
assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
assertNotNull(r.getNewRDN());
assertEquals(r.getNewRDN(), "ou=Users");
assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
assertTrue(r.deleteOldRDN());
assertNotNull(r.getNewSuperiorDN());
assertEquals(r.getNewSuperiorDN(), "o=example.com");
assertEquals(r.getParsedNewSuperiorDN(), new DN("o=example.com"));
assertEquals(r.getNewDN(), new DN("ou=Users,o=example.com"));
ModifyDNRequest modifyDNRequest = r.toModifyDNRequest();
assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
String[] ldifLines = r.toLDIF();
assertNotNull(ldifLines);
assertEquals(ldifLines.length, 5);
assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
r.hashCode();
ByteStringBuffer byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer);
assertNotNull(byteBuffer.toString());
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer, 10);
assertNotNull(byteBuffer.toString());
StringBuilder stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer);
assertNotNull(r.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer, 10);
assertNotNull(r.toString());
assertNotNull(r.toLDIFString());
assertNotNull(r.toLDIFString(10));
assertNotNull(r.toString());
assertNotNull(r.getControls());
assertTrue(r.getControls().isEmpty());
r = r.duplicate();
assertNotNull(r.getDN());
assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
assertNotNull(r.getNewRDN());
assertEquals(r.getNewRDN(), "ou=Users");
assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
assertTrue(r.deleteOldRDN());
assertNotNull(r.getNewSuperiorDN());
assertEquals(r.getNewSuperiorDN(), "o=example.com");
assertEquals(r.getParsedNewSuperiorDN(), new DN("o=example.com"));
assertEquals(r.getNewDN(), new DN("ou=Users,o=example.com"));
modifyDNRequest = r.toModifyDNRequest();
assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
ldifLines = r.toLDIF();
assertNotNull(ldifLines);
assertEquals(ldifLines.length, 5);
assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
r.hashCode();
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer);
assertNotNull(byteBuffer.toString());
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer, 10);
assertNotNull(byteBuffer.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer);
assertNotNull(r.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer, 10);
assertNotNull(r.toString());
assertNotNull(r.toLDIFString());
assertNotNull(r.toLDIFString(10));
assertNotNull(r.toString());
assertNotNull(r.getControls());
assertTrue(r.getControls().isEmpty());
r = r.duplicate((Control[]) null);
assertNotNull(r.getDN());
assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
assertNotNull(r.getNewRDN());
assertEquals(r.getNewRDN(), "ou=Users");
assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
assertTrue(r.deleteOldRDN());
assertNotNull(r.getNewSuperiorDN());
assertEquals(r.getNewSuperiorDN(), "o=example.com");
assertEquals(r.getParsedNewSuperiorDN(), new DN("o=example.com"));
assertEquals(r.getNewDN(), new DN("ou=Users,o=example.com"));
modifyDNRequest = r.toModifyDNRequest();
assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
ldifLines = r.toLDIF();
assertNotNull(ldifLines);
assertEquals(ldifLines.length, 5);
assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
r.hashCode();
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer);
assertNotNull(byteBuffer.toString());
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer, 10);
assertNotNull(byteBuffer.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer);
assertNotNull(r.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer, 10);
assertNotNull(r.toString());
assertNotNull(r.toLDIFString());
assertNotNull(r.toLDIFString(10));
assertNotNull(r.toString());
assertNotNull(r.getControls());
assertTrue(r.getControls().isEmpty());
r = r.duplicate(new Control[0]);
assertNotNull(r.getDN());
assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
assertNotNull(r.getNewRDN());
assertEquals(r.getNewRDN(), "ou=Users");
assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
assertTrue(r.deleteOldRDN());
assertNotNull(r.getNewSuperiorDN());
assertEquals(r.getNewSuperiorDN(), "o=example.com");
assertEquals(r.getParsedNewSuperiorDN(), new DN("o=example.com"));
assertEquals(r.getNewDN(), new DN("ou=Users,o=example.com"));
modifyDNRequest = r.toModifyDNRequest();
assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
ldifLines = r.toLDIF();
assertNotNull(ldifLines);
assertEquals(ldifLines.length, 5);
assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
r.hashCode();
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer);
assertNotNull(byteBuffer.toString());
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer, 10);
assertNotNull(byteBuffer.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer);
assertNotNull(r.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer, 10);
assertNotNull(r.toString());
assertNotNull(r.toLDIFString());
assertNotNull(r.toLDIFString(10));
assertNotNull(r.toString());
assertNotNull(r.getControls());
assertTrue(r.getControls().isEmpty());
r = r.duplicate(new ManageDsaITRequestControl(false));
assertNotNull(r.getDN());
assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
assertNotNull(r.getNewRDN());
assertEquals(r.getNewRDN(), "ou=Users");
assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
assertTrue(r.deleteOldRDN());
assertNotNull(r.getNewSuperiorDN());
assertEquals(r.getNewSuperiorDN(), "o=example.com");
assertEquals(r.getParsedNewSuperiorDN(), new DN("o=example.com"));
assertEquals(r.getNewDN(), new DN("ou=Users,o=example.com"));
modifyDNRequest = r.toModifyDNRequest();
assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
ldifLines = r.toLDIF();
assertNotNull(ldifLines);
assertEquals(ldifLines.length, 6);
assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
r.hashCode();
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer);
assertNotNull(byteBuffer.toString());
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer, 10);
assertNotNull(byteBuffer.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer);
assertNotNull(r.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer, 10);
assertNotNull(r.toString());
assertNotNull(r.toLDIFString());
assertNotNull(r.toLDIFString(10));
assertNotNull(r.toString());
assertNotNull(r.getControls());
assertFalse(r.getControls().isEmpty());
assertEquals(r.getControls(), Collections.singletonList(new ManageDsaITRequestControl(false)));
r = r.duplicate(new ManageDsaITRequestControl(false), new ProxiedAuthorizationV2RequestControl("u:test.user"));
assertNotNull(r.getDN());
assertEquals(r.getDN(), "ou=People,dc=example,dc=com");
assertEquals(r.getParsedDN(), new DN("ou=People,dc=example,dc=com"));
assertNotNull(r.getNewRDN());
assertEquals(r.getNewRDN(), "ou=Users");
assertEquals(r.getParsedNewRDN(), new RDN("ou=Users"));
assertTrue(r.deleteOldRDN());
assertNotNull(r.getNewSuperiorDN());
assertEquals(r.getNewSuperiorDN(), "o=example.com");
assertEquals(r.getParsedNewSuperiorDN(), new DN("o=example.com"));
assertEquals(r.getNewDN(), new DN("ou=Users,o=example.com"));
modifyDNRequest = r.toModifyDNRequest();
assertEquals(modifyDNRequest.getDN(), "ou=People,dc=example,dc=com");
ldifLines = r.toLDIF();
assertNotNull(ldifLines);
assertEquals(ldifLines.length, 7);
assertEquals(r.getChangeType(), ChangeType.MODIFY_DN);
r.hashCode();
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer);
assertNotNull(byteBuffer.toString());
byteBuffer = new ByteStringBuffer();
r.toLDIF(byteBuffer, 10);
assertNotNull(byteBuffer.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer);
assertNotNull(r.toString());
stringBuffer = new StringBuilder();
r.toLDIFString(stringBuffer, 10);
assertNotNull(r.toString());
assertNotNull(r.toLDIFString());
assertNotNull(r.toLDIFString(10));
assertNotNull(r.toString());
assertNotNull(r.getControls());
assertFalse(r.getControls().isEmpty());
assertEquals(r.getControls(), Arrays.asList(new ManageDsaITRequestControl(false), new ProxiedAuthorizationV2RequestControl("u:test.user")));
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class ProxyRequestHandler method processModifyDNRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest(request.getDN(), request.getNewRDN(), request.deleteOldRDN(), request.getNewSuperiorDN());
if (!controls.isEmpty()) {
modifyDNRequest.setControls(controls);
}
modifyDNRequest.setIntermediateResponseListener(this);
LDAPResult modifyDNResult;
try {
modifyDNResult = ldapConnection.modifyDN(modifyDNRequest);
} catch (final LDAPException le) {
Debug.debugException(le);
modifyDNResult = le.toLDAPResult();
}
final ModifyDNResponseProtocolOp modifyDNResponseProtocolOp = new ModifyDNResponseProtocolOp(modifyDNResult.getResultCode().intValue(), modifyDNResult.getMatchedDN(), modifyDNResult.getDiagnosticMessage(), Arrays.asList(modifyDNResult.getReferralURLs()));
return new LDAPMessage(messageID, modifyDNResponseProtocolOp, Arrays.asList(modifyDNResult.getResponseControls()));
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class InMemoryOperationInterceptorRequestHandler method processModifyDNRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
final InterceptedModifyDNOperation op = new InterceptedModifyDNOperation(connection, messageID, request, toArray(controls));
activeOperations.put(messageID, op);
try {
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processModifyDNRequest(op);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
}
}
final LDAPMessage resultMessage = wrappedHandler.processModifyDNRequest(messageID, new ModifyDNRequestProtocolOp((ModifyDNRequest) op.getRequest()), op.getRequest().getControlList());
op.setResult(resultMessage.getModifyDNResponseProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processModifyDNResult(op);
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
}
}
return new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
} finally {
activeOperations.remove(messageID);
}
}
use of com.unboundid.ldap.sdk.ModifyDNRequest in project ldapsdk by pingidentity.
the class ToCodeRequestHandler method processModifyDNRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
final List<String> lineList = getLineList(messageID);
final String requestID = "conn" + clientConnection.getConnectionID() + "Msg" + messageID + "ModifyDN";
final ModifyDNRequest modifyDNRequest = request.toModifyDNRequest(getControlArray(controls));
modifyDNRequest.toCode(lineList, requestID, 0, includeProcessing);
writeLines(lineList);
return requestHandler.processModifyDNRequest(messageID, request, controls);
}
Aggregations