use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class SoapSTSPublishServiceRequestHandler method handleUpdate.
/*
* A PUT to the url composed of the publish endpont + the sts instance id with a payload corresponding to a
* SoapSTSInstanceId (wrapped in invocation context information) will result in republishing the existing instance
* (which is a delete followed by a create).
*/
public Promise<ResourceResponse, ResourceException> handleUpdate(Context context, UpdateRequest request) {
String stsId = request.getResourcePath();
String realm = getRealmFromResourceName(request.getResourcePath());
if (!realmValidator.isRealm(realm)) {
logger.warn("Update of soap STS instance state for instance " + stsId + " in realm " + realm + " rejected because realm does not exist");
return new NotFoundException("The specified realm does not exist.").asPromise();
}
/*
Insure that the instance is published before performing an update.
*/
final boolean publishedToSMS;
try {
publishedToSMS = (publisher.getPublishedInstance(stsId, realm) != null);
} catch (STSPublishException e) {
logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught determining whether " + "instance persisted in SMS. Instance not updated. Exception: " + e, e);
return e.asPromise();
}
if (publishedToSMS) {
SoapSTSInstanceConfig instanceConfig;
try {
instanceConfig = marshalInstanceConfigFromInvocation(request.getContent());
} catch (BadRequestException e) {
logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught marshalling " + "invocation state to SoapSTSInstanceConfig. Instance not updated. The state: " + request.getContent() + "Exception: " + e, e);
return e.asPromise();
}
try {
publisher.removeInstance(stsId, realm);
} catch (STSPublishException e) {
logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught removing " + "soap sts instance " + instanceConfig.getDeploymentSubPath() + ". This means instance is" + "in indeterminate state, and has not been updated. The instance config: " + instanceConfig + "; Exception: " + e, e);
return e.asPromise();
}
try {
ResourceResponse response = publishInstance(instanceConfig);
logger.info("Soap STS instance " + instanceConfig.getDeploymentSubPath() + " updated to state " + instanceConfig.toJson());
return newResultPromise(response);
} catch (ResourceException e) {
logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught publishing " + "soap sts instance " + instanceConfig.getDeploymentSubPath() + ". This means instance is" + "in indeterminate state, having been removed, but not successfully published with updated " + "state. The instance config: " + instanceConfig + "; Exception: " + e, e);
return e.asPromise();
}
} else {
//404 - realm and id not found in SMS
return new NotFoundException("No soap sts instance with id " + stsId + " in realm " + realm).asPromise();
}
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class TokenGenerationService method queryCollection.
@Override
public Promise<QueryResponse, ResourceException> queryCollection(final Context serverContext, final QueryRequest queryRequest, final QueryResourceHandler queryResultHandler) {
QueryFilter<JsonPointer> queryFilter = queryRequest.getQueryFilter();
if (queryFilter == null) {
return new BadRequestException(getUsageString()).asPromise();
}
try {
final QueryFilter<CoreTokenField> coreTokenFieldQueryFilter = convertToCoreTokenFieldQueryFilter(queryFilter);
final List<STSIssuedTokenState> issuedTokens = ctsTokenPersistence.listTokens(coreTokenFieldQueryFilter);
for (STSIssuedTokenState tokenState : issuedTokens) {
queryResultHandler.handleResource(newResourceResponse(tokenState.getTokenId(), EMPTY_STRING, tokenState.toJson()));
}
return newResultPromise(newQueryResponse());
} catch (CTSTokenPersistenceException e) {
logger.error("Exception caught obtaining list of sts-issued tokens: " + e, e);
return e.asPromise();
}
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class UmaLabelResource method createInstance.
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context serverContext, CreateRequest createRequest) {
final JsonValue umaLabel = createRequest.getContent();
try {
validate(umaLabel);
} catch (BadRequestException e) {
return e.asPromise();
}
final String realm = getRealm(serverContext);
final String userName = getUserName(serverContext);
final String labelName = umaLabel.get(NAME_LABEL).asString();
final String labelType = umaLabel.get(TYPE_LABEL).asString();
final ResourceSetLabel label;
try {
label = labelStore.create(realm, userName, new ResourceSetLabel(null, labelName, LabelType.valueOf(labelType), Collections.EMPTY_SET));
return newResultPromise(newResourceResponse(label.getId(), String.valueOf(label.hashCode()), label.asJson()));
} catch (ResourceException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class UmaLabelResource method deleteInstance.
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context serverContext, String labelId, DeleteRequest deleteRequest) {
try {
ResourceSetLabel resourceSetLabel = labelStore.read(getRealm(serverContext), getUserName(serverContext), labelId);
if (!isSameRevision(deleteRequest, resourceSetLabel)) {
throw new BadRequestException("Revision number doesn't match latest revision.");
}
labelStore.delete(getRealm(serverContext), getUserName(serverContext), labelId);
return newResultPromise(newResourceResponse(labelId, null, resourceSetLabel.asJson()));
} catch (ResourceException e) {
return new BadRequestException("Error deleting label.").asPromise();
}
}
use of org.forgerock.json.resource.BadRequestException in project OpenAM by OpenRock.
the class PolicyV1Filter method retrieveResourceType.
/**
* Retrieves the resource type Id from the containing application
* and sets it within the policies' JSON representation.
*
* @param jsonValue
* the policies' JSON representation
* @param callingSubject
* the calling subject
* @param realm
* the realm
*
* @throws EntitlementException
* should some policy error occur
* @throws ResourceException
* should some violation occur that doesn't satisfy policy v1.0
*/
private void retrieveResourceType(JsonValue jsonValue, Subject callingSubject, String realm) throws EntitlementException, ResourceException {
final String applicationName = jsonValue.get("applicationName").asString();
if (applicationName == null) {
throw new BadRequestException("Invalid application name defined in request");
}
final ApplicationService applicationService = applicationServiceFactory.create(callingSubject, realm);
final Application application = applicationService.getApplication(applicationName);
if (application == null) {
throw new NotFoundException("Unable to find application " + applicationName);
}
if (application.getResourceTypeUuids().size() != 1) {
throw new BadRequestException("Cannot create policy under an application with more than " + "one resource type using version 1.0 of this endpoint");
}
// Retrieve the resource type from the applications single resource type.
final String resourceTypeUuid = application.getResourceTypeUuids().iterator().next();
jsonValue.put(RESOURCE_TYPE_UUID, resourceTypeUuid);
}
Aggregations