Search in sources :

Example 1 with ModifyDNRequest

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());
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) Control(com.unboundid.ldap.sdk.Control) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) PasswordModifyExtendedRequest(com.unboundid.ldap.sdk.extensions.PasswordModifyExtendedRequest) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) Test(org.testng.annotations.Test)

Example 2 with ModifyDNRequest

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")));
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) ProxiedAuthorizationV2RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl) Control(com.unboundid.ldap.sdk.Control) ProxiedAuthorizationV2RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN) ByteStringBuffer(com.unboundid.util.ByteStringBuffer) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) Test(org.testng.annotations.Test)

Example 3 with ModifyDNRequest

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()));
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 4 with ModifyDNRequest

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);
    }
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) ModifyDNRequestProtocolOp(com.unboundid.ldap.protocol.ModifyDNRequestProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 5 with ModifyDNRequest

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);
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) NotNull(com.unboundid.util.NotNull)

Aggregations

ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)39 Test (org.testng.annotations.Test)32 AddRequest (com.unboundid.ldap.sdk.AddRequest)21 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)21 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)20 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)20 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)11 Control (com.unboundid.ldap.sdk.Control)11 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)11 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)10 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)10 DN (com.unboundid.ldap.sdk.DN)9 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)8 TransactionSpecificationRequestControl (com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl)7 SearchResult (com.unboundid.ldap.sdk.SearchResult)6 TestUnsolicitedNotificationHandler (com.unboundid.ldap.sdk.TestUnsolicitedNotificationHandler)6 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)6 RDN (com.unboundid.ldap.sdk.RDN)5 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)5