Search in sources :

Example 66 with JsonValue

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

the class OpenIDConnectProviderConfiguration method getConfiguration.

/**
     * Gets the OpenId configuration for the OpenId Connect provider.
     *
     * @param request The OAuth2 request.
     * @return A JsonValue representation of the OpenId configuration.
     * @throws UnsupportedResponseTypeException If the requested response type is not supported by either the client
     *          or the OAuth2 provider.
     * @throws ServerException If any internal server error occurs.
     */
public JsonValue getConfiguration(OAuth2Request request) throws OAuth2Exception {
    final OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
    final OAuth2Uris uris = urisFactory.get(request);
    if (!providerSettings.exists() || providerSettings.getSupportedScopes() == null || !providerSettings.getSupportedScopes().contains("openid")) {
        throw new NotFoundException("Invalid URL");
    }
    final Map<String, Object> configuration = new HashMap<>();
    configuration.put("version", providerSettings.getOpenIDConnectVersion());
    configuration.put("issuer", uris.getIssuer());
    configuration.put("authorization_endpoint", uris.getAuthorizationEndpoint());
    configuration.put("token_endpoint", uris.getTokenEndpoint());
    configuration.put("userinfo_endpoint", uris.getUserInfoEndpoint());
    configuration.put("check_session_iframe", uris.getCheckSessionEndpoint());
    configuration.put("end_session_endpoint", uris.getEndSessionEndpoint());
    configuration.put("jwks_uri", uris.getJWKSUri());
    configuration.put("registration_endpoint", uris.getClientRegistrationEndpoint());
    configuration.put("claims_supported", providerSettings.getSupportedClaims());
    configuration.put("scopes_supported", providerSettings.getSupportedScopes());
    configuration.put("response_types_supported", getResponseTypes(providerSettings.getAllowedResponseTypes().keySet()));
    configuration.put("subject_types_supported", providerSettings.getSupportedSubjectTypes());
    configuration.put("id_token_signing_alg_values_supported", providerSettings.getSupportedIDTokenSigningAlgorithms());
    configuration.put("acr_values_supported", providerSettings.getAcrMapping().keySet());
    configuration.put("claims_parameter_supported", providerSettings.getClaimsParameterSupported());
    configuration.put("token_endpoint_auth_methods_supported", providerSettings.getEndpointAuthMethodsSupported());
    return new JsonValue(configuration);
}
Also used : OAuth2Uris(org.forgerock.oauth2.core.OAuth2Uris) HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings)

Example 67 with JsonValue

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

the class ResourceSetDescriptionValidator method validate.

/**
     * Validates that the resource set description is valid.
     *
     * @param resourceSetDescription The resource set description to validate.
     * @return The same resource set description.
     * @throws BadRequestException If any part of the resource set description is not valid.
     */
public Map<String, Object> validate(Map<String, Object> resourceSetDescription) throws BadRequestException {
    JsonValue description = json(resourceSetDescription);
    validateName(description);
    validateUri(description);
    validateType(description);
    validateScopes(description);
    validateIconUri(description);
    validateLabels(description);
    return resourceSetDescription;
}
Also used : JsonValue(org.forgerock.json.JsonValue)

Example 68 with JsonValue

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

the class CrestAuditorTest method auditSuccessShouldPublishEvents.

@Test(dataProvider = "CRESTRequests")
public void auditSuccessShouldPublishEvents(Request request) throws Exception {
    given(auditEventPublisher.isAuditing(anyString(), anyString(), any(EventName.class))).willReturn(true);
    auditor = new CrestAuditor(debug, auditEventPublisher, auditEventFactory, context, request);
    givenAccessAuditingEnabled(auditEventPublisher);
    final JsonValue detail = json(object(field("foo", "bar")));
    auditor.auditAccessSuccess(detail);
    ArgumentCaptor<AuditEvent> auditEventCaptor = ArgumentCaptor.forClass(AuditEvent.class);
    verify(auditEventPublisher).tryPublish(eq(ACCESS_TOPIC), auditEventCaptor.capture());
    assertThat(getField(auditEventCaptor, EVENT_NAME).asString()).isEqualTo(EventName.AM_ACCESS_OUTCOME.toString());
    assertThat(getField(auditEventCaptor, RESPONSE + "/" + DETAIL).asMap()).isEqualTo(detail.asMap());
}
Also used : JsonValue(org.forgerock.json.JsonValue) AuditEvent(org.forgerock.audit.events.AuditEvent) Test(org.testng.annotations.Test)

Example 69 with JsonValue

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

the class ScriptResource method actionCollection.

@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    if ("validate".equals(request.getAction())) {
        try {
            JsonValue json = request.getContent();
            SupportedScriptingLanguage language = getLanguageFromString(json.get(SCRIPT_LANGUAGE).asString());
            String script = json.get(SCRIPT_TEXT).asString();
            if (script == null) {
                throw new ScriptException(MISSING_SCRIPT);
            }
            List<ScriptError> scriptErrorList = scriptValidator.validateScript(new ScriptObject(EMPTY, decodeScript(script), language, null));
            if (scriptErrorList.isEmpty()) {
                return newResultPromise(newActionResponse(json(object(field("success", true)))));
            }
            Set<Object> errors = new HashSet<>();
            for (ScriptError error : scriptErrorList) {
                errors.add(object(field("line", error.getLineNumber()), field("column", error.getColumnNumber()), field("message", error.getMessage())));
            }
            return newResultPromise(newActionResponse(json(object(field("success", false), field("errors", errors)))));
        } catch (ScriptException se) {
            return exceptionMappingHandler.handleError(context, request, se).asPromise();
        }
    } else {
        return new NotSupportedException().asPromise();
    }
}
Also used : ScriptException(org.forgerock.openam.scripting.ScriptException) ScriptObject(org.forgerock.openam.scripting.ScriptObject) ScriptError(org.forgerock.openam.scripting.ScriptError) JsonValue(org.forgerock.json.JsonValue) ScriptObject(org.forgerock.openam.scripting.ScriptObject) SupportedScriptingLanguage(org.forgerock.openam.scripting.SupportedScriptingLanguage) NotSupportedException(org.forgerock.json.resource.NotSupportedException) HashSet(java.util.HashSet)

Example 70 with JsonValue

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

the class Requester method query.

/**
     * Request to perform a query at a specified endpoint.
     *
     * @param location Endpoint destination of this request. May not be null.
     * @param queryId Specific query ID to perform. May be null.
     * @param context Context of this request.
     * @return The {@link org.forgerock.json.JsonValue} returned from the endpoint.
     * @throws ResourceException If any exception occurred during processing.
     */
public JsonValue query(String location, String queryId, Context context) throws ResourceException {
    Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty.");
    final Router rootRouter = router.get();
    final QueryRequest queryRequest = Requests.newQueryRequest(location);
    if (queryId != null) {
        queryRequest.setQueryId(queryId);
    }
    final InMemoryQueryResourceHandler resourceHandler = new InMemoryQueryResourceHandler();
    return rootRouter.handleQuery(context, queryRequest, resourceHandler).thenAsync(new AsyncFunction<QueryResponse, JsonValue, ResourceException>() {

        @Override
        public Promise<JsonValue, ResourceException> apply(QueryResponse value) {
            final JsonArray responses = JsonValueBuilder.jsonValue().array("results");
            for (ResourceResponse resource : resourceHandler.getResources()) {
                responses.add(resource.getContent());
            }
            return newResultPromise(responses.build().build());
        }
    }).getOrThrowUninterruptibly();
}
Also used : JsonArray(org.forgerock.openam.utils.JsonArray) QueryRequest(org.forgerock.json.resource.QueryRequest) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) JsonValue(org.forgerock.json.JsonValue) Router(org.forgerock.json.resource.Router) ResourceException(org.forgerock.json.resource.ResourceException) AsyncFunction(org.forgerock.util.AsyncFunction)

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