List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture(T result)
From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java
License:Open Source License
@Override public final void getCredentials(final String tenantId, final String type, final String authId, final Handler<AsyncResult<CredentialsResult>> resultHandler) { CredentialsResult credentialsResult = getCredentialsResult(tenantId, authId, type); resultHandler.handle(Future.succeededFuture(credentialsResult)); }
From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java
License:Open Source License
@Override public void addCredentials(final String tenantId, final JsonObject otherKeys, final Handler<AsyncResult<CredentialsResult>> resultHandler) { // TODO: implement CredentialsResult credentialsResult = CredentialsResult.from(HTTP_NOT_IMPLEMENTED); resultHandler.handle(Future.succeededFuture(credentialsResult)); }
From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java
License:Open Source License
@Override public void updateCredentials(final String tenantId, final JsonObject otherKeys, final Handler<AsyncResult<CredentialsResult>> resultHandler) { // TODO: implement CredentialsResult credentialsResult = CredentialsResult.from(HTTP_NOT_IMPLEMENTED); resultHandler.handle(Future.succeededFuture(credentialsResult)); }
From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java
License:Open Source License
@Override public void removeCredentials(final String tenantId, final String deviceId, final String type, final String authId, final Handler<AsyncResult<CredentialsResult>> resultHandler) { // TODO: implement CredentialsResult credentialsResult = CredentialsResult.from(HTTP_NOT_IMPLEMENTED); resultHandler.handle(Future.succeededFuture(credentialsResult)); }
From source file:org.eclipse.hono.service.EventBusService.java
License:Open Source License
private void processRequestMessage(final Message<JsonObject> msg) { if (log.isTraceEnabled()) { log.trace("received request message: {}", msg.body().encodePrettily()); }// w w w . ja v a 2 s .c o m final EventBusMessage request = EventBusMessage.fromJson(msg.body()); processRequest(request).recover(t -> { log.debug("cannot process request [operation: {}]: {}", request.getOperation(), t.getMessage()); final int status = Optional.of(t).map(cause -> { if (cause instanceof ServiceInvocationException) { return ((ServiceInvocationException) cause).getErrorCode(); } else { return null; } }).orElse(HttpURLConnection.HTTP_INTERNAL_ERROR); return Future.succeededFuture(request.getResponse(status)); }).map(response -> { if (response.getReplyToAddress() == null) { log.debug("sending response as direct reply to request [operation: {}]", request.getOperation()); msg.reply(response.toJson()); } else if (response.hasResponseProperties()) { log.debug("sending response [operation: {}, reply-to: {}]", request.getOperation(), request.getReplyToAddress()); vertx.eventBus().send(request.getReplyToAddress(), response.toJson()); } else { log.warn("discarding response lacking correlation ID or operation"); } return null; }); }
From source file:org.eclipse.hono.service.registration.BaseRegistrationService.java
License:Open Source License
/** * {@inheritDoc}//from w ww . j a v a 2s .c o m * <p> * Subclasses may override this method in order to implement a more sophisticated approach for asserting registration status, e.g. * using cached information etc. */ @Override public void assertRegistration(final String tenantId, final String deviceId, final Handler<AsyncResult<RegistrationResult>> resultHandler) { getDevice(tenantId, deviceId, getAttempt -> { if (getAttempt.failed()) { resultHandler.handle(getAttempt); } else { final RegistrationResult result = getAttempt.result(); if (result.getStatus() == HTTP_NOT_FOUND) { // device is not registered with tenant resultHandler.handle(getAttempt); } else if (isDeviceEnabled(result.getPayload().getJsonObject(RegistrationConstants.FIELD_DATA))) { // device is registered with tenant and is enabled resultHandler.handle(Future.succeededFuture( RegistrationResult.from(HTTP_OK, getAssertionPayload(tenantId, deviceId)))); } else { resultHandler.handle(Future.succeededFuture(RegistrationResult.from(HTTP_NOT_FOUND))); } } }); }
From source file:org.eclipse.hono.service.registration.BaseRegistrationService.java
License:Open Source License
/** * This default implementation simply invokes {@link RegistrationService#getDevice(String, String, Handler)} * with the parameters passed in to this method. * <p>/*from w w w . j a va 2s . c o m*/ * Subclasses should override this method in order to use a more efficient way of determining the device's status. * @param tenantId The tenantId to which the device belongs. * @param deviceId The deviceIf of the device to be checked. * @param resultHandler The callback handler to which the result is reported. */ public void isEnabled(final String tenantId, final String deviceId, Handler<AsyncResult<RegistrationResult>> resultHandler) { getDevice(tenantId, deviceId, getAttempt -> { if (getAttempt.succeeded()) { RegistrationResult result = getAttempt.result(); if (result.getStatus() == HTTP_OK) { resultHandler.handle(Future.succeededFuture(RegistrationResult.from(result.getStatus(), result.getPayload().getJsonObject(RegistrationConstants.FIELD_DATA)))); } else { resultHandler.handle(getAttempt); } } else { resultHandler.handle(getAttempt); } }); }
From source file:org.eclipse.hono.service.registration.impl.FileBasedRegistrationService.java
License:Open Source License
@Override public void findDevice(final String tenantId, final String key, final String value, final Handler<AsyncResult<RegistrationResult>> resultHandler) { resultHandler.handle(Future.succeededFuture(findDevice(tenantId, key, value))); }
From source file:org.eclipse.hono.service.tenant.TenantAmqpEndpoint.java
License:Open Source License
/** * Checks if the client is authorized to invoke an operation. * <p>/*from w w w . j a va2s . c o m*/ * If the request does not include a <em>tenant_id</em> application property * then the request is authorized by default. This behavior allows clients to * invoke operations that do not require a tenant ID as a parameter. In such * cases the {@link #filterResponse(HonoUser, EventBusMessage)} method is used * to verify that the response only contains data that the client is authorized * to retrieve. * <p> * If the request does contain a tenant ID parameter in its application properties * then this tenant ID is used for the authorization check together with the * endpoint and operation name. * * @param clientPrincipal The client. * @param resource The resource the operation belongs to. * @param request The message for which the authorization shall be checked. * @return The outcome of the check. * @throws NullPointerException if any of the parameters is {@code null}. */ @Override protected Future<Boolean> isAuthorized(final HonoUser clientPrincipal, final ResourceIdentifier resource, final Message request) { Objects.requireNonNull(request); final String tenantId = MessageHelper.getTenantId(request); if (tenantId == null) { // delegate authorization check to filterResource operation return Future.succeededFuture(Boolean.TRUE); } else { final ResourceIdentifier specificTenantAddress = ResourceIdentifier .fromPath(new String[] { resource.getEndpoint(), tenantId }); return getAuthorizationService().isAuthorized(clientPrincipal, specificTenantAddress, request.getSubject()); } }
From source file:org.eclipse.hono.service.tenant.TenantAmqpEndpoint.java
License:Open Source License
/** * Verifies that a response only contains tenant information that the * client is authorized to retrieve./* w ww .j av a 2 s . co m*/ * <p> * If the response does not contain a tenant ID nor a payload, then the * returned future will succeed with the response <em>as-is</em>. * Otherwise the tenant ID is used together with the endpoint and operation * name to check the client's authority to retrieve the data. If the client * is authorized, the returned future will succeed with the response as-is, * otherwise the future will fail with a {@link ClientErrorException} containing a * <em>403 Forbidden</em> status. */ @Override protected Future<EventBusMessage> filterResponse(final HonoUser clientPrincipal, final EventBusMessage response) { Objects.requireNonNull(clientPrincipal); Objects.requireNonNull(response); if (response.getTenant() == null || response.getJsonPayload() == null) { return Future.succeededFuture(response); } else { // verify that payload contains tenant that the client is authorized for final ResourceIdentifier resourceId = ResourceIdentifier.from(TenantConstants.TENANT_ENDPOINT, response.getTenant(), null); return getAuthorizationService().isAuthorized(clientPrincipal, resourceId, response.getOperation()) .map(isAuthorized -> { if (isAuthorized) { return response; } else { throw new ClientErrorException(HttpURLConnection.HTTP_FORBIDDEN); } }); } }