use of com.unboundid.util.json.JSONBuffer 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);
}
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processAbandonRequest.
/**
* {@inheritDoc}
*/
@Override()
public void processAbandonRequest(final int messageID, @NotNull final AbandonRequestProtocolOp request, @NotNull final List<Control> controls) {
final JSONBuffer buffer = getRequestHeader("abandon", nextOperationID.incrementAndGet(), messageID);
buffer.appendNumber("id-to-abandon", request.getIDToAbandon());
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
requestHandler.processAbandonRequest(messageID, request, controls);
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method processBindRequest.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
final long opID = nextOperationID.getAndIncrement();
final JSONBuffer buffer = getRequestHeader("bind", opID, messageID);
buffer.appendNumber("ldap-version", request.getVersion());
buffer.appendString("dn", request.getBindDN());
switch(request.getCredentialsType()) {
case BindRequestProtocolOp.CRED_TYPE_SIMPLE:
buffer.appendString("authentication-type", "simple");
break;
case BindRequestProtocolOp.CRED_TYPE_SASL:
buffer.appendString("authentication-type", "sasl");
buffer.appendString("sasl-mechanism", request.getSASLMechanism());
break;
}
buffer.endObject();
logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
logHandler.flush();
final long startTimeNanos = System.nanoTime();
final LDAPMessage responseMessage = requestHandler.processBindRequest(messageID, request, controls);
final long eTimeNanos = System.nanoTime() - startTimeNanos;
final BindResponseProtocolOp protocolOp = responseMessage.getBindResponseProtocolOp();
generateResponse(buffer, "bind", 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.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class JSONAccessLogRequestHandler method getRequestHeader.
/**
* Retrieves a {@code JSONBuffer} with header information for a request log
* message for the specified type of operation.
*
* @param opType The type of operation being requested.
* @param opID The operation ID for the request.
* @param msgID The message ID for the request.
*
* @return A {@code StringBuilder} with header information appended for the
* request;
*/
@NotNull()
private JSONBuffer getRequestHeader(@NotNull final String opType, final long opID, final int msgID) {
final JSONBuffer buffer = getBuffer();
buffer.beginObject();
addTimestamp(buffer);
buffer.appendString("message-type", "request");
buffer.appendString("operation-type", opType);
buffer.appendNumber("connection-id", clientConnection.getConnectionID());
buffer.appendNumber("operation-id", opID);
buffer.appendNumber("message-id", msgID);
return buffer;
}
use of com.unboundid.util.json.JSONBuffer 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;
}
Aggregations