Search in sources :

Example 16 with JSONBuffer

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);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LogRecord(java.util.logging.LogRecord) JSONBuffer(com.unboundid.util.json.JSONBuffer) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 17 with JSONBuffer

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);
}
Also used : LogRecord(java.util.logging.LogRecord) JSONBuffer(com.unboundid.util.json.JSONBuffer)

Example 18 with JSONBuffer

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;
}
Also used : BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LogRecord(java.util.logging.LogRecord) JSONBuffer(com.unboundid.util.json.JSONBuffer) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Example 19 with JSONBuffer

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;
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) NotNull(com.unboundid.util.NotNull)

Example 20 with JSONBuffer

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;
}
Also used : LogRecord(java.util.logging.LogRecord) JSONBuffer(com.unboundid.util.json.JSONBuffer) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Aggregations

JSONBuffer (com.unboundid.util.json.JSONBuffer)73 Test (org.testng.annotations.Test)20 NotNull (com.unboundid.util.NotNull)16 LogRecord (java.util.logging.LogRecord)12 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)8 Date (java.util.Date)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)3 JSONException (com.unboundid.util.json.JSONException)3 DN (com.unboundid.ldap.sdk.DN)2 RDN (com.unboundid.ldap.sdk.RDN)2 JSONField (com.unboundid.util.json.JSONField)2 JSONObject (com.unboundid.util.json.JSONObject)2 JSONString (com.unboundid.util.json.JSONString)2 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)1 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)1 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)1 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)1 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)1 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)1