Search in sources :

Example 1 with AddRequestProtocolOp

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

the class InMemoryRequestHandler method add.

/**
 * Processes the provided add request.
 * <BR><BR>
 * This method may be used regardless of whether the server is listening for
 * client connections, and regardless of whether add operations are allowed in
 * the server.
 *
 * @param  addRequest  The add request to be processed.  It must not be
 *                     {@code null}.
 *
 * @return  The result of processing the add operation.
 *
 * @throws  LDAPException  If the server rejects the add request, or if a
 *                         problem is encountered while sending the request or
 *                         reading the response.
 */
@NotNull()
public LDAPResult add(@NotNull final AddRequest addRequest) throws LDAPException {
    final ArrayList<Control> requestControlList = new ArrayList<>(addRequest.getControlList());
    requestControlList.add(new Control(OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    final LDAPMessage responseMessage = processAddRequest(1, new AddRequestProtocolOp(addRequest.getDN(), addRequest.getAttributes()), requestControlList);
    final AddResponseProtocolOp addResponse = responseMessage.getAddResponseProtocolOp();
    final LDAPResult ldapResult = new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(addResponse.getResultCode()), addResponse.getDiagnosticMessage(), addResponse.getMatchedDN(), addResponse.getReferralURLs(), responseMessage.getControls());
    switch(addResponse.getResultCode()) {
        case ResultCode.SUCCESS_INT_VALUE:
        case ResultCode.NO_OPERATION_INT_VALUE:
            return ldapResult;
        default:
            throw new LDAPException(ldapResult);
    }
}
Also used : 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) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) ArrayList(java.util.ArrayList) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 2 with AddRequestProtocolOp

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

the class InMemoryRequestHandler method addEntry.

/**
 * Attempts to add the provided entry to the in-memory data set.  The attempt
 * will fail if any of the following conditions is true:
 * <UL>
 *   <LI>The provided entry has a malformed DN.</LI>
 *   <LI>The provided entry has the null DN.</LI>
 *   <LI>The provided entry has a DN that is the same as or subordinate to the
 *       subschema subentry.</LI>
 *   <LI>An entry already exists with the same DN as the entry in the provided
 *       request.</LI>
 *   <LI>The entry is outside the set of base DNs for the server.</LI>
 *   <LI>The entry is below one of the defined base DNs but the immediate
 *       parent entry does not exist.</LI>
 *   <LI>If a schema was provided, and the entry is not valid according to the
 *       constraints of that schema.</LI>
 * </UL>
 *
 * @param  entry                     The entry to be added.  It must not be
 *                                   {@code null}.
 * @param  ignoreNoUserModification  Indicates whether to ignore constraints
 *                                   normally imposed by the
 *                                   NO-USER-MODIFICATION element in attribute
 *                                   type definitions.
 *
 * @throws  LDAPException  If a problem occurs while attempting to add the
 *                         provided entry.
 */
public void addEntry(@NotNull final Entry entry, final boolean ignoreNoUserModification) throws LDAPException {
    final List<Control> controls;
    if (ignoreNoUserModification) {
        controls = new ArrayList<>(1);
        controls.add(new Control(OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    } else {
        controls = Collections.emptyList();
    }
    final AddRequestProtocolOp addRequest = new AddRequestProtocolOp(entry.getDN(), new ArrayList<>(entry.getAttributes()));
    final LDAPMessage resultMessage = processAddRequest(-1, addRequest, controls);
    final AddResponseProtocolOp addResponse = resultMessage.getAddResponseProtocolOp();
    if (addResponse.getResultCode() != ResultCode.SUCCESS_INT_VALUE) {
        throw new LDAPException(ResultCode.valueOf(addResponse.getResultCode()), addResponse.getDiagnosticMessage(), addResponse.getMatchedDN(), stringListToArray(addResponse.getReferralURLs()));
    }
}
Also used : 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) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp)

Example 3 with AddRequestProtocolOp

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

the class InMemoryOperationInterceptorRequestHandler method processAddRequest.

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

Example 4 with AddRequestProtocolOp

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

the class InterceptedAddOperationTestCase method testBasics.

/**
 * Provides basic test coverage for an intercepted add operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBasics() throws Exception {
    // Create an intercepted add operation.  We'll use a null connection, which
    // shouldn't happen naturally but will be sufficient for this test.
    final AddRequestProtocolOp requestOp = new AddRequestProtocolOp(new AddRequest("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example"));
    final InterceptedAddOperation o = new InterceptedAddOperation(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 add operation.
    assertNotNull(o.getRequest());
    assertFalse(o.getRequest().hasAttribute("description"));
    final AddRequest r = o.getRequest().duplicate();
    r.addAttribute("description", "foo");
    o.setRequest(r);
    assertNotNull(o.getRequest());
    assertTrue(o.getRequest().hasAttributeValue("description", "foo"));
    assertNotNull(o.toString());
    assertNull(o.getResult());
    o.setResult(new LDAPResult(o.getMessageID(), ResultCode.SUCCESS));
    assertNotNull(o.getResult());
    assertNotNull(o.toString());
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) Test(org.testng.annotations.Test)

Example 5 with AddRequestProtocolOp

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

the class InterceptedIntermediateResponseTestCase method testBasics.

/**
 * Provides basic test coverage for an intercepted intermediate response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBasics() throws Exception {
    // Create an intercepted intermediate response.  We'll use a null
    // connection, which shouldn't happen naturally but will be sufficient for
    // this test.
    final AddRequestProtocolOp requestOp = new AddRequestProtocolOp(new AddRequest("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example"));
    final InterceptedAddOperation o = new InterceptedAddOperation(null, 1, requestOp);
    assertNotNull(o.toString());
    final IntermediateResponseProtocolOp responseOp = new IntermediateResponseProtocolOp(new IntermediateResponse("1.2.3.4", null));
    final InterceptedIntermediateResponse r = new InterceptedIntermediateResponse(o, responseOp);
    assertNotNull(r.toString());
    // Test methods for a generic intercepted operation.
    assertNull(r.getClientConnection());
    assertEquals(r.getConnectionID(), -1L);
    assertNull(r.getConnectedAddress());
    assertEquals(r.getConnectedPort(), -1);
    assertEquals(r.getMessageID(), 1);
    assertNull(r.getProperty("propX"));
    r.setProperty("propX", "valX");
    assertNotNull(r.getProperty("propX"));
    assertEquals(r.getProperty("propX"), "valX");
    assertNotNull(r.toString());
    r.setProperty("propX", null);
    assertNull(r.getProperty("propX"));
    // Test methods specific to an intercepted compare operation.
    assertNotNull(r.getRequest());
    assertNotNull(r.getIntermediateResponse());
    assertEquals(r.getIntermediateResponse().getOID(), "1.2.3.4");
    assertNotNull(r.toString());
    r.setIntermediateResponse(new IntermediateResponse("5.6.7.8", null));
    assertEquals(r.getIntermediateResponse().getOID(), "5.6.7.8");
    assertNotNull(r.toString());
    r.setIntermediateResponse(null);
    assertNull(r.getIntermediateResponse());
    assertNotNull(r.toString());
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) Test(org.testng.annotations.Test)

Aggregations

AddRequestProtocolOp (com.unboundid.ldap.protocol.AddRequestProtocolOp)6 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)4 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)4 AddRequest (com.unboundid.ldap.sdk.AddRequest)3 Control (com.unboundid.ldap.sdk.Control)3 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 Test (org.testng.annotations.Test)3 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)2 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)2 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)2 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)2 DontUseCopyRequestControl (com.unboundid.ldap.sdk.controls.DontUseCopyRequestControl)2 DraftLDUPSubentriesRequestControl (com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl)2 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)2 PermissiveModifyRequestControl (com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl)2 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)2 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)2 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)2 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)2 ProxiedAuthorizationV1RequestControl (com.unboundid.ldap.sdk.controls.ProxiedAuthorizationV1RequestControl)2