use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class AMTokenParserImpl method getSessionFromAuthNResponse.
@Override
public String getSessionFromAuthNResponse(String authNResponse) throws TokenValidationException {
JsonValue responseJson;
try {
responseJson = JsonValueBuilder.toJsonValue(authNResponse);
} catch (JsonException e) {
String message = "Exception caught getting the text of the json authN response: " + e;
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, message, e);
}
JsonValue sessionIdJsonValue = responseJson.get(TOKEN_ID);
if (!sessionIdJsonValue.isString()) {
String message = "REST authN response does not contain " + TOKEN_ID + " string entry. The obtained entry: " + sessionIdJsonValue.toString() + "; The response: " + responseJson.toString();
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, message);
}
return sessionIdJsonValue.asString();
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class DecisionCombinersResource method queryCollection.
/**
* {@inheritDoc}
*/
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
final Set<String> combinerTypeNames = new TreeSet<>();
List<ResourceResponse> combinerTypes = new ArrayList<>();
final String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(context);
combinerTypeNames.addAll(entitlementRegistry.getCombinersShortNames());
for (String combinerTypeName : combinerTypeNames) {
final Class<? extends EntitlementCombiner> conditionClass = entitlementRegistry.getCombinerType(combinerTypeName);
if (conditionClass == null) {
if (debug.warningEnabled()) {
debug.warning("DecisionCombinersResource :: QUERY by " + principalName + ": Listed combiner short name not found: " + combinerTypeName);
}
continue;
}
final JsonValue json = jsonify(combinerTypeName);
if (json != null) {
if (json != null) {
String id = json.get(JSON_OBJ_TITLE).asString();
combinerTypes.add(newResourceResponse(id, null, json));
}
}
}
QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
return QueryResponsePresentation.perform(handler, request, combinerTypes);
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class SubjectTypesResource method readInstance.
/**
* {@inheritDoc}
*
* Uses the {@link EntitlementRegistry} to locate the {@link EntitlementSubject} to return.
*/
@Override
public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) {
final Class<? extends EntitlementSubject> subjectClass = entitlementRegistry.getSubjectType(resourceId);
final String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(context);
if (subjectClass == null) {
if (debug.errorEnabled()) {
debug.error("SubjectTypesResource :: READ by " + principalName + "Requested subject short name not found: " + resourceId);
}
return new NotFoundException().asPromise();
}
final JsonValue json = jsonify(subjectClass, resourceId, LogicalSubject.class.isAssignableFrom(subjectClass));
final ResourceResponse resource = newResourceResponse(resourceId, String.valueOf(System.currentTimeMillis()), json);
return newResultPromise(resource);
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class ApplicationV1Filter method filterUpdate.
/**
* Update expects the application json to contain both actions and resources; these attributes are part of the old
* json definition for an application. It also expects that the mentioned application exists with exactly one
* resource type - no resource types or many resource types is not acceptable, else it is impossible to determine
* which resource type applies to the set of actions and resources being passed as part of the application json.
* <p/>
* Changes to the actions and/or resources will be reflected in the applications associated resource type.
*
* @param context
* the filter chain context
* @param request
* the update request
* @param next
* a request handler representing the remainder of the filter chain
*/
@Override
public Promise<ResourceResponse, ResourceException> filterUpdate(final Context context, final UpdateRequest request, final RequestHandler next) {
final JsonValue jsonValue = request.getContent();
final Map<String, Boolean> actions = jsonValue.get(ACTIONS).asMap(Boolean.class);
final Set<String> resources = jsonValue.get(RESOURCES).asSet(String.class);
final String bodyRealm = jsonValue.get(REALM).asString();
final String pathRealm = contextHelper.getRealm(context);
if (actions == null) {
return new BadRequestException("Invalid actions defined in request").asPromise();
}
if (resources == null) {
return new BadRequestException("Invalid resources defined in request").asPromise();
}
if (!pathRealm.equals(bodyRealm)) {
return resourceErrorHandler.handleError(context, request, new EntitlementException(EntitlementException.INVALID_APP_REALM, new String[] { bodyRealm, pathRealm })).asPromise();
}
final Subject callingSubject = contextHelper.getSubject(context);
final String applicationName = request.getResourcePath();
try {
final ApplicationService applicationService = applicationServiceFactory.create(callingSubject, pathRealm);
final Application application = applicationService.getApplication(applicationName);
if (application == null) {
return new NotFoundException("Unable to find application " + applicationName).asPromise();
}
if (application.getResourceTypeUuids().size() != 1) {
return new BadRequestException("Cannot modify application with more than one " + "resource type using version 1.0 of this endpoint").asPromise();
}
// Retrieve the resource type from the applications single resource type.
final String resourceTypeUuid = application.getResourceTypeUuids().iterator().next();
ResourceType resourceType = resourceTypeService.getResourceType(callingSubject, pathRealm, resourceTypeUuid);
boolean resourceTypeModified = false;
if (!actions.equals(resourceType.getActions())) {
resourceTypeModified = true;
resourceType = resourceType.populatedBuilder().setActions(actions).build();
}
if (!resources.equals(resourceType.getPatterns())) {
resourceTypeModified = true;
resourceType = resourceType.populatedBuilder().setPatterns(resources).build();
}
if (resourceTypeModified) {
resourceTypeService.updateResourceType(callingSubject, pathRealm, resourceType);
}
// Ensure the resource type UUID isn't lost.
jsonValue.put(RESOURCE_TYPE_UUIDS, new HashSet<String>(Arrays.asList(resourceTypeUuid)));
} catch (EntitlementException eE) {
debug.error("Error filtering application update CREST request", eE);
return resourceErrorHandler.handleError(context, request, eE).asPromise();
}
// Forward onto next handler.
return applicationTransformer.transform(next.handleUpdate(context, request), context);
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class PolicyV1Filter method filterCreate.
/**
* The policy json will not have any resource type defined. Create retrieves the policy's associated application
* and uses the applications associated resource type for the policy.
*
* @param context
* the filter chain context
* @param request
* the create request
* @param next
* a request handler representing the remainder of the filter chain
*/
@Override
public Promise<ResourceResponse, ResourceException> filterCreate(Context context, CreateRequest request, RequestHandler next) {
try {
final JsonValue jsonValue = request.getContent();
final Subject callingSubject = contextHelper.getSubject(context);
final String realm = contextHelper.getRealm(context);
retrieveResourceType(jsonValue, callingSubject, realm);
} catch (EntitlementException eE) {
debug.error("Error filtering policy create CREST request", eE);
return resourceErrorHandler.handleError(context, request, eE).asPromise();
} catch (ResourceException rE) {
debug.error("Error filtering policy create CREST request", rE);
return rE.asPromise();
}
return transform(next.handleCreate(context, request));
}
Aggregations