Search in sources :

Example 1 with JSONValue

use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.

the class JSONLogFieldSyntax method valueStringIsCompletelyTokenized.

/**
 * {@inheritDoc}
 */
@Override()
public boolean valueStringIsCompletelyTokenized(@NotNull final String valueString) {
    if (super.valueStringIsCompletelyTokenized(valueString)) {
        return true;
    }
    try {
        final JSONObject jsonObject = new JSONObject(valueString);
        final Map<String, JSONValue> fields = jsonObject.getFields();
        return ((fields.size() == 1) && fields.containsKey("tokenized"));
    } catch (final Exception e) {
        Debug.debugException(e);
        return false;
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONString(com.unboundid.util.json.JSONString)

Example 2 with JSONValue

use of com.unboundid.util.json.JSONValue 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;
    }
}
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 3 with JSONValue

use of com.unboundid.util.json.JSONValue 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);
    }
}
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 4 with JSONValue

use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.

the class PasswordPolicyStateJSON method getPasswordQualityRequirements.

/**
 * Retrieves a list of the password quality requirements that are contained in
 * the JSON object in which the indicated Boolean field is present and set to
 * {@code true}.
 *
 * @param  booleanFieldName  The name of the field that is expected to be
 *                           present with a Boolean value of true for each
 *                           requirement to be included in the list that is
 *                           returned.
 *
 * @return  The appropriate list of password quality requirements, or an empty
 *          list if no requirements will be imposed.
 */
@NotNull()
private List<PasswordQualityRequirement> getPasswordQualityRequirements(@NotNull final String booleanFieldName) {
    final List<JSONValue> requirementObjectLst = passwordPolicyStateObject.getFieldAsArray(PASSWORD_QUALITY_REQUIREMENTS.getFieldName());
    if ((requirementObjectLst == null) || requirementObjectLst.isEmpty()) {
        return Collections.emptyList();
    }
    final List<PasswordQualityRequirement> requirements = new ArrayList<>(requirementObjectLst.size());
    for (final JSONValue requirementObjectValue : requirementObjectLst) {
        if (!(requirementObjectValue instanceof JSONObject)) {
            continue;
        }
        final JSONObject requirementObject = (JSONObject) requirementObjectValue;
        final Boolean include = requirementObject.getFieldAsBoolean(booleanFieldName);
        if ((include == null) || (!include.booleanValue())) {
            continue;
        }
        final String description = requirementObject.getFieldAsString(REQUIREMENT_FIELD_DESCRIPTION);
        if (description == null) {
            continue;
        }
        final String clientSideValidationType = requirementObject.getFieldAsString(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_TYPE);
        final Map<String, String> clientSideValidationProperties = new LinkedHashMap<>();
        final List<JSONValue> propertyValues = requirementObject.getFieldAsArray(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_PROPERTIES);
        if (propertyValues != null) {
            for (final JSONValue propertyValue : propertyValues) {
                if (!(propertyValue instanceof JSONObject)) {
                    continue;
                }
                final JSONObject propertyObject = (JSONObject) propertyValue;
                final String name = propertyObject.getFieldAsString(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_PROPERTY_NAME);
                final String value = propertyObject.getFieldAsString(REQUIREMENT_FIELD_CLIENT_SIDE_VALIDATION_PROPERTY_VALUE);
                if ((name != null) && (value != null)) {
                    clientSideValidationProperties.put(name, value);
                }
            }
        }
        requirements.add(new PasswordQualityRequirement(description, clientSideValidationType, clientSideValidationProperties));
    }
    return requirements;
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) PasswordQualityRequirement(com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Example 5 with JSONValue

use of com.unboundid.util.json.JSONValue 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);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) ArrayList(java.util.ArrayList) JSONString(com.unboundid.util.json.JSONString) LDAPException(com.unboundid.ldap.sdk.LDAPException) 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