use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class InMemoryRequestHandler method modifyDN.
/**
* Processes the provided modify DN request.
* <BR><BR>
* This method may be used regardless of whether the server is listening for
* client connections, and regardless of whether modify DN operations are
* allowed in the server.
*
* @param modifyDNRequest The modify DN request to be processed. It must
* not be {@code null}.
*
* @return The result of processing the modify DN operation.
*
* @throws LDAPException If the server rejects the modify DN request, or if
* a problem is encountered while sending the request
* or reading the response.
*/
@NotNull()
public LDAPResult modifyDN(@NotNull final ModifyDNRequest modifyDNRequest) throws LDAPException {
final ArrayList<Control> requestControlList = new ArrayList<>(modifyDNRequest.getControlList());
requestControlList.add(new Control(OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
final LDAPMessage responseMessage = processModifyDNRequest(1, new ModifyDNRequestProtocolOp(modifyDNRequest.getDN(), modifyDNRequest.getNewRDN(), modifyDNRequest.deleteOldRDN(), modifyDNRequest.getNewSuperiorDN()), requestControlList);
final ModifyDNResponseProtocolOp modifyDNResponse = responseMessage.getModifyDNResponseProtocolOp();
final LDAPResult ldapResult = new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(modifyDNResponse.getResultCode()), modifyDNResponse.getDiagnosticMessage(), modifyDNResponse.getMatchedDN(), modifyDNResponse.getReferralURLs(), responseMessage.getControls());
switch(modifyDNResponse.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.LDAPMessage 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()));
}
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processAddRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processAddRequest(final int messageID, @NotNull final AddRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final JSONBuffer buffer = getRequestHeader("add", 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.processAddRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final AddResponseProtocolOp protocolOp = responseMessage.getAddResponseProtocolOp();
generateResponse(buffer, "add", 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.LDAPMessage in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processExtendedRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final JSONBuffer buffer = getRequestHeader("extended", opID, messageID);
buffer.appendString("request-oid", request.getOID());
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processExtendedRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final ExtendedResponseProtocolOp protocolOp = responseMessage.getExtendedResponseProtocolOp();
generateResponse(buffer, "extended", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
final String responseOID = protocolOp.getResponseOID();
if (responseOID != null) {
buffer.appendString("response-oid", responseOID);
}
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
return responseMessage;
}
use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processSearchRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final JSONBuffer buffer = getRequestHeader("search", opID, messageID);
buffer.appendString("base", request.getBaseDN());
buffer.appendNumber("scope", request.getScope().intValue());
buffer.appendString("filter", request.getFilter().toString());
buffer.beginArray("requested-attributes");
for (final String requestedAttribute : request.getAttributes()) {
buffer.appendString(requestedAttribute);
}
buffer.endArray();
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
final AtomicLong entryCounter = new AtomicLong(0L);
entryCounts.put(messageID, entryCounter);
try {
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processSearchRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final SearchResultDoneProtocolOp protocolOp = responseMessage.getSearchResultDoneProtocolOp();
generateResponse(buffer, "search", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
buffer.appendNumber("entries-returned", entryCounter.get());
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
return responseMessage;
} finally {
entryCounts.remove(messageID);
}
}
Aggregations