use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class EqualsAnyJSONObjectFilter method decodeFilter.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
protected EqualsAnyJSONObjectFilter decodeFilter(@NotNull final JSONObject filterObject) throws JSONException {
final List<String> fieldPath = getStrings(filterObject, FIELD_FIELD_PATH, false, null);
final boolean isCaseSensitive = getBoolean(filterObject, FIELD_CASE_SENSITIVE, false);
final JSONValue arrayValue = filterObject.getField(FIELD_VALUES);
if (arrayValue instanceof JSONArray) {
return new EqualsAnyJSONObjectFilter(fieldPath, ((JSONArray) arrayValue).getValues(), isCaseSensitive);
} else {
throw new JSONException(ERR_OBJECT_FILTER_VALUE_NOT_ARRAY.get(String.valueOf(filterObject), FILTER_TYPE, FIELD_VALUES));
}
}
use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class EqualsAnyJSONObjectFilter method toJSONObject.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public JSONObject toJSONObject() {
final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(4));
fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
if (field.size() == 1) {
fields.put(FIELD_FIELD_PATH, new JSONString(field.get(0)));
} else {
final ArrayList<JSONValue> fieldNameValues = new ArrayList<>(field.size());
for (final String s : field) {
fieldNameValues.add(new JSONString(s));
}
fields.put(FIELD_FIELD_PATH, new JSONArray(fieldNameValues));
}
fields.put(FIELD_VALUES, new JSONArray(values));
if (caseSensitive) {
fields.put(FIELD_CASE_SENSITIVE, JSONBoolean.TRUE);
}
return new JSONObject(fields);
}
use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class SubstringJSONObjectFilter method toJSONObject.
/**
* {@inheritDoc}
*/
@Override()
@NotNull()
public JSONObject toJSONObject() {
final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(6));
fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
if (field.size() == 1) {
fields.put(FIELD_FIELD_PATH, new JSONString(field.get(0)));
} else {
final ArrayList<JSONValue> fieldNameValues = new ArrayList<>(field.size());
for (final String s : field) {
fieldNameValues.add(new JSONString(s));
}
fields.put(FIELD_FIELD_PATH, new JSONArray(fieldNameValues));
}
if (startsWith != null) {
fields.put(FIELD_STARTS_WITH, new JSONString(startsWith));
}
if (!contains.isEmpty()) {
if (contains.size() == 1) {
fields.put(FIELD_CONTAINS, new JSONString(contains.get(0)));
} else {
final ArrayList<JSONValue> containsValues = new ArrayList<>(contains.size());
for (final String s : contains) {
containsValues.add(new JSONString(s));
}
fields.put(FIELD_CONTAINS, new JSONArray(containsValues));
}
}
if (endsWith != null) {
fields.put(FIELD_ENDS_WITH, new JSONString(endsWith));
}
if (caseSensitive) {
fields.put(FIELD_CASE_SENSITIVE, JSONBoolean.TRUE);
}
return new JSONObject(fields);
}
use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class JSONLogFieldSyntax method tokenizeValue.
/**
* Retrieves a tokenized representation of the provided JSON value.
*
* @param value The value to be tokenized.
* @param pepper A pepper used to provide brute-force protection for the
* resulting token. The pepper value should be kept secret so
* that it is not available to unauthorized users who might be
* able to view log information, although the same pepper
* value should be consistently provided when tokenizing
* values so that the same value will consistently yield the
* same token. It must not be {@code null} and should not be
* empty.
*
* @return A tokenized representation of the provided JSON value.
*/
@NotNull()
private JSONValue tokenizeValue(@NotNull final JSONValue value, @NotNull final byte[] pepper) {
if (value instanceof JSONObject) {
final Map<String, JSONValue> originalFields = ((JSONObject) value).getFields();
final Map<String, JSONValue> tokenizedFields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(originalFields.size()));
for (final Map.Entry<String, JSONValue> e : originalFields.entrySet()) {
final String fieldName = e.getKey();
final JSONValue fieldValue = e.getValue();
if (shouldRedactOrTokenize(fieldName)) {
final String tokenizedValue = tokenize(fieldValue.toNormalizedString(), pepper);
tokenizedFields.put(fieldName, new JSONString(tokenizedValue));
} else {
tokenizedFields.put(fieldName, tokenizeValue(fieldValue, pepper));
}
}
return new JSONObject(tokenizedFields);
} else if (value instanceof JSONArray) {
final List<JSONValue> originalValues = ((JSONArray) value).getValues();
final List<JSONValue> tokenizedValues = new ArrayList<>(originalValues.size());
for (final JSONValue v : originalValues) {
tokenizedValues.add(tokenizeValue(v, pepper));
}
return new JSONArray(tokenizedValues);
} else {
return sanitize(value);
}
}
use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class JSONLogMessage method valueToStrings.
/**
* Retrieves a list of the string representations of the values represented by
* the provided JSON value.
*
* @param value The JSON value for which to obtain the string
* representations. It must not be {@code null}.
*
* @return A list of the string representations of the values represented by
* the provided JSON value.
*/
@NotNull()
static List<String> valueToStrings(@NotNull final JSONValue value) {
if (value instanceof JSONArray) {
final JSONArray a = (JSONArray) value;
final List<JSONValue> valueList = a.getValues();
final List<String> valueStrings = new ArrayList<>(valueList.size());
for (final JSONValue v : valueList) {
if (v instanceof JSONString) {
valueStrings.add(((JSONString) v).stringValue());
} else {
valueStrings.add(v.toSingleLineString());
}
}
return Collections.unmodifiableList(valueStrings);
} else if (value instanceof JSONString) {
return Collections.singletonList(((JSONString) value).stringValue());
} else {
return Collections.singletonList(value.toSingleLineString());
}
}
Aggregations