use of com.unboundid.util.json.JSONObject 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.JSONObject 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.JSONObject 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.JSONObject in project ldapsdk by pingidentity.
the class OIDRegistry method getDefault.
/**
* Retrieves the default instance of this OID registry.
*
* @return The default instance of this OID registry.
*/
@NotNull()
public static OIDRegistry getDefault() {
OIDRegistry oidRegistry = DEFAULT_INSTANCE.get();
if (oidRegistry == null) {
synchronized (DEFAULT_INSTANCE) {
oidRegistry = DEFAULT_INSTANCE.get();
if (oidRegistry == null) {
final Map<OID, OIDRegistryItem> items = new TreeMap<>();
try (InputStream inputStream = OIDRegistry.class.getClassLoader().getResourceAsStream(OID_REGISTRY_JSON_RESOURCE_NAME);
JSONObjectReader jsonObjectReader = new JSONObjectReader(inputStream)) {
while (true) {
final JSONObject o = jsonObjectReader.readObject();
if (o == null) {
break;
}
try {
final OIDRegistryItem item = new OIDRegistryItem(o);
items.put(new OID(item.getOID()), item);
} catch (final Exception e) {
Debug.debugException(e);
}
}
} catch (final Exception e) {
Debug.debugException(e);
}
oidRegistry = new OIDRegistry(Collections.unmodifiableMap(items));
DEFAULT_INSTANCE.set(oidRegistry);
}
}
}
return oidRegistry;
}
use of com.unboundid.util.json.JSONObject in project ldapsdk by pingidentity.
the class OAUTHBEARERBindResultTestCase method testFailureResultWithCredentials.
/**
* Tests the behavior for a failure result that includes server SASL
* credentials that has all elements.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFailureResultWithCredentials() throws Exception {
final String[] initialReferralURLs = { "ldap://ds1.example.com:389/o=initial" };
final Control[] initialControls = { new Control("1.2.3.4") };
final JSONObject initialFailureDetails = new JSONObject(new JSONField("status", "invalid_token"), new JSONField("scope", "scope1 scope2 scope3"), new JSONField("openid-configuration", "https://openid.example.com/config"), new JSONField("some-other-field", "foo"));
final ASN1OctetString initialServerSASLCredentials = new ASN1OctetString(initialFailureDetails.toSingleLineString());
final String[] finalReferralURLs = { "ldap://ds1.example.com:389/o=final" };
final Control[] finalControls = { new Control("1.2.3.5") };
final BindResult initialBindResult = new BindResult(3, ResultCode.SASL_BIND_IN_PROGRESS, "initial diagnostic message", "o=initial matched DN", initialReferralURLs, initialControls, initialServerSASLCredentials);
final BindResult finalBindResult = new BindResult(4, ResultCode.INVALID_CREDENTIALS, "final diagnostic message", "o=final matched DN", finalReferralURLs, finalControls, null);
final OAUTHBEARERBindResult bindResult = new OAUTHBEARERBindResult(initialBindResult, finalBindResult);
assertEquals(bindResult.getMessageID(), 4);
assertNotNull(bindResult.getResultCode());
assertEquals(bindResult.getResultCode(), ResultCode.INVALID_CREDENTIALS);
assertNotNull(bindResult.getDiagnosticMessage());
assertEquals(bindResult.getDiagnosticMessage(), "final diagnostic message");
assertNotNull(bindResult.getMatchedDN());
assertDNsEqual(bindResult.getMatchedDN(), "o=final matched DN");
assertNotNull(bindResult.getReferralURLs());
assertEquals(bindResult.getReferralURLs().length, 1);
assertEquals(bindResult.getReferralURLs()[0], finalReferralURLs[0]);
assertNotNull(bindResult.getResponseControls());
assertEquals(bindResult.getResponseControls().length, 1);
assertEquals(bindResult.getResponseControls()[0], finalControls[0]);
assertNotNull(bindResult.getServerSASLCredentials());
assertTrue(bindResult.getServerSASLCredentials().equalsIgnoreType(initialServerSASLCredentials));
assertNotNull(bindResult.getInitialBindResult());
assertEquals(bindResult.getInitialBindResult(), initialBindResult);
assertNotNull(bindResult.getFinalBindResult());
assertEquals(bindResult.getFinalBindResult(), finalBindResult);
assertNotNull(bindResult.getFailureDetailsObject());
assertEquals(bindResult.getFailureDetailsObject(), initialFailureDetails);
assertNotNull(bindResult.getAuthorizationErrorCode());
assertEquals(bindResult.getAuthorizationErrorCode(), "invalid_token");
assertNotNull(bindResult.getScopes());
assertFalse(bindResult.getScopes().isEmpty());
assertEquals(bindResult.getScopes(), StaticUtils.setOf("scope1", "scope2", "scope3"));
assertNotNull(bindResult.getOpenIDConfigurationURL());
assertEquals(bindResult.getOpenIDConfigurationURL(), "https://openid.example.com/config");
assertNotNull(bindResult.toString());
}
Aggregations