Search in sources :

Example 11 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class JSONLDAPConnectionLogger method logBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void logBindRequest(@NotNull final LDAPConnectionInfo connectionInfo, final int messageID, @NotNull final SASLBindRequest bindRequest) {
    if (logRequests && operationTypes.contains(OperationType.BIND)) {
        final JSONBuffer buffer = startLogMessage("request", OperationType.BIND, connectionInfo, messageID);
        buffer.appendString("authentication-type", "SASL");
        buffer.appendString("sasl-mechanism", bindRequest.getSASLMechanismName());
        appendControls(buffer, "control-oids", bindRequest.getControls());
        logMessage(buffer, flushAfterRequestMessages);
    }
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer)

Example 12 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class JSONLDAPConnectionLogger method logBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void logBindRequest(@NotNull final LDAPConnectionInfo connectionInfo, final int messageID, @NotNull final SimpleBindRequest bindRequest) {
    if (logRequests && operationTypes.contains(OperationType.BIND)) {
        final JSONBuffer buffer = startLogMessage("request", OperationType.BIND, connectionInfo, messageID);
        buffer.appendString("authentication-type", "simple");
        appendDN(buffer, "dn", bindRequest.getBindDN());
        appendControls(buffer, "control-oids", bindRequest.getControls());
        logMessage(buffer, flushAfterRequestMessages);
    }
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer)

Example 13 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class JSONAccessLogRequestHandler method newInstance.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public JSONAccessLogRequestHandler newInstance(@NotNull final LDAPListenerClientConnection connection) throws LDAPException {
    final JSONAccessLogRequestHandler h = new JSONAccessLogRequestHandler(logHandler, requestHandler.newInstance(connection), connection, jsonBuffers, timestampFormatters, decimalFormatters);
    connection.addSearchEntryTransformer(h);
    final JSONBuffer buffer = h.getConnectionHeader("connect");
    final Socket s = connection.getSocket();
    buffer.appendString("from-address", s.getInetAddress().getHostAddress());
    buffer.appendNumber("from-port", s.getPort());
    buffer.appendString("to-address", s.getLocalAddress().getHostAddress());
    buffer.appendNumber("to-port", s.getLocalPort());
    buffer.endObject();
    logHandler.publish(new LogRecord(Level.INFO, buffer.toString()));
    logHandler.flush();
    return h;
}
Also used : LogRecord(java.util.logging.LogRecord) JSONBuffer(com.unboundid.util.json.JSONBuffer) Socket(java.net.Socket) NotNull(com.unboundid.util.NotNull)

Example 14 with JSONBuffer

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

Example 15 with JSONBuffer

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