use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.
the class ClaimsBasedAuthorizationService method isAuthorized.
@Override
public Future<Boolean> isAuthorized(final HonoUser user, final ResourceIdentifier resource, final String operation) {
Objects.requireNonNull(user);
Objects.requireNonNull(resource);
Objects.requireNonNull(operation);
if (user.isExpired()) {
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN, "user information expired"));
} else {
return Future.succeededFuture(user.getAuthorities().isAuthorized(resource, operation));
}
}
use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.
the class BaseCredentialsService method processRemoveRequest.
private Future<EventBusMessage> processRemoveRequest(final EventBusMessage request) {
final String tenantId = request.getTenant();
final JsonObject payload = request.getJsonPayload();
if (tenantId == null || payload == null) {
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else {
final String type = getTypesafeValueForField(payload, CredentialsConstants.FIELD_TYPE);
final String authId = getTypesafeValueForField(payload, CredentialsConstants.FIELD_AUTH_ID);
final String deviceId = getTypesafeValueForField(payload, CredentialsConstants.FIELD_PAYLOAD_DEVICE_ID);
if (type == null) {
log.debug("remove credentials request does not contain mandatory type parameter");
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else if (!type.equals(CredentialsConstants.SPECIFIER_WILDCARD) && authId != null) {
// delete a single credentials instance
log.debug("removing specific credentials [tenant: {}, type: {}, auth-id: {}]", tenantId, type, authId);
final Future<CredentialsResult<JsonObject>> result = Future.future();
remove(tenantId, type, authId, result.completer());
return result.map(res -> {
return request.getResponse(res.getStatus()).setCacheDirective(res.getCacheDirective());
});
} else if (deviceId != null && type.equals(CredentialsConstants.SPECIFIER_WILDCARD)) {
// delete all credentials for device
log.debug("removing all credentials for device [tenant: {}, device-id: {}]", tenantId, deviceId);
final Future<CredentialsResult<JsonObject>> result = Future.future();
removeAll(tenantId, deviceId, result.completer());
return result.map(res -> {
return request.getResponse(res.getStatus()).setDeviceId(deviceId).setCacheDirective(res.getCacheDirective());
});
} else {
log.debug("remove credentials request contains invalid search criteria [type: {}, device-id: {}, auth-id: {}]", type, deviceId, authId);
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
}
}
}
use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.
the class BaseCredentialsService method processUpdateRequest.
private Future<EventBusMessage> processUpdateRequest(final EventBusMessage request) {
final String tenantId = request.getTenant();
final CredentialsObject payload = Optional.ofNullable(request.getJsonPayload()).map(json -> json.mapTo(CredentialsObject.class)).orElse(null);
if (tenantId == null || payload == null) {
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else if (payload.isValid()) {
final Future<CredentialsResult<JsonObject>> result = Future.future();
update(tenantId, JsonObject.mapFrom(payload), result.completer());
return result.map(res -> {
return request.getResponse(res.getStatus()).setDeviceId(payload.getDeviceId()).setCacheDirective(res.getCacheDirective());
});
} else {
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
}
}
use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.
the class BaseRegistrationService method processGetRequest.
private Future<EventBusMessage> processGetRequest(final EventBusMessage request) {
final String tenantId = request.getTenant();
final String deviceId = request.getDeviceId();
if (tenantId == null || deviceId == null) {
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else {
log.debug("retrieving device [{}] of tenant [{}]", deviceId, tenantId);
final Future<RegistrationResult> result = Future.future();
getDevice(tenantId, deviceId, result.completer());
return result.map(res -> {
return request.getResponse(res.getStatus()).setDeviceId(deviceId).setJsonPayload(res.getPayload()).setCacheDirective(res.getCacheDirective());
});
}
}
use of org.eclipse.hono.client.ClientErrorException in project hono by eclipse.
the class BaseRegistrationService method processAssertRequest.
private Future<EventBusMessage> processAssertRequest(final EventBusMessage request) {
final String tenantId = request.getTenant();
final String deviceId = request.getDeviceId();
final String gatewayId = request.getGatewayId();
if (tenantId == null || deviceId == null) {
return Future.failedFuture(new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST));
} else if (gatewayId == null) {
log.debug("asserting registration of device [{}] with tenant [{}]", deviceId, tenantId);
final Future<RegistrationResult> result = Future.future();
assertRegistration(tenantId, deviceId, result.completer());
return result.map(res -> {
return request.getResponse(res.getStatus()).setDeviceId(deviceId).setJsonPayload(res.getPayload()).setCacheDirective(res.getCacheDirective());
});
} else {
log.debug("asserting registration of device [{}] with tenant [{}] for gateway [{}]", deviceId, tenantId, gatewayId);
final Future<RegistrationResult> result = Future.future();
assertRegistration(tenantId, deviceId, gatewayId, result.completer());
return result.map(res -> {
return request.getResponse(res.getStatus()).setDeviceId(deviceId).setJsonPayload(res.getPayload()).setCacheDirective(res.getCacheDirective());
});
}
}
Aggregations