use of com.unboundid.util.json.JSONBoolean in project ldapsdk by pingidentity.
the class PasswordPolicyStateJSONTestCase method encodeRequirement.
/**
* Encodes the provided password quality requirement to a JSON object suitable
* for inclusion in the password policy state properties object.
*
* @param requirement The requirement to be encoded.
* @param appliesToAdd Indicates whether the requirement applies to
* add operations.
* @param appliesToSelfChange Indicates whether the requirement applies to
* self password changes.
* @param appliesToAdminReset Indicates whether the requirement applies to
* administrative password resets.
* @param appliesToBind Indicates whether the requirement applies to
* bind operations.
*
* @return The encoded JSON object.
*/
private static JSONObject encodeRequirement(final PasswordQualityRequirement requirement, final boolean appliesToAdd, final boolean appliesToSelfChange, final boolean appliesToAdminReset, final boolean appliesToBind) {
final Map<String, JSONValue> objectFields = new LinkedHashMap<>();
objectFields.put("description", new JSONString(requirement.getDescription()));
final String validationType = requirement.getClientSideValidationType();
if (validationType != null) {
objectFields.put("client-side-validation-type", new JSONString(validationType));
final List<JSONValue> propertyObjects = new ArrayList<>();
for (Map.Entry<String, String> e : requirement.getClientSideValidationProperties().entrySet()) {
propertyObjects.add(new JSONObject(new JSONField("name", e.getKey()), new JSONField("value", e.getValue())));
}
objectFields.put("client-side-validation-properties", new JSONArray(propertyObjects));
}
objectFields.put("applies-to-add", new JSONBoolean(appliesToAdd));
objectFields.put("applies-to-self-change", new JSONBoolean(appliesToSelfChange));
objectFields.put("applies-to-administrative-reset", new JSONBoolean(appliesToAdminReset));
objectFields.put("applies-to-bind", new JSONBoolean(appliesToBind));
return new JSONObject(objectFields);
}
use of com.unboundid.util.json.JSONBoolean in project ldapsdk by pingidentity.
the class ScrambleAttributeTransformation method scrambleJSONValue.
/**
* Scrambles the provided JSON value.
*
* @param v The JSON value to be scrambled.
* @param scrambleAllFields Indicates whether all fields of any JSON object
* should be scrambled.
*
* @return The scrambled JSON value.
*/
@NotNull()
private JSONValue scrambleJSONValue(@NotNull final JSONValue v, final boolean scrambleAllFields) {
if (v instanceof JSONArray) {
final JSONArray a = (JSONArray) v;
final List<JSONValue> originalValues = a.getValues();
final ArrayList<JSONValue> scrambledValues = new ArrayList<>(originalValues.size());
for (final JSONValue arrayValue : originalValues) {
scrambledValues.add(scrambleJSONValue(arrayValue, true));
}
return new JSONArray(scrambledValues);
} else if (v instanceof JSONBoolean) {
return new JSONBoolean(ThreadLocalRandom.get().nextBoolean());
} else if (v instanceof JSONNumber) {
try {
return new JSONNumber(scrambleNumericValue(v.toString()));
} catch (final Exception e) {
// This should never happen.
Debug.debugException(e);
return v;
}
} else if (v instanceof JSONObject) {
final JSONObject o = (JSONObject) v;
final Map<String, JSONValue> originalFields = o.getFields();
final LinkedHashMap<String, JSONValue> scrambledFields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(originalFields.size()));
for (final Map.Entry<String, JSONValue> e : originalFields.entrySet()) {
final JSONValue scrambledValue;
final String fieldName = e.getKey();
final JSONValue originalValue = e.getValue();
if (scrambleAllFields || jsonFields.contains(StaticUtils.toLowerCase(fieldName))) {
scrambledValue = scrambleJSONValue(originalValue, scrambleAllFields);
} else if (originalValue instanceof JSONArray) {
scrambledValue = scrambleObjectsInArray((JSONArray) originalValue);
} else if (originalValue instanceof JSONObject) {
scrambledValue = scrambleJSONValue(originalValue, false);
} else {
scrambledValue = originalValue;
}
scrambledFields.put(fieldName, scrambledValue);
}
return new JSONObject(scrambledFields);
} else if (v instanceof JSONString) {
final JSONString s = (JSONString) v;
return new JSONString(scrambleString(s.stringValue()));
} else {
// those.
return v;
}
}
Aggregations