use of com.bluenimble.platform.api.ApiAccessDeniedException in project serverless by bluenimble.
the class GetRecordSpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String sEntity = (String) request.get(CommonSpec.Entity);
String record = (String) request.get(Spec.Record);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
DatabaseObject dbo = null;
try {
Database db = space.feature(Database.class, provider, request);
dbo = db.get(sEntity, record);
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
if (dbo == null) {
return null;
}
return new JsonApiOutput(dbo.toJson(null));
}
use of com.bluenimble.platform.api.ApiAccessDeniedException in project serverless by bluenimble.
the class GetKeysSpi method getNotSecure.
private ApiOutput getNotSecure(Api api, ApiRequest request, String accessKey, String paraphrase) throws ApiServiceExecutionException {
ApiSpace keysSpace = null;
int indexOfDot = accessKey.indexOf(Lang.DOT);
if (indexOfDot <= 0) {
throw new ApiServiceExecutionException("invalid accessKey. Using super privileges, you should prefix the accessKey by the space NS.").status(ApiResponse.BAD_REQUEST);
}
String space = accessKey.substring(0, indexOfDot);
accessKey = accessKey.substring(indexOfDot + 1);
try {
keysSpace = api.space().space(space);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException("access denied").status(ApiResponse.FORBIDDEN);
}
KeyPair skp = null;
try {
skp = keysSpace.keystore().get(accessKey, true);
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
if (skp == null) {
throw new ApiServiceExecutionException("keys " + accessKey + " not found").status(ApiResponse.NOT_FOUND);
}
try {
return toOutput(skp, paraphrase, keysSpace, api, request);
} catch (Exception e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
}
use of com.bluenimble.platform.api.ApiAccessDeniedException in project serverless by bluenimble.
the class DescribeApiSpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String apiNs = (String) request.get(CommonSpec.Api);
Api uApi;
try {
uApi = MgmUtils.api(consumer, api, apiNs);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.NOT_FOUND);
}
if (uApi == null) {
throw new ApiServiceExecutionException("api '" + apiNs + "' not found").status(ApiResponse.NOT_FOUND);
}
return new JsonApiOutput(uApi.describe(MgmUtils.options((String) request.get(CommonSpec.Options), DescribeOption.Info)));
}
use of com.bluenimble.platform.api.ApiAccessDeniedException in project serverless by bluenimble.
the class DeleteEntrySpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String key = (String) request.get(Spec.Key);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
Cache cache = space.feature(Cache.class, provider, request);
cache.delete(key);
return new JsonApiOutput((JsonObject) new JsonObject().set(CommonOutput.Deleted, true));
}
use of com.bluenimble.platform.api.ApiAccessDeniedException in project serverless by bluenimble.
the class AddRecordSpi method execute.
@Override
public ApiOutput execute(Api api, final ApiConsumer consumer, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
String provider = (String) request.get(CommonSpec.Provider);
String sEntity = (String) request.get(CommonSpec.Entity);
final JsonObject payload = (JsonObject) request.get(ApiRequest.Payload);
ApiSpace space;
try {
space = MgmUtils.space(consumer, api);
} catch (ApiAccessDeniedException e) {
throw new ApiServiceExecutionException(e.getMessage(), e).status(ApiResponse.FORBIDDEN);
}
DatabaseObject dbo;
try {
Database db = space.feature(Database.class, provider, request);
dbo = db.create(sEntity);
dbo.load(payload);
dbo.save();
} catch (DatabaseException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
return new JsonApiOutput((JsonObject) new JsonObject().set(ApiOutput.Defaults.Id, dbo.getId()).set(ApiOutput.Defaults.Timestamp, Lang.toUTC(dbo.getTimestamp())));
}
Aggregations