use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.
the class PendingRequestResource method queryCollection.
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
if (request.getQueryFilter() == null) {
return new NotSupportedException("Only query filter is supported.").asPromise();
}
try {
List<ResourceResponse> values = new ArrayList<>();
// Filter items based on query filter.
for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
if (request.getQueryFilter().accept(QUERY_VISITOR, pendingRequest.asJson())) {
values.add(newResourceResponse(pendingRequest.getId(), null, pendingRequest.asJson()));
}
}
// Sort and Page for presentation
QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
return QueryResponsePresentation.perform(handler, request, values);
} catch (ResourceException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.
the class PendingRequestResource method actionCollection.
@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
try {
if (APPROVE_ACTION_ID.equalsIgnoreCase(request.getAction())) {
List<Promise<Void, ResourceException>> promises = new ArrayList<>();
JsonValue content = request.getContent();
for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
promises.add(service.approvePendingRequest(context, pendingRequest.getId(), content.get(pendingRequest.getId()), ServerContextUtils.getRealm(context)));
}
return handlePendingRequestApproval(promises);
} else if (DENY_ACTION_ID.equalsIgnoreCase(request.getAction())) {
for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
service.denyPendingRequest(pendingRequest.getId(), ServerContextUtils.getRealm(context));
}
return newResultPromise(newActionResponse((json(object()))));
} else {
return new NotSupportedException("Action, " + request.getAction() + ", is not supported.").asPromise();
}
} catch (ResourceException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.
the class UmaEnabledFilter method enabled.
private Promise<Void, ResourceException> enabled(Context serverContext) {
try {
String realm = RealmContext.getRealm(serverContext);
UmaProviderSettings settings = umaProviderSettingsFactory.get(realm);
if (settings.isEnabled()) {
return newResultPromise(null);
}
} catch (NotFoundException ignore) {
}
return new NotSupportedException("UMA is not currently supported in this realm").asPromise();
}
use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.
the class PolicyResource method actionCollection.
/**
* {@inheritDoc}
*/
@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest actionRequest) {
final String actionString = actionRequest.getAction();
final PolicyAction action = PolicyAction.getAction(actionString);
if (!PolicyAction.isEvaluateAction(action)) {
final String errorMsg = "Action '" + actionString + "' not implemented for this resource";
final NotSupportedException nsE = new NotSupportedException(errorMsg);
DEBUG.error(errorMsg, nsE);
return nsE.asPromise();
}
try {
if (DEBUG.messageEnabled()) {
DEBUG.message("Rendering policy request for action " + actionString);
}
final PolicyRequest request = requestFactory.buildRequest(action, context, actionRequest);
final PolicyEvaluator evaluator = factory.getEvaluator(request.getRestSubject(), request.getApplication());
if (DEBUG.messageEnabled()) {
final StringBuilder builder = new StringBuilder();
builder.append("Evaluating policy request for action ");
builder.append(actionString);
builder.append(" under realm ");
builder.append(request.getRealm());
builder.append(" within the application context ");
builder.append(request.getApplication());
DEBUG.message(builder.toString());
}
final List<Entitlement> entitlements = evaluator.routePolicyRequest(request);
return newResultPromise(newActionResponse(policyParser.printEntitlements(entitlements)));
} catch (final EntitlementException eE) {
DEBUG.error("Error evaluating policy request", eE);
return resourceErrorHandler.handleError(context, actionRequest, eE).asPromise();
}
}
use of org.forgerock.json.resource.NotSupportedException 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();
}
}
Aggregations