Search in sources :

Example 1 with InvalidAttributeValueException

use of com.sun.identity.sm.InvalidAttributeValueException in project OpenAM by OpenRock.

the class SmsJsonConverter method fromJson.

/**
     * Will validate the Json representation of the service configuration against the serviceSchema for a realm,
     * and return a corresponding Map representation.
     *
     * @param jsonValue The request body.
     * @param realm The realm, or null if global.
     * @return Map representation of jsonValue
     */
public Map<String, Set<String>> fromJson(String realm, JsonValue jsonValue) throws JsonException, BadRequestException {
    if (!initialised) {
        init();
    }
    Map<String, Set<String>> result = new HashMap<>();
    if (jsonValue == null || jsonValue.isNull()) {
        return result;
    }
    Map<String, Object> translatedAttributeValuePairs = getTranslatedAttributeValuePairs(jsonValue.asMap());
    for (String attributeName : translatedAttributeValuePairs.keySet()) {
        // Ignore _id field used to name resource when creating
        if (ResourceResponse.FIELD_CONTENT_ID.equals(attributeName)) {
            continue;
        }
        if (shouldNotBeUpdated(attributeName)) {
            throw new BadRequestException("Invalid attribute, '" + attributeName + "', specified");
        }
        if (shouldBeIgnored(attributeName)) {
            continue;
        }
        final Object attributeValue = translatedAttributeValuePairs.get(attributeName);
        Set<String> value = new HashSet<>();
        if (attributeValue instanceof HashMap) {
            final HashMap<String, Object> attributeMap = (HashMap<String, Object>) attributeValue;
            for (String name : attributeMap.keySet()) {
                value.add("[" + name + "]=" + convertJsonToString(attributeName, attributeMap.get(name)));
            }
        } else if (attributeValue instanceof List) {
            List<Object> attributeArray = (ArrayList<Object>) attributeValue;
            for (Object val : attributeArray) {
                value.add(convertJsonToString(attributeName, val));
            }
        } else {
            value.add(convertJsonToString(attributeName, attributeValue));
        }
        result.put(attributeName, value);
    }
    try {
        if (result.isEmpty() || (realm == null && schema.validateAttributes(result)) || (realm != null && schema.validateAttributes(result, realm))) {
            return result;
        } else {
            throw new JsonException("Invalid attributes");
        }
    } catch (InvalidAttributeValueException e) {
        throw new BadRequestException(e.getLocalizedMessage(), e);
    } catch (SMSException e) {
        throw new JsonException("Unable to validate attributes", e);
    }
}
Also used : JsonException(org.forgerock.json.JsonException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) InvalidAttributeValueException(com.sun.identity.sm.InvalidAttributeValueException) BadRequestException(org.forgerock.json.resource.BadRequestException) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with InvalidAttributeValueException

use of com.sun.identity.sm.InvalidAttributeValueException in project OpenAM by OpenRock.

the class AMOrgTemplateImpl method store.

/**
     * Stores the change to directory server.
     * 
     * @throws AMException
     *             if there is an internal problem with AM Store.
     * @throws SSOException
     *             if the sign-on is no longer valid.
     */
public void store() throws AMException, SSOException {
    Map attributes = modAttributes;
    modAttributes = new HashMap();
    try {
        serviceConfig.setAttributes(attributes);
    } catch (ServiceNotFoundException ex) {
        Object[] args = { serviceName };
        throw new AMException(AMSDKBundle.getString("481", args), "481", args);
    } catch (InvalidAttributeValueException ex) {
        Object[] args = ex.getMessageArgs();
        debug.error("Store exception from SMS: " + ex, ex);
        throw new AMException(AMSDKBundle.getString("975", args), "975", args);
    } catch (SMSException ex) {
        Object[] args = { serviceName };
        debug.error("Store exception from SMS: " + ex, ex);
        throw new AMException(AMSDKBundle.getString("486", args), "486", args);
    }
}
Also used : HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) ServiceNotFoundException(com.sun.identity.sm.ServiceNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) InvalidAttributeValueException(com.sun.identity.sm.InvalidAttributeValueException)

Aggregations

InvalidAttributeValueException (com.sun.identity.sm.InvalidAttributeValueException)2 SMSException (com.sun.identity.sm.SMSException)2 HashMap (java.util.HashMap)2 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 JsonException (org.forgerock.json.JsonException)1 BadRequestException (org.forgerock.json.resource.BadRequestException)1 NodeList (org.w3c.dom.NodeList)1