use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class SmsCollectionProvider method deleteInstance.
/**
* Deletes a child instance of config. The parent config referenced by the request path is found, and
* the config is deleted using the resourceId.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, final String resourceId, DeleteRequest request) {
try {
ServiceConfigManager scm = getServiceConfigManager(context);
ServiceConfig config = parentSubConfigFor(context, scm);
checkedInstanceSubConfig(context, resourceId, config);
if (isDefaultCreatedAuthModule(context, resourceId)) {
scm.removeOrganizationConfiguration(realmFor(context), null);
} else {
config.removeSubConfig(resourceId);
}
return awaitDeletion(context, resourceId).then(new Function<Void, ResourceResponse, ResourceException>() {
@Override
public ResourceResponse apply(Void aVoid) {
return newResourceResponse(resourceId, "0", json(object(field("success", true))));
}
});
} catch (ServiceNotFoundException e) {
debug.warning("::SmsCollectionProvider:: ServiceNotFoundException on delete", e);
return new NotFoundException("Unable to delete SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on delete", e);
return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on delete", e);
return new InternalServerErrorException("Unable to delete SMS config: " + e.getMessage()).asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class SmsSingletonProvider method handleCreate.
/**
* Creates config for the singleton instance referenced, and returns the JsonValue representation.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> handleCreate(Context serverContext, CreateRequest createRequest) {
final String realm = realmFor(serverContext);
try {
Map<String, Set<String>> attrs = convertFromJson(createRequest.getContent(), realm);
ServiceConfigManager scm = getServiceConfigManager(serverContext);
ServiceConfig config;
if (subSchemaPath.isEmpty()) {
if (type == SchemaType.GLOBAL) {
config = scm.createGlobalConfig(attrs);
} else {
config = scm.createOrganizationConfig(realm, attrs);
}
} else {
ServiceConfig parent = parentSubConfigFor(serverContext, scm);
parent.addSubConfig(resourceId(), lastSchemaNodeName(), -1, attrs);
config = parent.getSubConfig(lastSchemaNodeName());
}
JsonValue result = withExtraAttributes(realm, convertToJson(realm, config));
return newResultPromise(newResourceResponse(resourceId(), String.valueOf(result.hashCode()), result));
} 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.ResourceException in project OpenAM by OpenRock.
the class SmsRealmProvider method handleDelete.
@Override
public Promise<ResourceResponse, ResourceException> handleDelete(Context serverContext, DeleteRequest request) {
RealmContext realmContext = serverContext.asContext(RealmContext.class);
String realmPath = realmContext.getResolvedRealm();
try {
OrganizationConfigManager realmManager = new OrganizationConfigManager(getSSOToken(), realmPath);
final ResourceResponse resource = getResource(getJsonValue(realmPath));
realmManager.deleteSubOrganization(null, false);
String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(serverContext);
debug.message("RealmResource.deleteInstance :: DELETE of realm " + realmPath + " performed by " + principalName);
return newResultPromise(resource);
} catch (SMSException smse) {
ResourceException exception = configureErrorMessage(smse);
if (exception instanceof NotFoundException) {
debug.warning("RealmResource.deleteInstance() : Cannot find {}", realmPath, smse);
return exception.asPromise();
} else if (exception instanceof ForbiddenException || exception instanceof PermanentException || exception instanceof ConflictException || exception instanceof BadRequestException) {
debug.warning("RealmResource.deleteInstance() : Cannot DELETE {}", realmPath, smse);
return exception.asPromise();
} else {
return new BadRequestException(exception.getMessage(), exception).asPromise();
}
} catch (Exception e) {
return new BadRequestException(e.getMessage(), e).asPromise();
}
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class SmsRealmProvider method handleRead.
@Override
public Promise<ResourceResponse, ResourceException> handleRead(Context context, ReadRequest request) {
RealmContext realmContext = context.asContext(RealmContext.class);
String realmPath = realmContext.getResolvedRealm();
if (!request.getResourcePath().isEmpty()) {
//if the resource path is not empty, the realm has not resolved correctly
return new NotFoundException("Realm \"" + RealmUtils.concatenateRealmPath(RealmUtils.cleanRealm(realmPath), RealmUtils.cleanRealm(request.getResourcePath())) + "\" is not a valid realm.").asPromise();
}
try {
JsonValue jsonResponse = getJsonValue(realmPath);
if (debug.messageEnabled()) {
debug.message("RealmResource.readInstance :: READ : Successfully read realm, " + realmPath + " performed by " + PrincipalRestUtils.getPrincipalNameFromServerContext(context));
}
return newResultPromise(getResource(jsonResponse));
} catch (SMSException smse) {
ResourceException exception = configureErrorMessage(smse);
if (exception instanceof NotFoundException) {
debug.warning("RealmResource.readInstance() : Cannot find {}", realmPath, smse);
return exception.asPromise();
} else if (exception instanceof ForbiddenException || exception instanceof PermanentException || exception instanceof ConflictException || exception instanceof BadRequestException) {
debug.warning("RealmResource.readInstance() : Cannot READ {}", realmPath, smse);
return exception.asPromise();
} else {
return new BadRequestException(exception.getMessage(), exception).asPromise();
}
} catch (Exception e) {
return new BadRequestException(e.getMessage(), e).asPromise();
}
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class SessionResourceAuthzModuleTest method shouldAllowLogoutAction.
@Test
public void shouldAllowLogoutAction() throws ExecutionException, InterruptedException {
//given
Context mockContext = mock(Context.class);
ActionRequest mockRequest = mock(ActionRequest.class);
given(mockRequest.getAction()).willReturn("logout");
//when
Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest);
//then
assertTrue(result.get().isAuthorized());
}
Aggregations