use of com.unboundid.ldap.protocol.DeleteResponseProtocolOp in project ldapsdk by pingidentity.
the class InMemoryRequestHandler method processDeleteRequest.
/**
* Attempts to process the provided delete request. The attempt will fail if
* any of the following conditions is true:
* <UL>
* <LI>There is a problem with any of the request controls.</LI>
* <LI>The delete request contains a malformed target DN.</LI>
* <LI>The target entry is the root DSE.</LI>
* <LI>The target entry is the subschema subentry.</LI>
* <LI>The target entry is at or below the changelog base entry.</LI>
* <LI>The target entry does not exist.</LI>
* <LI>The target entry has one or more subordinate entries.</LI>
* </UL>
*
* @param messageID The message ID of the LDAP message containing the delete
* request.
* @param request The delete request that was included in the LDAP message
* that was received.
* @param controls The set of controls included in the LDAP message. It
* may be empty if there were no controls, but will not be
* {@code null}.
*
* @return The {@link LDAPMessage} containing the response to send to the
* client. The protocol op in the {@code LDAPMessage} must be a
* {@code DeleteResponseProtocolOp}.
*/
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
synchronized (entryMap) {
// Sleep before processing, if appropriate.
sleepBeforeProcessing();
// Process the provided request controls.
final Map<String, Control> controlMap;
try {
controlMap = RequestControlPreProcessor.processControls(LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST, controls);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(le.getResultCode().intValue(), null, le.getMessage(), null));
}
final ArrayList<Control> responseControls = new ArrayList<>(1);
// If this operation type is not allowed, then reject it.
final boolean isInternalOp = controlMap.containsKey(OID_INTERNAL_OPERATION_REQUEST_CONTROL);
if ((!isInternalOp) && (!config.getAllowedOperationTypes().contains(OperationType.DELETE))) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.UNWILLING_TO_PERFORM_INT_VALUE, null, ERR_MEM_HANDLER_DELETE_NOT_ALLOWED.get(), null));
}
// client is authenticated.
if ((authenticatedDN.isNullDN() && config.getAuthenticationRequiredOperationTypes().contains(OperationType.DELETE))) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.INSUFFICIENT_ACCESS_RIGHTS_INT_VALUE, null, ERR_MEM_HANDLER_DELETE_REQUIRES_AUTH.get(), null));
}
// without actually doing any further processing.
try {
final ASN1OctetString txnID = processTransactionRequest(messageID, request, controlMap);
if (txnID != null) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.SUCCESS_INT_VALUE, null, INFO_MEM_HANDLER_OP_IN_TXN.get(txnID.stringValue()), null));
}
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(), le.getDiagnosticMessage(), StaticUtils.toList(le.getReferralURLs())), le.getResponseControls());
}
// Get the parsed target DN.
final DN dn;
try {
dn = new DN(request.getDN(), schemaRef.get());
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.INVALID_DN_SYNTAX_INT_VALUE, null, ERR_MEM_HANDLER_DELETE_MALFORMED_DN.get(request.getDN(), le.getMessage()), null));
}
// See if the target entry or one of its superiors is a smart referral.
if (!controlMap.containsKey(ManageDsaITRequestControl.MANAGE_DSA_IT_REQUEST_OID)) {
final Entry referralEntry = findNearestReferral(dn);
if (referralEntry != null) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.REFERRAL_INT_VALUE, referralEntry.getDN(), INFO_MEM_HANDLER_REFERRAL_ENCOUNTERED.get(), getReferralURLs(dn, referralEntry)));
}
}
// entry.
if (dn.isNullDN()) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.UNWILLING_TO_PERFORM_INT_VALUE, null, ERR_MEM_HANDLER_DELETE_ROOT_DSE.get(), null));
} else if (dn.equals(subschemaSubentryDN)) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.UNWILLING_TO_PERFORM_INT_VALUE, null, ERR_MEM_HANDLER_DELETE_SCHEMA.get(subschemaSubentryDN.toString()), null));
} else if (dn.isDescendantOf(changeLogBaseDN, true)) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.UNWILLING_TO_PERFORM_INT_VALUE, null, ERR_MEM_HANDLER_DELETE_CHANGELOG.get(request.getDN()), null));
}
// Get the target entry. If it does not exist, then fail.
final Entry entry = entryMap.get(dn);
if (entry == null) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.NO_SUCH_OBJECT_INT_VALUE, getMatchedDNString(dn), ERR_MEM_HANDLER_DELETE_NO_SUCH_ENTRY.get(request.getDN()), null));
}
// Create a list with the DN of the target entry, and all the DNs of its
// subordinates. If the entry has subordinates and the subtree delete
// control was not provided, then fail.
final ArrayList<DN> subordinateDNs = new ArrayList<>(entryMap.size());
for (final DN mapEntryDN : entryMap.keySet()) {
if (mapEntryDN.isDescendantOf(dn, false)) {
subordinateDNs.add(mapEntryDN);
}
}
if ((!subordinateDNs.isEmpty()) && (!controlMap.containsKey(SubtreeDeleteRequestControl.SUBTREE_DELETE_REQUEST_OID))) {
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.NOT_ALLOWED_ON_NONLEAF_INT_VALUE, null, ERR_MEM_HANDLER_DELETE_HAS_SUBORDINATES.get(request.getDN()), null));
}
// Handle the necessary processing for the assertion, pre-read, and
// proxied auth controls.
final DN authzDN;
try {
handleAssertionRequestControl(controlMap, entry);
final PreReadResponseControl preReadResponse = handlePreReadControl(controlMap, entry);
if (preReadResponse != null) {
responseControls.add(preReadResponse);
}
authzDN = handleProxiedAuthControl(controlMap);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(le.getResultCode().intValue(), null, le.getMessage(), null));
}
// that the changelog will show the deletes in the appropriate order.
for (int i = (subordinateDNs.size() - 1); i >= 0; i--) {
final DN subordinateDN = subordinateDNs.get(i);
final Entry subEntry = entryMap.remove(subordinateDN);
indexDelete(subEntry);
addDeleteChangeLogEntry(subEntry, authzDN);
handleReferentialIntegrityDelete(subordinateDN);
}
// Finally, remove the target entry and create a changelog entry for it.
entryMap.remove(dn);
indexDelete(entry);
addDeleteChangeLogEntry(entry, authzDN);
handleReferentialIntegrityDelete(dn);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.SUCCESS_INT_VALUE, null, null, null), responseControls);
}
}
use of com.unboundid.ldap.protocol.DeleteResponseProtocolOp in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processDeleteRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final JSONBuffer buffer = getRequestHeader("delete", opID, messageID);
buffer.appendString("dn", request.getDN());
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processDeleteRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final DeleteResponseProtocolOp protocolOp = responseMessage.getDeleteResponseProtocolOp();
generateResponse(buffer, "delete", 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;
}
use of com.unboundid.ldap.protocol.DeleteResponseProtocolOp in project ldapsdk by pingidentity.
the class LDAPListenerClientConnection method run.
/**
* Operates in a loop, waiting for a request to arrive from the client and
* handing it off to the request handler for processing. This method is for
* internal use only and must not be invoked by external callers.
*/
@InternalUseOnly()
@Override()
public void run() {
try {
while (true) {
final LDAPMessage requestMessage;
try {
requestMessage = LDAPMessage.readFrom(asn1Reader, false);
if (requestMessage == null) {
// so we won't notify the exception handler.
try {
close();
} catch (final IOException ioe) {
Debug.debugException(ioe);
}
return;
}
} catch (final LDAPException le) {
// This indicates that the client sent a malformed request.
Debug.debugException(le);
close(le);
return;
}
try {
final int messageID = requestMessage.getMessageID();
final List<Control> controls = requestMessage.getControls();
LDAPMessage responseMessage;
switch(requestMessage.getProtocolOpType()) {
case LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST:
requestHandler.processAbandonRequest(messageID, requestMessage.getAbandonRequestProtocolOp(), controls);
responseMessage = null;
break;
case LDAPMessage.PROTOCOL_OP_TYPE_ADD_REQUEST:
try {
responseMessage = requestHandler.processAddRequest(messageID, requestMessage.getAddRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new AddResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_BIND_REQUEST:
try {
responseMessage = requestHandler.processBindRequest(messageID, requestMessage.getBindRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_REQUEST:
try {
responseMessage = requestHandler.processCompareRequest(messageID, requestMessage.getCompareRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST:
try {
responseMessage = requestHandler.processDeleteRequest(messageID, requestMessage.getDeleteRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_EXTENDED_REQUEST:
try {
responseMessage = requestHandler.processExtendedRequest(messageID, requestMessage.getExtendedRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ExtendedResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null, null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_REQUEST:
try {
responseMessage = requestHandler.processModifyRequest(messageID, requestMessage.getModifyRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ModifyResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_REQUEST:
try {
responseMessage = requestHandler.processModifyDNRequest(messageID, requestMessage.getModifyDNRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST:
try {
responseMessage = requestHandler.processSearchRequest(messageID, requestMessage.getSearchRequestProtocolOp(), controls);
} catch (final Exception e) {
Debug.debugException(e);
responseMessage = new LDAPMessage(messageID, new SearchResultDoneProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
}
break;
case LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST:
requestHandler.processUnbindRequest(messageID, requestMessage.getUnbindRequestProtocolOp(), controls);
close();
return;
default:
close(new LDAPException(ResultCode.PROTOCOL_ERROR, ERR_CONN_INVALID_PROTOCOL_OP_TYPE.get(StaticUtils.toHex(requestMessage.getProtocolOpType()))));
return;
}
if (responseMessage != null) {
try {
sendMessage(responseMessage);
} catch (final LDAPException le) {
Debug.debugException(le);
close(le);
return;
}
}
} catch (final Throwable t) {
close(new LDAPException(ResultCode.LOCAL_ERROR, ERR_CONN_EXCEPTION_IN_REQUEST_HANDLER.get(String.valueOf(requestMessage), StaticUtils.getExceptionMessage(t))));
StaticUtils.throwErrorOrRuntimeException(t);
}
}
} finally {
if (listener != null) {
listener.connectionClosed(this);
}
}
}
use of com.unboundid.ldap.protocol.DeleteResponseProtocolOp in project ldapsdk by pingidentity.
the class InMemoryOperationInterceptorRequestHandler method processDeleteRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
final InterceptedDeleteOperation op = new InterceptedDeleteOperation(connection, messageID, request, toArray(controls));
activeOperations.put(messageID, op);
try {
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processDeleteRequest(op);
} catch (final LDAPException le) {
Debug.debugException(le);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(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.processDeleteRequest(messageID, new DeleteRequestProtocolOp((DeleteRequest) op.getRequest()), op.getRequest().getControlList());
op.setResult(resultMessage.getDeleteResponseProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
for (final InMemoryOperationInterceptor i : interceptors) {
try {
i.processDeleteResult(op);
} catch (final Exception e) {
Debug.debugException(e);
return new LDAPMessage(messageID, new DeleteResponseProtocolOp(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 DeleteResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
} finally {
activeOperations.remove(messageID);
}
}
use of com.unboundid.ldap.protocol.DeleteResponseProtocolOp in project ldapsdk by pingidentity.
the class AccessLogRequestHandler method processDeleteRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processDeleteRequest(final int messageID, @NotNull final DeleteRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final StringBuilder b = getRequestHeader("DELETE", opID, messageID);
b.append(" dn=\"");
b.append(request.getDN());
b.append('"');
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processDeleteRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final DeleteResponseProtocolOp protocolOp = responseMessage.getDeleteResponseProtocolOp();
generateResponse(b, "DELETE", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
logHandler.publish(new LogRecord(Level.INFO, b.toString()));
logHandler.flush();
return responseMessage;
}
Aggregations