use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class SitesResourceProvider method updateInstance.
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String id, UpdateRequest request) {
JsonValue content = request.getContent();
try {
validWriteOperation(content, id);
} catch (BadRequestException e) {
return e.asPromise();
}
ResourceResponse site;
SSOToken token;
try {
token = getSsoToken(context);
site = getSite(token, id);
} catch (SMSException | SSOException | ConfigurationException e) {
debug.error("Could not read site {}", id, e);
return new InternalServerErrorException("Could not read site").asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
try {
if (!site.getRevision().equals(request.getRevision())) {
return new PreconditionFailedException("Revision did not match").asPromise();
}
SiteConfiguration.setSitePrimaryURL(token, id, content.get("url").asString());
SiteConfiguration.setSiteSecondaryURLs(token, id, content.get("secondaryURLs").asSet());
return newResultPromise(getSite(token, id));
} catch (SSOException | SMSException | ConfigurationException e) {
debug.error("Could not update site {}", id, e);
return new InternalServerErrorException("Could not update site").asPromise();
} catch (NotFoundException e) {
return new InternalServerErrorException("Could not read site after just updating it", e).asPromise();
}
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class SmsCollectionProvider method createInstance.
/**
* Creates a new child instance of config. The parent config referenced by the request path is found, and
* new config is created using the provided name property.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {
JsonValue content = request.getContent();
final String realm = realmFor(context);
try {
Map<String, Set<String>> attrs = converter.fromJson(realm, content);
ServiceConfigManager scm = getServiceConfigManager(context);
ServiceConfig config = parentSubConfigFor(context, scm);
String name = content.get("_id").asString();
if (name == null) {
name = request.getNewResourceId();
} else if (request.getNewResourceId() != null && !name.equals(request.getNewResourceId())) {
return new BadRequestException("name and URI's resource ID do not match").asPromise();
}
if (name == null) {
return new BadRequestException("Invalid name").asPromise();
}
config.addSubConfig(name, lastSchemaNodeName(), 0, attrs);
final ServiceConfig created = checkedInstanceSubConfig(context, name, config);
return awaitCreation(context, name).then(new Function<Void, ResourceResponse, ResourceException>() {
@Override
public ResourceResponse apply(Void aVoid) {
JsonValue result = getJsonValue(realm, created);
return newResourceResponse(created.getName(), String.valueOf(result.hashCode()), result);
}
});
} catch (ServiceAlreadyExistsException e) {
debug.warning("::SmsCollectionProvider:: ServiceAlreadyExistsException on create", e);
return new ConflictException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (ResourceException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class SessionResource method actionCollection.
/**
* Actions supported are:
* <ul>
* <li>{@link #LOGOUT_ACTION_ID}</li>
* <li>{@link #VALIDATE_ACTION_ID}</li>
* <li>{@link #IS_ACTIVE_ACTION_ID}</li>
* <li>{@link #GET_MAX_TIME_ACTION_ID}</li>
* <li>{@link #GET_IDLE_ACTION_ID}</li>
* </ul>
*
* @param context {@inheritDoc}
* @param request {@inheritDoc}
*/
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
final String cookieName = SystemProperties.get(Constants.AM_COOKIE_NAME, "iPlanetDirectoryPro");
String tokenId = getTokenIdFromUrlParam(request);
if (tokenId == null) {
tokenId = getTokenIdFromHeader(context, cookieName);
}
if (tokenId == null) {
tokenId = getTokenIdFromCookie(context, cookieName);
}
// code will have to be moved/changed.
if (tokenId == null) {
final BadRequestException e = new BadRequestException("iPlanetDirectoryCookie not set on request");
LOGGER.message("SessionResource.handleNullSSOToken :: iPlanetDirectoryCookie not set on request", e);
return e.asPromise();
}
return internalHandleAction(tokenId, context, request);
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class RecordResource method actionStop.
/**
* Stop action
*
* @return
*/
private Promise<ActionResponse, ResourceException> actionStop() {
try {
Record record = debugRecorder.stopRecording();
if (record == null) {
return new BadRequestException("No record or it's already stopped.").asPromise();
} else {
JsonObject result = JsonValueBuilder.jsonValue();
result.put(STATUS_LABEL, false);
result.put(RECORD_LABEL, record.exportJson().asMap());
return newResultPromise(newActionResponse(result.build()));
}
} catch (RecordException e) {
debug.message("Record can't be stopped.", e);
return new BadRequestException("Record can't be stopped.", e).asPromise();
}
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class SoapSTSPublishServiceRequestHandler method handleQuery.
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
QueryFilter<JsonPointer> queryFilter = request.getQueryFilter();
if (queryFilter == null) {
return new BadRequestException(getQueryUsageString()).asPromise();
}
String realm;
try {
realm = getRealmFromQueryFilter(queryFilter);
} catch (STSPublishException e) {
return e.asPromise();
}
try {
if (!realmValidator.isRealm(realm)) {
return new BadRequestException("The specified realm does not exist.").asPromise();
}
final List<SoapSTSInstanceConfig> publishedInstances = publisher.getPublishedInstances(realm);
for (SoapSTSInstanceConfig instanceConfig : publishedInstances) {
/*
Although instanceConfig.toJson() will yield the JsonValue which the handleResource invocation requires,
the SoapSTSInstanceConfig is a complicated nesting of JsonValue objects, which should be 'homogenized'
into a json format prior to inclusion in the response.
*/
handler.handleResource(newResourceResponse(instanceConfig.getDeploymentSubPath(), getInstanceConfigEtag(instanceConfig), new JsonValue(mapStringToJson(instanceConfig.toJson().toString()))));
}
return newResultPromise(newQueryResponse());
} catch (STSPublishException e) {
logger.error("Exception caught obtaining soap sts instances for realm " + (realm != null ? realm : "null realm") + "; Exception: " + e);
return e.asPromise();
}
}
Aggregations