Search in sources :

Example 11 with JsonException

use of org.forgerock.json.JsonException in project OpenAM by OpenRock.

the class PublishServiceConsumerImpl method parseResponse.

/*
    The response is created in SoapSTSPublishServiceRequestHandler#handleQuery.
     */
private Set<SoapSTSInstanceConfig> parseResponse(String response) throws STSPublishException {
    Set<SoapSTSInstanceConfig> instanceConfigs = new HashSet<>();
    JsonValue json;
    try {
        json = JsonValueBuilder.toJsonValue(response);
    } catch (JsonException e) {
        throw new STSPublishException(ResourceException.INTERNAL_ERROR, e.getMessage(), e);
    }
    JsonValue queryResult = json.get(RESULT);
    if (queryResult.isCollection()) {
        int size = queryResult.asCollection().size();
        for (int ndx = 0; ndx < size; ndx++) {
            final SoapSTSInstanceConfig soapSTSInstanceConfig = SoapSTSInstanceConfig.fromJson(queryResult.get(ndx));
            /*
                check for duplicates: duplicates cannot really be present because the combination of realm and deployment
                uri constitutes the identity of the soap-sts instance, and duplicate entries will result in LDAP errors
                when the instance is persisted in the SMS, but paranoia pays...
                 */
            if (!instanceConfigs.add(soapSTSInstanceConfig)) {
                logger.error("The set of published soap-sts instances contains a duplicate!! The duplicate instance: " + queryResult.get(ndx));
            }
        }
        return instanceConfigs;
    } else {
        throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Unexpected state: the query result is not " + "a collection. The query result: " + queryResult.toString());
    }
}
Also used : JsonException(org.forgerock.json.JsonException) SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) JsonValue(org.forgerock.json.JsonValue) STSPublishException(org.forgerock.openam.sts.STSPublishException) HashSet(java.util.HashSet)

Example 12 with JsonException

use of org.forgerock.json.JsonException in project OpenAM by OpenRock.

the class RestAuthHiddenValueCallbackHandler method convertFromJson.

/**
     * {@inheritDoc}
     */
public HiddenValueCallback convertFromJson(HiddenValueCallback callback, JsonValue jsonCallback) throws RestAuthException {
    validateCallbackType(CALLBACK_NAME, jsonCallback);
    JsonValue input = jsonCallback.get("input");
    if (input.size() != 1) {
        throw new JsonException("JSON Callback does not include an input field");
    }
    JsonValue inputField = input.get(0);
    String value = inputField.get("value").asString();
    callback.setValue(value);
    return callback;
}
Also used : JsonException(org.forgerock.json.JsonException) JsonValue(org.forgerock.json.JsonValue)

Example 13 with JsonException

use of org.forgerock.json.JsonException in project OpenAM by OpenRock.

the class RestAuthChoiceCallbackHandler method convertFromJson.

/**
     * {@inheritDoc}
     */
public ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback) throws RestAuthException {
    validateCallbackType(CALLBACK_NAME, jsonCallback);
    JsonValue input = jsonCallback.get("input");
    if (input.size() != 1) {
        throw new JsonException("JSON Callback does not include a input field");
    }
    JsonValue inputField = input.get(0);
    int selectedIndex = toInteger(inputField.get("value"));
    callback.setSelectedIndex(selectedIndex);
    return callback;
}
Also used : JsonException(org.forgerock.json.JsonException) JsonValue(org.forgerock.json.JsonValue)

Example 14 with JsonException

use of org.forgerock.json.JsonException in project OpenAM by OpenRock.

the class RestAuthConfirmationCallbackHandler method convertFromJson.

/**
     * {@inheritDoc}
     */
public ConfirmationCallback convertFromJson(ConfirmationCallback callback, JsonValue jsonCallback) throws RestAuthException {
    validateCallbackType(CALLBACK_NAME, jsonCallback);
    JsonValue input = jsonCallback.get("input");
    if (input.size() != 1) {
        throw new JsonException("JSON Callback does not include a input field");
    }
    JsonValue inputFieldValue = input.get(0).get("value").required();
    int value;
    if (inputFieldValue.isString()) {
        value = Integer.parseInt(inputFieldValue.asString());
    } else {
        value = inputFieldValue.asInteger();
    }
    callback.setSelectedIndex(value);
    return callback;
}
Also used : JsonException(org.forgerock.json.JsonException) JsonValue(org.forgerock.json.JsonValue)

Example 15 with JsonException

use of org.forgerock.json.JsonException in project OpenAM by OpenRock.

the class RestAuthPasswordCallbackHandler method convertFromJson.

/**
     * {@inheritDoc}
     */
public PasswordCallback convertFromJson(PasswordCallback callback, JsonValue jsonCallback) throws RestAuthException {
    validateCallbackType(CALLBACK_NAME, jsonCallback);
    JsonValue input = jsonCallback.get("input");
    if (input.size() != 1) {
        throw new JsonException("JSON Callback does not include a input field");
    }
    JsonValue inputField = input.get(0);
    String value = inputField.get("value").asString();
    callback.setPassword(value.toCharArray());
    return callback;
}
Also used : JsonException(org.forgerock.json.JsonException) JsonValue(org.forgerock.json.JsonValue)

Aggregations

JsonException (org.forgerock.json.JsonException)15 JsonValue (org.forgerock.json.JsonValue)13 ArrayList (java.util.ArrayList)3 SMSException (com.sun.identity.sm.SMSException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 TokenValidationException (org.forgerock.openam.sts.TokenValidationException)2 NodeList (org.w3c.dom.NodeList)2 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)1 L10NMessageImpl (com.sun.identity.shared.locale.L10NMessageImpl)1 ValidationException (com.sun.identity.shared.validation.ValidationException)1 AttributeSchema (com.sun.identity.sm.AttributeSchema)1 InvalidAttributeValueException (com.sun.identity.sm.InvalidAttributeValueException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 SignatureException (java.security.SignatureException)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 Map (java.util.Map)1