Search in sources :

Example 1 with ModifyRequestProtocolOp

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

the class InMemoryRequestHandler method modifyEntry.

/**
 * Attempts to apply the provided set of modifications to the specified entry.
 * The attempt will fail if any of the following conditions is true:
 * <UL>
 *   <LI>The target DN is malformed.</LI>
 *   <LI>The target entry is the root DSE.</LI>
 *   <LI>The target entry is the subschema subentry.</LI>
 *   <LI>The target entry does not exist.</LI>
 *   <LI>Any of the modifications cannot be applied to the entry.</LI>
 *   <LI>If a schema was provided, and the entry violates any of the
 *       constraints of that schema.</LI>
 * </UL>
 *
 * @param  dn    The DN of the entry to be modified.
 * @param  mods  The set of modifications to be applied to the entry.
 *
 * @throws  LDAPException  If a problem is encountered while attempting to
 *                         update the specified entry.
 */
public void modifyEntry(@NotNull final String dn, @NotNull final List<Modification> mods) throws LDAPException {
    final ModifyRequestProtocolOp modifyRequest = new ModifyRequestProtocolOp(dn, mods);
    final LDAPMessage resultMessage = processModifyRequest(-1, modifyRequest, Collections.<Control>emptyList());
    final ModifyResponseProtocolOp modifyResponse = resultMessage.getModifyResponseProtocolOp();
    if (modifyResponse.getResultCode() != ResultCode.SUCCESS_INT_VALUE) {
        throw new LDAPException(ResultCode.valueOf(modifyResponse.getResultCode()), modifyResponse.getDiagnosticMessage(), modifyResponse.getMatchedDN(), stringListToArray(modifyResponse.getReferralURLs()));
    }
}
Also used : ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp)

Example 2 with ModifyRequestProtocolOp

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

the class InterceptedModifyOperationTestCase method testBasics.

/**
 * Provides basic test coverage for an intercepted modify operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBasics() throws Exception {
    // Create an intercepted modify operation.  We'll use a null connection,
    // which shouldn't happen naturally but will be sufficient for this test.
    final ModifyRequestProtocolOp requestOp = new ModifyRequestProtocolOp(new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo"));
    final InterceptedModifyOperation o = new InterceptedModifyOperation(null, 1, requestOp);
    assertNotNull(o.toString());
    // Test methods for a generic intercepted operation.
    assertNull(o.getClientConnection());
    assertEquals(o.getConnectionID(), -1L);
    assertNull(o.getConnectedAddress());
    assertEquals(o.getConnectedPort(), -1);
    assertEquals(o.getMessageID(), 1);
    assertNull(o.getProperty("propX"));
    o.setProperty("propX", "valX");
    assertNotNull(o.getProperty("propX"));
    assertEquals(o.getProperty("propX"), "valX");
    assertNotNull(o.toString());
    o.setProperty("propX", null);
    assertNull(o.getProperty("propX"));
    // Test methods specific to an intercepted modify operation.
    assertNotNull(o.getRequest());
    assertEquals(o.getRequest().getModifications().get(0).getAttribute().getValue(), "foo");
    assertNotNull(o.toString());
    final ModifyRequest r = o.getRequest().duplicate();
    r.setModifications(new Modification(ModificationType.REPLACE, "description", "bar"));
    o.setRequest(r);
    assertNotNull(o.getRequest());
    assertEquals(o.getRequest().getModifications().get(0).getAttribute().getValue(), "bar");
    assertNotNull(o.toString());
    assertNull(o.getResult());
    o.setResult(new LDAPResult(o.getMessageID(), ResultCode.SUCCESS));
    assertNotNull(o.getResult());
    assertNotNull(o.toString());
}
Also used : ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) Modification(com.unboundid.ldap.sdk.Modification) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) Test(org.testng.annotations.Test)

Example 3 with ModifyRequestProtocolOp

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

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

the class InMemoryRequestHandler method modify.

/**
 * Processes the provided modify request.
 * <BR><BR>
 * This method may be used regardless of whether the server is listening for
 * client connections, and regardless of whether modify operations are allowed
 * in the server.
 *
 * @param  modifyRequest  The modify request to be processed.  It must not be
 *                        {@code null}.
 *
 * @return  The result of processing the modify operation.
 *
 * @throws  LDAPException  If the server rejects the modify request, or if a
 *                         problem is encountered while sending the request or
 *                         reading the response.
 */
@NotNull()
public LDAPResult modify(@NotNull final ModifyRequest modifyRequest) throws LDAPException {
    final ArrayList<Control> requestControlList = new ArrayList<>(modifyRequest.getControlList());
    requestControlList.add(new Control(OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    final LDAPMessage responseMessage = processModifyRequest(1, new ModifyRequestProtocolOp(modifyRequest.getDN(), modifyRequest.getModifications()), requestControlList);
    final ModifyResponseProtocolOp modifyResponse = responseMessage.getModifyResponseProtocolOp();
    final LDAPResult ldapResult = new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(modifyResponse.getResultCode()), modifyResponse.getDiagnosticMessage(), modifyResponse.getMatchedDN(), modifyResponse.getReferralURLs(), responseMessage.getControls());
    switch(modifyResponse.getResultCode()) {
        case ResultCode.SUCCESS_INT_VALUE:
        case ResultCode.NO_OPERATION_INT_VALUE:
            return ldapResult;
        default:
            throw new LDAPException(ldapResult);
    }
}
Also used : ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) VirtualListViewRequestControl(com.unboundid.ldap.sdk.controls.VirtualListViewRequestControl) SubtreeDeleteRequestControl(com.unboundid.ldap.sdk.controls.SubtreeDeleteRequestControl) RFC3672SubentriesRequestControl(com.unboundid.ldap.sdk.controls.RFC3672SubentriesRequestControl) SimplePagedResultsControl(com.unboundid.ldap.sdk.controls.SimplePagedResultsControl) VirtualListViewResponseControl(com.unboundid.ldap.sdk.controls.VirtualListViewResponseControl) TransactionSpecificationRequestControl(com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl) DraftZeilengaLDAPNoOp12RequestControl(com.unboundid.ldap.sdk.experimental.DraftZeilengaLDAPNoOp12RequestControl) PostReadRequestControl(com.unboundid.ldap.sdk.controls.PostReadRequestControl) ProxiedAuthorizationV1RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV1RequestControl) ServerSideSortResponseControl(com.unboundid.ldap.sdk.controls.ServerSideSortResponseControl) PreReadResponseControl(com.unboundid.ldap.sdk.controls.PreReadResponseControl) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) PermissiveModifyRequestControl(com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) IgnoreNoUserModificationRequestControl(com.unboundid.ldap.sdk.unboundidds.controls.IgnoreNoUserModificationRequestControl) ProxiedAuthorizationV2RequestControl(com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV2RequestControl) ServerSideSortRequestControl(com.unboundid.ldap.sdk.controls.ServerSideSortRequestControl) PostReadResponseControl(com.unboundid.ldap.sdk.controls.PostReadResponseControl) DontUseCopyRequestControl(com.unboundid.ldap.sdk.controls.DontUseCopyRequestControl) AssertionRequestControl(com.unboundid.ldap.sdk.controls.AssertionRequestControl) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) DraftLDUPSubentriesRequestControl(com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl) PreReadRequestControl(com.unboundid.ldap.sdk.controls.PreReadRequestControl) LDAPException(com.unboundid.ldap.sdk.LDAPException) ArrayList(java.util.ArrayList) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 5 with ModifyRequestProtocolOp

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

the class InMemoryOperationInterceptorRequestHandler method processModifyRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processModifyRequest(final int messageID, @NotNull final ModifyRequestProtocolOp request, @NotNull final List<Control> controls) {
    final InterceptedModifyOperation op = new InterceptedModifyOperation(connection, messageID, request, toArray(controls));
    activeOperations.put(messageID, op);
    try {
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processModifyRequest(op);
            } catch (final LDAPException le) {
                Debug.debugException(le);
                return new LDAPMessage(messageID, new ModifyResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new ModifyResponseProtocolOp(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.processModifyRequest(messageID, new ModifyRequestProtocolOp((ModifyRequest) op.getRequest()), op.getRequest().getControlList());
        op.setResult(resultMessage.getModifyResponseProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processModifyResult(op);
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new ModifyResponseProtocolOp(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 ModifyResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
    } finally {
        activeOperations.remove(messageID);
    }
}
Also used : ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Aggregations

ModifyRequestProtocolOp (com.unboundid.ldap.protocol.ModifyRequestProtocolOp)5 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)4 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 Control (com.unboundid.ldap.sdk.Control)2 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)2 Modification (com.unboundid.ldap.sdk.Modification)2 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)2 NotNull (com.unboundid.util.NotNull)2 Test (org.testng.annotations.Test)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 AddRequestProtocolOp (com.unboundid.ldap.protocol.AddRequestProtocolOp)1 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)1 BindRequestProtocolOp (com.unboundid.ldap.protocol.BindRequestProtocolOp)1 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)1 CompareRequestProtocolOp (com.unboundid.ldap.protocol.CompareRequestProtocolOp)1 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)1 DeleteRequestProtocolOp (com.unboundid.ldap.protocol.DeleteRequestProtocolOp)1 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)1 ExtendedRequestProtocolOp (com.unboundid.ldap.protocol.ExtendedRequestProtocolOp)1