Search in sources :

Example 46 with JSONValue

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));
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONArray(com.unboundid.util.json.JSONArray) JSONException(com.unboundid.util.json.JSONException) JSONString(com.unboundid.util.json.JSONString) NotNull(com.unboundid.util.NotNull)

Example 47 with JSONValue

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);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.unboundid.util.json.JSONArray) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Example 48 with JSONValue

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);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.unboundid.util.json.JSONArray) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Example 49 with JSONValue

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);
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Example 50 with JSONValue

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());
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONArray(com.unboundid.util.json.JSONArray) ArrayList(java.util.ArrayList) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) NotNull(com.unboundid.util.NotNull)

Aggregations

JSONValue (com.unboundid.util.json.JSONValue)50 JSONString (com.unboundid.util.json.JSONString)45 JSONObject (com.unboundid.util.json.JSONObject)40 NotNull (com.unboundid.util.NotNull)33 LinkedHashMap (java.util.LinkedHashMap)31 JSONArray (com.unboundid.util.json.JSONArray)27 ArrayList (java.util.ArrayList)27 Test (org.testng.annotations.Test)9 LogException (com.unboundid.ldap.sdk.unboundidds.logs.LogException)8 JSONBoolean (com.unboundid.util.json.JSONBoolean)6 Map (java.util.Map)6 JSONNumber (com.unboundid.util.json.JSONNumber)5 File (java.io.File)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 JSONException (com.unboundid.util.json.JSONException)4 JSONField (com.unboundid.util.json.JSONField)4 Date (java.util.Date)4 List (java.util.List)4 Entry (com.unboundid.ldap.sdk.Entry)3 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)2