use of com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType 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));
}
}
use of com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType in project ldapsdk by pingidentity.
the class JSONAccessLogReader method parseMessage.
/**
* Parses the contents of the provided JSON object as a JSON-formatted access
* log message.
*
* @param messageObject The JSON object 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 JSONAccessLogMessage parseMessage(@NotNull final JSONObject messageObject) throws LogException {
// Determine the message type for the log message.
final String messageTypeStr = messageObject.getFieldAsString(JSONFormattedAccessLogFields.MESSAGE_TYPE.getFieldName());
if (messageTypeStr == null) {
final String messageStr = messageObject.toSingleLineString();
throw new LogException(messageStr, ERR_JSON_ACCESS_LOG_READER_MISSING_MESSAGE_TYPE.get(messageStr, JSONFormattedAccessLogFields.MESSAGE_TYPE.getFieldName()));
}
final AccessLogMessageType messageType = AccessLogMessageType.forName(messageTypeStr);
if (messageType == null) {
final String messageStr = messageObject.toSingleLineString();
throw new LogException(messageStr, ERR_JSON_ACCESS_LOG_READER_UNSUPPORTED_MESSAGE_TYPE.get(messageStr, messageTypeStr));
}
switch(messageType) {
case CONNECT:
return new JSONConnectAccessLogMessage(messageObject);
case DISCONNECT:
return new JSONDisconnectAccessLogMessage(messageObject);
case SECURITY_NEGOTIATION:
return new JSONSecurityNegotiationAccessLogMessage(messageObject);
case CLIENT_CERTIFICATE:
return new JSONClientCertificateAccessLogMessage(messageObject);
case ENTRY_REBALANCING_REQUEST:
return new JSONEntryRebalancingRequestAccessLogMessage(messageObject);
case ENTRY_REBALANCING_RESULT:
return new JSONEntryRebalancingResultAccessLogMessage(messageObject);
case ENTRY:
return new JSONSearchEntryAccessLogMessage(messageObject);
case REFERENCE:
return new JSONSearchReferenceAccessLogMessage(messageObject);
case INTERMEDIATE_RESPONSE:
return new JSONIntermediateResponseAccessLogMessage(messageObject);
case REQUEST:
return createRequestMessage(messageObject);
case RESULT:
return createResultMessage(messageObject);
case FORWARD:
return createForwardMessage(messageObject);
case FORWARD_FAILED:
return createForwardFailedMessage(messageObject);
case ASSURANCE_COMPLETE:
return createAssuranceCompleteMessage(messageObject);
default:
final String messageStr = messageObject.toSingleLineString();
throw new LogException(messageStr, ERR_JSON_ACCESS_LOG_READER_UNSUPPORTED_MESSAGE_TYPE.get(messageStr, messageTypeStr));
}
}
Aggregations