use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class TrustedDevicesResource method convertValue.
protected ResourceResponse convertValue(JsonValue profile) throws ParseException {
final JsonValue lastSelectedDateJson = profile.get(LAST_SELECTED_DATE_KEY);
final Date lastSelectedDate;
final String formatted;
if (lastSelectedDateJson.isString()) {
synchronized (DATE_PARSER) {
lastSelectedDate = DATE_PARSER.parse(lastSelectedDateJson.asString());
}
} else {
lastSelectedDate = new Date(lastSelectedDateJson.asLong());
}
synchronized (DATE_FORMATTER) {
formatted = DATE_FORMATTER.format(lastSelectedDate);
}
profile.put(LAST_SELECTED_DATE_KEY, formatted);
return newResourceResponse(profile.get("name").asString(), profile.hashCode() + "", profile);
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class CoreTokenResource method deleteInstance.
/**
* Delete the instance referred to by its Resource path.
*
* @param serverContext Required context.
* @param tokenId The TokenID of the token to delete.
* @param deleteRequest Not used.
*/
public Promise<ResourceResponse, ResourceException> deleteInstance(Context serverContext, String tokenId, DeleteRequest deleteRequest) {
String principal = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
try {
store.deleteAsync(tokenId);
Map<String, String> result = new HashMap<String, String>();
result.put(TOKEN_ID, tokenId);
ResourceResponse resource = newResourceResponse(tokenId, String.valueOf(System.currentTimeMillis()), new JsonValue(result));
debug("DELETE by {0}: Deleted token resource with ID: {1}", principal, tokenId);
return newResultPromise(resource);
} catch (CoreTokenException e) {
error(e, "DELETE by {0}: Error deleting token resource with ID: {1}", principal, tokenId);
return generateException(e).asPromise();
}
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class CoreTokenResource method updateInstance.
/**
* Update a Token based on the Resource path.
*
* @param serverContext Required context.
* @param tokenId The tokenId to update. This must be the same TokenId as the serialised Token.
* @param updateRequest Contains the JSON serialised Token to update.
*/
public Promise<ResourceResponse, ResourceException> updateInstance(Context serverContext, String tokenId, UpdateRequest updateRequest) {
String principal = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
String value = updateRequest.getContent().toString();
Token newToken = serialisation.deserialise(value, Token.class);
try {
store.updateAsync(newToken);
ResourceResponse resource = newResourceResponse(newToken.getTokenId(), String.valueOf(System.currentTimeMillis()), new JsonValue("Token Updated"));
debug("UPDATE by {0}: Updated token resource with ID: {1}", principal, tokenId);
return newResultPromise(resource);
} catch (CoreTokenException e) {
error(e, "UPDATE by {0}: Error updating token resource with ID: {1}", principal, tokenId);
return generateException(e).asPromise();
}
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestAuthRedirectCallbackHandler method convertToJson.
/**
* Converts the {@code RedirectCallback} into a JSON representation.
*
* {@inheritDoc}
*/
public JsonValue convertToJson(RedirectCallback callback, int index) throws RestAuthException {
JsonValue callbacksJson = json(array(createOutputField("redirectUrl", callback.getRedirectUrl()), createOutputField("redirectMethod", callback.getMethod()), createOutputField("trackingCookie", callback.getTrackingCookie())));
JsonValue jsonValue = json(object(field("type", CALLBACK_NAME), field("output", callbacksJson.getObject())));
if (callback.getRedirectData() != null) {
callbacksJson.add(createOutputField("redirectData", callback.getRedirectData()));
}
return jsonValue;
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestAuthTextInputCallbackHandler method convertToJson.
/**
* {@inheritDoc}
*/
public JsonValue convertToJson(TextInputCallback callback, int index) {
String prompt = callback.getPrompt();
String defaultText = callback.getDefaultText();
String text = callback.getText();
JsonValue jsonValue = JsonValueBuilder.jsonValue().put("type", CALLBACK_NAME).array("output").add(createOutputField("prompt", prompt)).addLast(createOutputField("defaultText", defaultText)).array("input").addLast(createInputField(index, text)).build();
return jsonValue;
}
Aggregations