use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class EqualsJSONObjectFilter 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_VALUE, value);
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 RegularExpressionJSONObjectFilter 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_REGULAR_EXPRESSION, new JSONString(regularExpression.toString()));
if (matchAllElements) {
fields.put(FIELD_MATCH_ALL_ELEMENTS, JSONBoolean.TRUE);
}
return new JSONObject(fields);
}
use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class ScrambleAttributeTransformation method scrambleObjectsInArray.
/**
* Creates a new JSON array that will have all the same elements as the
* provided array except that any values in the array that are JSON objects
* (including objects contained in nested arrays) will have any appropriate
* scrambling performed.
*
* @param a The JSON array for which to scramble any values.
*
* @return The array with any appropriate scrambling performed.
*/
@NotNull()
private JSONArray scrambleObjectsInArray(@NotNull final JSONArray a) {
final List<JSONValue> originalValues = a.getValues();
final ArrayList<JSONValue> scrambledValues = new ArrayList<>(originalValues.size());
for (final JSONValue arrayValue : originalValues) {
if (arrayValue instanceof JSONArray) {
scrambledValues.add(scrambleObjectsInArray((JSONArray) arrayValue));
} else if (arrayValue instanceof JSONObject) {
scrambledValues.add(scrambleJSONValue(arrayValue, false));
} else {
scrambledValues.add(arrayValue);
}
}
return new JSONArray(scrambledValues);
}
use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class ModifiablePasswordPolicyStateJSONTestCase method createState.
/**
* Creates a password policy state JSON object with the provided fields.
*
* @param fields The fields to include in the JSON object.
*
* @return The password policy state JSON object that was created.
*
* @throws Exception If an unexpected problem occurs.
*/
private ModifiablePasswordPolicyStateJSON createState(final Map<ModifiablePasswordPolicyStateJSONField, ?> fields) throws Exception {
final Map<String, JSONValue> jsonFields = new LinkedHashMap<>();
for (final ModifiablePasswordPolicyStateJSONField field : fields.keySet()) {
final String name = field.getFieldName();
final Object value = fields.get(field);
if (value instanceof Boolean) {
final Boolean b = (Boolean) value;
jsonFields.put(name, new JSONBoolean(b));
} else if (value instanceof String) {
final String s = (String) value;
jsonFields.put(name, new JSONString(s));
} else if (value instanceof Date) {
final Date d = (Date) value;
jsonFields.put(name, new JSONString(StaticUtils.encodeRFC3339Time(d)));
} else if (value instanceof JSONValue) {
jsonFields.put(name, (JSONValue) value);
} else {
fail("Unexpected field value " + value + " of type " + value.getClass().getName());
}
}
final JSONObject o = new JSONObject(jsonFields);
final Entry entry = new Entry("dn: uid=test.user,ou=People,dc=example,dc=com", "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "uid: test.user", "givenName: Test", "sn: User", "cn: Test User");
entry.addAttribute("ds-pwp-modifiable-state-json", o.toSingleLineString());
final ModifiablePasswordPolicyStateJSON state = ModifiablePasswordPolicyStateJSON.get(entry);
assertNotNull(state);
assertNotNull(state.getModifiablePasswordPolicyStateJSONObject());
assertFalse(state.getModifiablePasswordPolicyStateJSONObject().getFields().isEmpty());
assertEquals(state.getModifiablePasswordPolicyStateJSONObject().getFields().size(), jsonFields.size());
assertNotNull(state.toString());
assertFalse(state.toString().isEmpty());
return state;
}
use of com.unboundid.util.json.JSONValue in project ldapsdk by pingidentity.
the class JSONAccessLogReaderTestCase method testReadObjectWithInvalidOperationType.
/**
* Tests the behavior when trying to read a file containing a JSON object
* for an operation message that has an invalid operation type.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testReadObjectWithInvalidOperationType() throws Exception {
final JSONObject minimalMessageObject = createMinimalMessageObject(REQUEST, ABANDON);
final Map<String, JSONValue> fieldsWithInvalidOperationType = new LinkedHashMap<>(minimalMessageObject.getFields());
assertNotNull(fieldsWithInvalidOperationType.put(OPERATION_TYPE.getFieldName(), new JSONString("invalid")));
final JSONObject objectWithoutMessageType = new JSONObject(fieldsWithInvalidOperationType);
final File logFile = createTempFile(objectWithoutMessageType.toSingleLineString());
try (JSONAccessLogReader reader = new JSONAccessLogReader(logFile)) {
reader.readMessage();
fail("Expected an exception for a file that contains a JSON object " + "with an invalid operation type");
} catch (final LogException e) {
// This was expected.
}
}
Aggregations