Search in sources :

Example 6 with ModifyDNResponseProtocolOp

use of com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp 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 7 with ModifyDNResponseProtocolOp

use of com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp in project ldapsdk by pingidentity.

the class LDAPDebuggerTestCase method testSuccessfulModifyDN.

/**
 * Provides test coverage for a successful modify DN operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSuccessfulModifyDN() throws Exception {
    TestRequestHandler.setReturnOp(new ModifyDNResponseProtocolOp(0, null, null, null));
    final ModifyDNRequest r = new ModifyDNRequest("ou=People,dc=example,dc=com", "ou=Users", true, "o=example.com");
    r.addControl(new Control("1.2.3.4"));
    conn.modifyDN(r);
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) Test(org.testng.annotations.Test)

Example 8 with ModifyDNResponseProtocolOp

use of com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp in project ldapsdk by pingidentity.

the class LDAPDebuggerTestCase method testFailedModifyDN.

/**
 * Provides test coverage for a failed modify DN operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testFailedModifyDN() throws Exception {
    TestRequestHandler.setReturnOp(new ModifyDNResponseProtocolOp(32, "dc=example,dc=com", "msg", Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com")));
    conn.modifyDN("ou=People,dc=example,dc=com", "ou=Users", true, "o=example.com");
}
Also used : ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) Test(org.testng.annotations.Test)

Example 9 with ModifyDNResponseProtocolOp

use of com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp in project ldapsdk by pingidentity.

the class CannedResponseRequestHandlerTestCase method testDefaultConstructor.

/**
 * Tests the behavior of the request handler with the default configuration.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDefaultConstructor() throws Exception {
    final CannedResponseRequestHandler handler = new CannedResponseRequestHandler().newInstance(null);
    LDAPMessage m = handler.processAddRequest(1, new AddRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 1);
    assertTrue(m.getProtocolOp() instanceof AddResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processBindRequest(2, new BindRequestProtocolOp("uid=admin,dc=example,dc=com", "password"), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 2);
    assertTrue(m.getProtocolOp() instanceof BindResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processCompareRequest(3, new CompareRequestProtocolOp("dc=example,dc=com", "objectClass", new ASN1OctetString("top")), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 3);
    assertTrue(m.getProtocolOp() instanceof CompareResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processDeleteRequest(4, new DeleteRequestProtocolOp("dc=example,dc=com"), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 4);
    assertTrue(m.getProtocolOp() instanceof DeleteResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processExtendedRequest(5, new ExtendedRequestProtocolOp("1.2.3.4", null), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 5);
    assertTrue(m.getProtocolOp() instanceof ExtendedResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processModifyRequest(6, new ModifyRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.REPLACE, "description", "foo"))), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 6);
    assertTrue(m.getProtocolOp() instanceof ModifyResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processModifyDNRequest(6, new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 6);
    assertTrue(m.getProtocolOp() instanceof ModifyDNResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processSearchRequest(7, new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 0, 0, false, Filter.createEqualityFilter("uid", "test"), Arrays.<String>asList()), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 7);
    assertTrue(m.getProtocolOp() instanceof SearchResultDoneProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Modification(com.unboundid.ldap.sdk.Modification) ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) Attribute(com.unboundid.ldap.sdk.Attribute) SearchRequestProtocolOp(com.unboundid.ldap.protocol.SearchRequestProtocolOp) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) CompareRequestProtocolOp(com.unboundid.ldap.protocol.CompareRequestProtocolOp) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) ExtendedRequestProtocolOp(com.unboundid.ldap.protocol.ExtendedRequestProtocolOp) DeleteRequestProtocolOp(com.unboundid.ldap.protocol.DeleteRequestProtocolOp) ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) Control(com.unboundid.ldap.sdk.Control) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) ModifyDNRequestProtocolOp(com.unboundid.ldap.protocol.ModifyDNRequestProtocolOp) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) Test(org.testng.annotations.Test)

Example 10 with ModifyDNResponseProtocolOp

use of com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp in project ldapsdk by pingidentity.

the class JSONAccessLogRequestHandler method processModifyDNRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final JSONBuffer buffer = getRequestHeader("modify-dn", opID, messageID);
    buffer.appendString("dn", request.getDN());
    buffer.appendString("new-rdn", request.getNewRDN());
    buffer.appendBoolean("delete-old-rdn", request.deleteOldRDN());
    final String newSuperior = request.getNewSuperiorDN();
    if (newSuperior != null) {
        buffer.appendString("new-superior", newSuperior);
    }
    buffer.endObject();
    logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processModifyDNRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final ModifyDNResponseProtocolOp protocolOp = responseMessage.getModifyDNResponseProtocolOp();
    generateResponse(buffer, "modify-dn", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
    buffer.endObject();
    logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : LogRecord(java.util.logging.LogRecord) JSONBuffer(com.unboundid.util.json.JSONBuffer) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Aggregations

ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)13 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)10 NotNull (com.unboundid.util.NotNull)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)7 Control (com.unboundid.ldap.sdk.Control)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)4 ArrayList (java.util.ArrayList)4 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)3 ModifyDNRequestProtocolOp (com.unboundid.ldap.protocol.ModifyDNRequestProtocolOp)3 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)3 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)3 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)3 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)3 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)3 Test (org.testng.annotations.Test)3 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)2 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)2 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)2 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)2