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