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);
}
}
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);
}
}
Aggregations