use of com.unboundid.util.json.JSONString in project ldapsdk by pingidentity.
the class JSONLogFieldSyntax method sanitize.
/**
* Sanitizes the provided JSON value.
*
* @param value The value to be sanitized. It must not be {@code null}.
*
* @return A sanitized representation of the provided JSON value.
*/
@NotNull()
private JSONValue sanitize(@NotNull final JSONValue value) {
if (value instanceof JSONObject) {
final Map<String, JSONValue> originalFields = ((JSONObject) value).getFields();
final Map<String, JSONValue> sanitizedFields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(originalFields.size()));
for (final Map.Entry<String, JSONValue> e : originalFields.entrySet()) {
sanitizedFields.put(e.getKey(), sanitize(e.getValue()));
}
return new JSONObject(sanitizedFields);
} else if (value instanceof JSONArray) {
final List<JSONValue> originalValues = ((JSONArray) value).getValues();
final List<JSONValue> sanitizedValues = new ArrayList<>(originalValues.size());
for (final JSONValue v : originalValues) {
sanitizedValues.add(sanitize(v));
}
return new JSONArray(sanitizedValues);
} else if (value instanceof JSONString) {
final String stringValue = ((JSONString) value).stringValue();
return new JSONString(sanitize(stringValue));
} else {
return value;
}
}
use of com.unboundid.util.json.JSONString in project ldapsdk by pingidentity.
the class JSONLogFieldSyntax method redactValue.
/**
* Retrieves a redacted representation of the provided JSON value.
*
* @param value The value to be redacted.
*
* @return A redacted representation of the provided JSON value.
*/
@NotNull()
private JSONValue redactValue(@NotNull final JSONValue value) {
if (value instanceof JSONObject) {
final Map<String, JSONValue> originalFields = ((JSONObject) value).getFields();
final Map<String, JSONValue> redactedFields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(originalFields.size()));
for (final Map.Entry<String, JSONValue> e : originalFields.entrySet()) {
final String fieldName = e.getKey();
if (shouldRedactOrTokenize(fieldName)) {
redactedFields.put(fieldName, new JSONString(REDACTED_STRING));
} else {
redactedFields.put(fieldName, redactValue(e.getValue()));
}
}
return new JSONObject(redactedFields);
} else if (value instanceof JSONArray) {
final List<JSONValue> originalValues = ((JSONArray) value).getValues();
final List<JSONValue> redactedValues = new ArrayList<>(originalValues.size());
for (final JSONValue v : originalValues) {
redactedValues.add(redactValue(v));
}
return new JSONArray(redactedValues);
} else {
return sanitize(value);
}
}
use of com.unboundid.util.json.JSONString in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSON method getAvailableOTPDeliveryMechanisms.
/**
* Retrieves a list of the names of the OTP delivery mechanisms that the user
* can use to receive one-time passwords, password reset tokens, and
* single-use tokens.
*
* @return A list of the names of the OTP delivery mechanisms that the user
* can use, or an empty list if no OTP delivery mechanisms are
* available to the user or if this was not included in the password
* policy state JSON object.
*/
@NotNull()
public List<String> getAvailableOTPDeliveryMechanisms() {
final List<String> deliveryMechanismNames = new ArrayList<>();
final List<JSONValue> values = passwordPolicyStateObject.getFieldAsArray(AVAILABLE_OTP_DELIVERY_MECHANISMS.getFieldName());
if (values != null) {
for (final JSONValue v : values) {
try {
deliveryMechanismNames.add(((JSONString) v).stringValue());
} catch (final Exception e) {
Debug.debugException(e);
}
}
}
return Collections.unmodifiableList(deliveryMechanismNames);
}
use of com.unboundid.util.json.JSONString in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSON method getGraceLoginUseTimes.
/**
* Retrieves a list of the times that the user has used a grace login to
* authenticate.
*
* @return A list of the times that the user has used a grace login to
* authenticate, or an empty list if the user has not used any grace
* logins, or if this was not included in the password policy state
* JSON object (e.g., if grace logins are not configured in the
* password policy that governs the user).
*/
@NotNull()
public List<Date> getGraceLoginUseTimes() {
final List<Date> graceLoginTimes = new ArrayList<>();
final List<JSONValue> values = passwordPolicyStateObject.getFieldAsArray(GRACE_LOGIN_USE_TIMES.getFieldName());
if (values != null) {
for (final JSONValue v : values) {
try {
final String valueString = ((JSONString) v).stringValue();
graceLoginTimes.add(StaticUtils.decodeRFC3339Time(valueString));
} catch (final Exception e) {
Debug.debugException(e);
}
}
}
return Collections.unmodifiableList(graceLoginTimes);
}
use of com.unboundid.util.json.JSONString in project ldapsdk by pingidentity.
the class JSONLogsTestCase method createPopulatedMessageObject.
/**
* Creates a JSON object with an encoded representation of a log message that
* has values populated for most of the optional common fields.
*
* @param messageType The message type for the log message. This must not
* be {@code null}.
* @param operationType The operation type for the log message. This may be
* {@code null} if it is not an operation log message.
* @param fields The set of additional fields to include in the log
* message. This must not be {@code null} but may be
* empty.
*
* @return The log message that was created.
*/
@NotNull()
protected static JSONObject createPopulatedMessageObject(@NotNull final AccessLogMessageType messageType, @Nullable final AccessLogOperationType operationType, @NotNull final JSONField... fields) {
final Map<String, JSONValue> fieldMap = createMinimalFieldMap(messageType, operationType);
fieldMap.put(PRODUCT_NAME.getFieldName(), new JSONString(DEFAULT_PRODUCT_NAME));
fieldMap.put(INSTANCE_NAME.getFieldName(), new JSONString(DEFAULT_INSTANCE_NAME));
fieldMap.put(STARTUP_ID.getFieldName(), new JSONString(DEFAULT_STARTUP_ID));
fieldMap.put(THREAD_ID.getFieldName(), new JSONNumber(DEFAULT_THREAD_ID));
fieldMap.put(CONNECTION_ID.getFieldName(), new JSONNumber(DEFAULT_CONNECTION_ID));
if (operationType != null) {
fieldMap.put(OPERATION_ID.getFieldName(), new JSONNumber(DEFAULT_OPERATION_ID));
fieldMap.put(MESSAGE_ID.getFieldName(), new JSONNumber(DEFAULT_MESSAGE_ID));
fieldMap.put(TRIGGERED_BY_CONNECTION_ID.getFieldName(), new JSONNumber(DEFAULT_TRIGGERED_BY_CONNECTION_ID));
fieldMap.put(TRIGGERED_BY_OPERATION_ID.getFieldName(), new JSONNumber(DEFAULT_TRIGGERED_BY_OPERATION_ID));
fieldMap.put(ORIGIN.getFieldName(), new JSONString(DEFAULT_ORIGIN));
fieldMap.put(REQUESTER_IP_ADDRESS.getFieldName(), new JSONString(DEFAULT_REQUESTER_IP));
fieldMap.put(REQUESTER_DN.getFieldName(), new JSONString(DEFAULT_REQUESTER_DN));
fieldMap.put(REQUEST_CONTROL_OIDS.getFieldName(), createArray(DEFAULT_REQUEST_CONTROL_OIDS));
fieldMap.put(USING_ADMIN_SESSION_WORKER_THREAD.getFieldName(), new JSONBoolean(DEFAULT_USING_ADMIN_SESSION_WORKER_THREAD));
fieldMap.put(ADMINISTRATIVE_OPERATION.getFieldName(), new JSONString(DEFAULT_ADMIN_OP_MESSAGE));
fieldMap.put(INTERMEDIATE_CLIENT_REQUEST_CONTROL.getFieldName(), DEFAULT_INTERMEDIATE_CLIENT_REQUEST.getControlObject());
fieldMap.put(OPERATION_PURPOSE.getFieldName(), DEFAULT_OPERATION_PURPOSE_REQUEST.getControlObject());
if ((messageType == AccessLogMessageType.FORWARD) || (messageType == AccessLogMessageType.FORWARD_FAILED) || (messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE)) {
fieldMap.put(TARGET_HOST.getFieldName(), new JSONString(DEFAULT_FORWARD_TARGET_HOST));
fieldMap.put(TARGET_PORT.getFieldName(), new JSONNumber(DEFAULT_FORWARD_TARGET_PORT));
fieldMap.put(TARGET_PROTOCOL.getFieldName(), new JSONString(DEFAULT_FORWARD_TARGET_PROTOCOL));
}
if ((messageType == AccessLogMessageType.FORWARD_FAILED) || (messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE)) {
fieldMap.put(RESULT_CODE_VALUE.getFieldName(), new JSONNumber(DEFAULT_RESULT_CODE.intValue()));
fieldMap.put(RESULT_CODE_NAME.getFieldName(), new JSONString(DEFAULT_RESULT_CODE.getName()));
fieldMap.put(DIAGNOSTIC_MESSAGE.getFieldName(), new JSONString(DEFAULT_DIAGNOSTIC_MESSAGE));
}
if ((messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE) || (messageType == AccessLogMessageType.ENTRY) || (messageType == AccessLogMessageType.REFERENCE) || (messageType == AccessLogMessageType.INTERMEDIATE_RESPONSE)) {
fieldMap.put(RESPONSE_CONTROL_OIDS.getFieldName(), createArray(DEFAULT_RESPONSE_CONTROL_OIDS));
}
if ((messageType == AccessLogMessageType.RESULT) || (messageType == AccessLogMessageType.ASSURANCE_COMPLETE)) {
fieldMap.put(ADDITIONAL_INFO.getFieldName(), new JSONString(DEFAULT_ADDITIONAL_INFO_MESSAGE));
fieldMap.put(MATCHED_DN.getFieldName(), new JSONString(DEFAULT_MATCHED_DN));
fieldMap.put(REFERRAL_URLS.getFieldName(), createArray(DEFAULT_REFERRAL_URLS));
fieldMap.put(SERVERS_ACCESSED.getFieldName(), createArray(DEFAULT_SERVERS_ACCESSED));
fieldMap.put(UNCACHED_DATA_ACCESSED.getFieldName(), new JSONBoolean(DEFAULT_UNCACHED_DATA_ACCESSED));
fieldMap.put(WORK_QUEUE_WAIT_TIME_MILLIS.getFieldName(), new JSONNumber(DEFAULT_WORK_QUEUE_WAIT_TIME_MILLIS));
fieldMap.put(PROCESSING_TIME_MILLIS.getFieldName(), new JSONNumber(DEFAULT_PROCESSING_TIME_MILLIS));
fieldMap.put(INTERMEDIATE_RESPONSES_RETURNED.getFieldName(), new JSONNumber(DEFAULT_INTERMEDIATE_RESPONSES_RETURNED));
fieldMap.put(USED_PRIVILEGES.getFieldName(), createArray(DEFAULT_USED_PRIVILEGES));
fieldMap.put(PRE_AUTHORIZATION_USED_PRIVILEGES.getFieldName(), createArray(DEFAULT_PRE_AUTHZ_USED_PRIVILEGES));
fieldMap.put(MISSING_PRIVILEGES.getFieldName(), createArray(DEFAULT_MISSING_PRIVILEGES));
if (operationType != AccessLogOperationType.ABANDON) {
fieldMap.put(INTERMEDIATE_CLIENT_RESPONSE_CONTROL.getFieldName(), DEFAULT_INTERMEDIATE_CLIENT_RESPONSE.getControlObject());
}
if ((operationType == AccessLogOperationType.ADD) || (operationType == AccessLogOperationType.COMPARE) || (operationType == AccessLogOperationType.DELETE) || (operationType == AccessLogOperationType.MODIFY) || (operationType == AccessLogOperationType.MODDN) || (operationType == AccessLogOperationType.SEARCH)) {
fieldMap.put(AUTHORIZATION_DN.getFieldName(), new JSONString(DEFAULT_AUTHZ_DN));
}
if ((operationType == AccessLogOperationType.ADD) || (operationType == AccessLogOperationType.DELETE) || (operationType == AccessLogOperationType.MODIFY) || (operationType == AccessLogOperationType.MODDN)) {
fieldMap.put(REPLICATION_CHANGE_ID.getFieldName(), new JSONString(DEFAULT_REPLICATION_CHANGE_ID));
fieldMap.put(ASSURED_REPLICATION_REQUIREMENTS.getFieldName(), createAssuredReplicationRequirements());
}
if ((operationType == AccessLogOperationType.ADD) || (operationType == AccessLogOperationType.DELETE) || (operationType == AccessLogOperationType.MODIFY) || (operationType == AccessLogOperationType.MODDN) || (operationType == AccessLogOperationType.SEARCH)) {
fieldMap.put(INDEXES_WITH_KEYS_ACCESSED_NEAR_ENTRY_LIMIT.getFieldName(), createArray(DEFAULT_INDEXES_NEAR_ENTRY_LIMIT));
fieldMap.put(INDEXES_WITH_KEYS_ACCESSED_EXCEEDING_ENTRY_LIMIT.getFieldName(), createArray(DEFAULT_INDEXES_EXCEEDING_ENTRY_LIMIT));
}
}
if (messageType == AccessLogMessageType.ASSURANCE_COMPLETE) {
fieldMap.put(LOCAL_ASSURANCE_SATISFIED.getFieldName(), new JSONBoolean(DEFAULT_LOCAL_ASSURANCE_SATISFIED));
fieldMap.put(REMOTE_ASSURANCE_SATISFIED.getFieldName(), new JSONBoolean(DEFAULT_REMOTE_ASSURANCE_SATISFIED));
fieldMap.put(SERVER_ASSURANCE_RESULTS.getFieldName(), new JSONArray(DEFAULT_ASSURED_REPLICATION_SERVER_RESULTS.get(0).getServerResultObject(), DEFAULT_ASSURED_REPLICATION_SERVER_RESULTS.get(1).getServerResultObject()));
}
}
for (final JSONField field : fields) {
fieldMap.put(field.getName(), field.getValue());
}
return new JSONObject(fieldMap);
}
Aggregations