Search in sources :

Example 1 with ApiAccessDeniedException

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));
}
Also used : ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) Database(com.bluenimble.platform.db.Database) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) DatabaseException(com.bluenimble.platform.db.DatabaseException) JsonApiOutput(com.bluenimble.platform.api.impls.JsonApiOutput)

Example 2 with ApiAccessDeniedException

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);
    }
}
Also used : ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) KeyPair(com.bluenimble.platform.security.KeyPair) ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) EncryptionProviderException(com.bluenimble.platform.security.EncryptionProviderException)

Example 3 with ApiAccessDeniedException

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)));
}
Also used : ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) Api(com.bluenimble.platform.api.Api) JsonApiOutput(com.bluenimble.platform.api.impls.JsonApiOutput)

Example 4 with ApiAccessDeniedException

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));
}
Also used : ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) JsonObject(com.bluenimble.platform.json.JsonObject) JsonApiOutput(com.bluenimble.platform.api.impls.JsonApiOutput) Cache(com.bluenimble.platform.cache.Cache)

Example 5 with ApiAccessDeniedException

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())));
}
Also used : ApiAccessDeniedException(com.bluenimble.platform.api.ApiAccessDeniedException) ApiSpace(com.bluenimble.platform.api.ApiSpace) ApiServiceExecutionException(com.bluenimble.platform.api.ApiServiceExecutionException) Database(com.bluenimble.platform.db.Database) JsonObject(com.bluenimble.platform.json.JsonObject) DatabaseObject(com.bluenimble.platform.db.DatabaseObject) DatabaseException(com.bluenimble.platform.db.DatabaseException) JsonApiOutput(com.bluenimble.platform.api.impls.JsonApiOutput)

Aggregations

ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)28 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)27 ApiSpace (com.bluenimble.platform.api.ApiSpace)26 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)25 JsonObject (com.bluenimble.platform.json.JsonObject)22 Database (com.bluenimble.platform.db.Database)8 DatabaseException (com.bluenimble.platform.db.DatabaseException)8 Storage (com.bluenimble.platform.storage.Storage)6 StorageException (com.bluenimble.platform.storage.StorageException)6 StorageObject (com.bluenimble.platform.storage.StorageObject)6 DatabaseObject (com.bluenimble.platform.db.DatabaseObject)4 JsonArray (com.bluenimble.platform.json.JsonArray)4 Cache (com.bluenimble.platform.cache.Cache)3 KeyPair (com.bluenimble.platform.security.KeyPair)3 Folder (com.bluenimble.platform.storage.Folder)3 Api (com.bluenimble.platform.api.Api)2 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)2 ApiStreamSource (com.bluenimble.platform.api.ApiStreamSource)2 Role (com.bluenimble.platform.apis.mgm.Role)2 ExchangeOption (com.bluenimble.platform.db.Database.ExchangeOption)2