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);
}
}
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()));
}
}
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);
}
}
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());
}
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());
}
Aggregations