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;
}
}
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;
}
}
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);
}
}
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;
}
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);
}
Aggregations