Search in sources :

Example 1 with AccessLogOperationType

use of com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType in project ldapsdk by pingidentity.

the class TextFormattedAccessLogReader method parseMessage.

/**
 * Parses the contents of the provided string as a JSON-formatted access log
 * message.
 *
 * @param  messageString  The string to parse as an access log message.  It
 *                        must not be {@code null}.
 *
 * @return  The parsed access log message.
 *
 * @throws  LogException  If the provided JSON object cannot be parsed as a
 *                        valid access log message.
 */
@NotNull()
public static TextFormattedAccessLogMessage parseMessage(@NotNull final String messageString) throws LogException {
    // Parse the line as a generic log message, which will give us access to
    // all of its fields.
    final TextFormattedLogMessage m = new TextFormattedLogMessage(messageString);
    // Make sure that the message has at least one field without a name.
    final List<String> unnamedFields = m.getFields().get(TextFormattedLogMessage.NO_FIELD_NAME);
    if ((unnamedFields == null) || unnamedFields.isEmpty()) {
        throw new LogException(messageString, ERR_TEXT_ACCESS_READER_CANNOT_DETERMINE_MESSAGE_TYPE.get(messageString));
    }
    // Look at the first unnamed field.  For messages that are not associated
    // with an operation, then it will be the message type.  For messages that
    // are associated with an operation, then the operation type will come
    // first, so it's okay if we can't parse the first unnamed field value as a
    // message type.
    final String messageOrOpType = unnamedFields.get(0);
    AccessLogMessageType messageType = AccessLogMessageType.forName(messageOrOpType);
    if (messageType != null) {
        switch(messageType) {
            case CONNECT:
                return new TextFormattedConnectAccessLogMessage(m);
            case DISCONNECT:
                return new TextFormattedDisconnectAccessLogMessage(m);
            case SECURITY_NEGOTIATION:
                return new TextFormattedSecurityNegotiationAccessLogMessage(m);
            case CLIENT_CERTIFICATE:
                return new TextFormattedClientCertificateAccessLogMessage(m);
            case ENTRY_REBALANCING_REQUEST:
                return new TextFormattedEntryRebalancingRequestAccessLogMessage(m);
            case ENTRY_REBALANCING_RESULT:
                return new TextFormattedEntryRebalancingResultAccessLogMessage(m);
            default:
                throw new LogException(messageString, ERR_TEXT_ACCESS_READER_CANNOT_DETERMINE_MESSAGE_TYPE.get(messageString));
        }
    }
    // If we've gotten here, then we expect the first unnamed field to be the
    // operation type, and the second field will be the message type.
    final AccessLogOperationType opType = AccessLogOperationType.forName(messageOrOpType);
    if (opType == null) {
        throw new LogException(messageString, ERR_TEXT_ACCESS_READER_CANNOT_DETERMINE_MESSAGE_TYPE.get(messageOrOpType));
    }
    if (unnamedFields.size() < 2) {
        throw new LogException(messageString, ERR_TEXT_ACCESS_READER_CANNOT_DETERMINE_MESSAGE_TYPE.get(messageString));
    }
    messageType = AccessLogMessageType.forName(unnamedFields.get(1));
    if (messageType == null) {
        throw new LogException(messageString, ERR_TEXT_ACCESS_READER_CANNOT_DETERMINE_MESSAGE_TYPE.get(messageString));
    }
    switch(messageType) {
        case REQUEST:
            switch(opType) {
                case ABANDON:
                    return new TextFormattedAbandonRequestAccessLogMessage(m);
                case ADD:
                    return new TextFormattedAddRequestAccessLogMessage(m);
                case BIND:
                    return new TextFormattedBindRequestAccessLogMessage(m);
                case COMPARE:
                    return new TextFormattedCompareRequestAccessLogMessage(m);
                case DELETE:
                    return new TextFormattedDeleteRequestAccessLogMessage(m);
                case EXTENDED:
                    return new TextFormattedExtendedRequestAccessLogMessage(m);
                case MODIFY:
                    return new TextFormattedModifyRequestAccessLogMessage(m);
                case MODDN:
                    return new TextFormattedModifyDNRequestAccessLogMessage(m);
                case SEARCH:
                    return new TextFormattedSearchRequestAccessLogMessage(m);
                case UNBIND:
                    return new TextFormattedUnbindRequestAccessLogMessage(m);
                default:
                    throw new LogException(messageString, ERR_TEXT_ACCESS_READER_UNSUPPORTED_REQUEST_OP_TYPE.get(messageString));
            }
        case FORWARD:
            switch(opType) {
                case ABANDON:
                    return new TextFormattedAbandonForwardAccessLogMessage(m);
                case ADD:
                    return new TextFormattedAddForwardAccessLogMessage(m);
                case BIND:
                    return new TextFormattedBindForwardAccessLogMessage(m);
                case COMPARE:
                    return new TextFormattedCompareForwardAccessLogMessage(m);
                case DELETE:
                    return new TextFormattedDeleteForwardAccessLogMessage(m);
                case EXTENDED:
                    return new TextFormattedExtendedForwardAccessLogMessage(m);
                case MODIFY:
                    return new TextFormattedModifyForwardAccessLogMessage(m);
                case MODDN:
                    return new TextFormattedModifyDNForwardAccessLogMessage(m);
                case SEARCH:
                    return new TextFormattedSearchForwardAccessLogMessage(m);
                case UNBIND:
                default:
                    throw new LogException(messageString, ERR_TEXT_ACCESS_READER_UNSUPPORTED_FORWARD_OP_TYPE.get(messageString));
            }
        case FORWARD_FAILED:
            switch(opType) {
                case ABANDON:
                    return new TextFormattedAbandonForwardFailedAccessLogMessage(m);
                case ADD:
                    return new TextFormattedAddForwardFailedAccessLogMessage(m);
                case BIND:
                    return new TextFormattedBindForwardFailedAccessLogMessage(m);
                case COMPARE:
                    return new TextFormattedCompareForwardFailedAccessLogMessage(m);
                case DELETE:
                    return new TextFormattedDeleteForwardFailedAccessLogMessage(m);
                case EXTENDED:
                    return new TextFormattedExtendedForwardFailedAccessLogMessage(m);
                case MODIFY:
                    return new TextFormattedModifyForwardFailedAccessLogMessage(m);
                case MODDN:
                    return new TextFormattedModifyDNForwardFailedAccessLogMessage(m);
                case SEARCH:
                    return new TextFormattedSearchForwardFailedAccessLogMessage(m);
                case UNBIND:
                default:
                    throw new LogException(messageString, ERR_TEXT_ACCESS_READER_UNSUPPORTED_FORWARD_FAILED_OP_TYPE.get(messageString));
            }
        case RESULT:
            switch(opType) {
                case ABANDON:
                    return new TextFormattedAbandonResultAccessLogMessage(m);
                case ADD:
                    return new TextFormattedAddResultAccessLogMessage(m);
                case BIND:
                    return new TextFormattedBindResultAccessLogMessage(m);
                case COMPARE:
                    return new TextFormattedCompareResultAccessLogMessage(m);
                case DELETE:
                    return new TextFormattedDeleteResultAccessLogMessage(m);
                case EXTENDED:
                    return new TextFormattedExtendedResultAccessLogMessage(m);
                case MODIFY:
                    return new TextFormattedModifyResultAccessLogMessage(m);
                case MODDN:
                    return new TextFormattedModifyDNResultAccessLogMessage(m);
                case SEARCH:
                    return new TextFormattedSearchResultAccessLogMessage(m);
                case UNBIND:
                default:
                    throw new LogException(messageString, ERR_TEXT_ACCESS_READER_UNSUPPORTED_RESULT_OP_TYPE.get(messageString));
            }
        case ASSURANCE_COMPLETE:
            switch(opType) {
                case ADD:
                    return new TextFormattedAddAssuranceCompletedAccessLogMessage(m);
                case DELETE:
                    return new TextFormattedDeleteAssuranceCompletedAccessLogMessage(m);
                case MODIFY:
                    return new TextFormattedModifyAssuranceCompletedAccessLogMessage(m);
                case MODDN:
                    return new TextFormattedModifyDNAssuranceCompletedAccessLogMessage(m);
                case ABANDON:
                case BIND:
                case COMPARE:
                case EXTENDED:
                case SEARCH:
                case UNBIND:
                default:
                    throw new LogException(messageString, ERR_TEXT_ACCESS_READER_UNSUPPORTED_ASSURANCE_OP_TYPE.get(messageString));
            }
        case ENTRY:
            return new TextFormattedSearchEntryAccessLogMessage(m);
        case REFERENCE:
            return new TextFormattedSearchReferenceAccessLogMessage(m);
        case INTERMEDIATE_RESPONSE:
            return new TextFormattedIntermediateResponseAccessLogMessage(m, opType);
        default:
            throw new LogException(messageString, ERR_TEXT_ACCESS_READER_CANNOT_DETERMINE_MESSAGE_TYPE.get(messageString));
    }
}
Also used : AccessLogOperationType(com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType) AccessLogMessageType(com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) NotNull(com.unboundid.util.NotNull)

Example 2 with AccessLogOperationType

use of com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType in project ldapsdk by pingidentity.

the class JSONAccessLogReader method getOperationType.

/**
 * Determines the operation type for the JSON-formatted access log message
 * encoded in the provided JSON object.
 *
 * @param  messageObject  The JSON object containing an encoded representation
 *                        of an access log message.  It must not be
 *                        {@code null}.
 *
 * @return  The operation type extracted from the provided JSON object.
 *
 * @throws  LogException  If it is not possible to extract a valid operation
 *                        type from the provided JSON object.
 */
@NotNull()
private static AccessLogOperationType getOperationType(@NotNull final JSONObject messageObject) throws LogException {
    final String opTypeStr = messageObject.getFieldAsString(JSONFormattedAccessLogFields.OPERATION_TYPE.getFieldName());
    if (opTypeStr == null) {
        final String messageStr = messageObject.toSingleLineString();
        throw new LogException(messageStr, ERR_JSON_ACCESS_LOG_READER_MISSING_OPERATION_TYPE.get(messageStr, JSONFormattedAccessLogFields.OPERATION_TYPE.getFieldName()));
    }
    final AccessLogOperationType opType = AccessLogOperationType.forName(opTypeStr);
    if (opType == null) {
        final String messageStr = messageObject.toSingleLineString();
        throw new LogException(messageStr, ERR_JSON_ACCESS_LOG_READER_UNSUPPORTED_OPERATION_TYPE.get(messageStr, opTypeStr));
    }
    return opType;
}
Also used : AccessLogOperationType(com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType) LogException(com.unboundid.ldap.sdk.unboundidds.logs.LogException) NotNull(com.unboundid.util.NotNull)

Aggregations

AccessLogOperationType (com.unboundid.ldap.sdk.unboundidds.logs.AccessLogOperationType)2 LogException (com.unboundid.ldap.sdk.unboundidds.logs.LogException)2 NotNull (com.unboundid.util.NotNull)2 AccessLogMessageType (com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType)1