Search in sources :

Example 1 with JsonValue

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);
}
Also used : JsonValue(org.forgerock.json.JsonValue) Date(java.util.Date)

Example 2 with JsonValue

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();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException)

Example 3 with JsonValue

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();
    }
}
Also used : Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) CoreTokenException(org.forgerock.openam.cts.exceptions.CoreTokenException) Token(org.forgerock.openam.cts.api.tokens.Token)

Example 4 with JsonValue

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;
}
Also used : JsonValue(org.forgerock.json.JsonValue)

Example 5 with 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;
}
Also used : JsonValue(org.forgerock.json.JsonValue)

Aggregations

JsonValue (org.forgerock.json.JsonValue)575 Test (org.testng.annotations.Test)333 ResourceException (org.forgerock.json.resource.ResourceException)144 ResourceResponse (org.forgerock.json.resource.ResourceResponse)123 RealmContext (org.forgerock.openam.rest.RealmContext)70 Context (org.forgerock.services.context.Context)63 HashSet (java.util.HashSet)56 SSOException (com.iplanet.sso.SSOException)54 ArrayList (java.util.ArrayList)51 BadRequestException (org.forgerock.json.resource.BadRequestException)47 Privilege (com.sun.identity.entitlement.Privilege)46 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)46 SSOToken (com.iplanet.sso.SSOToken)43 SMSException (com.sun.identity.sm.SMSException)42 HashMap (java.util.HashMap)42 NotFoundException (org.forgerock.json.resource.NotFoundException)41 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)41 CreateRequest (org.forgerock.json.resource.CreateRequest)40 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 Subject (javax.security.auth.Subject)32