Search in sources :

Example 1 with Type

use of com.bluenimble.platform.api.security.ApiConsumer.Type in project serverless by bluenimble.

the class MgmApiSpi method findConsumer.

@Override
public void findConsumer(Api api, ApiService service, ApiRequest request, ApiConsumer consumer) throws ApiAuthenticationException {
    Type type = consumer.type();
    if ("container".equals(request.getChannel())) {
        consumer.override((ApiConsumer) request.get(ApiRequest.Consumer));
        return;
    }
    if (!this.isSecure(service)) {
        return;
    }
    if (!type.equals(Type.Signature)) {
        throw new ApiAuthenticationException("unsupported authentication mechanism");
    }
    String accessKey = (String) consumer.get(ApiConsumer.Fields.AccessKey);
    final JsonObject oConsumer = Json.getObject(consumers, accessKey);
    if (oConsumer == null || oConsumer.isEmpty()) {
        throw new ApiAuthenticationException("accessKey not found");
    }
    Iterator<String> keys = oConsumer.keys();
    if (keys == null) {
        return;
    }
    while (keys.hasNext()) {
        String key = keys.next();
        consumer.set(key, oConsumer.get(key));
    }
}
Also used : Type(com.bluenimble.platform.api.security.ApiConsumer.Type) ApiAuthenticationException(com.bluenimble.platform.api.security.ApiAuthenticationException) JsonObject(com.bluenimble.platform.json.JsonObject)

Aggregations

ApiAuthenticationException (com.bluenimble.platform.api.security.ApiAuthenticationException)1 Type (com.bluenimble.platform.api.security.ApiConsumer.Type)1 JsonObject (com.bluenimble.platform.json.JsonObject)1