List of usage examples for io.vertx.core.eventbus Message reply
default void reply(@Nullable Object message)
From source file:org.eclipse.hono.authorization.impl.BaseAuthorizationService.java
License:Open Source License
private void processMessage(final Message<JsonObject> message) { final JsonObject body = message.body(); final String authSubject = body.getString(AUTH_SUBJECT_FIELD); final Permission permission = Permission.valueOf(body.getString(PERMISSION_FIELD)); final ResourceIdentifier resource = ResourceIdentifier.fromString(body.getString(RESOURCE_FIELD)); boolean hasPermission = hasPermission(authSubject, resource, permission); message.reply(hasPermission ? ALLOWED : DENIED); LOG.debug("subject [{}] is {}allowed to {} on resource [{}]", authSubject, hasPermission ? "" : "not ", permission, resource);// w w w . j a va 2s. co m }
From source file:org.eclipse.hono.service.auth.BaseAuthenticationService.java
License:Open Source License
private void processMessage(final Message<JsonObject> message) { final JsonObject body = message.body(); authenticate(body, validation -> { if (validation.succeeded()) { message.reply(AuthenticationConstants.getAuthenticationReply(validation.result().getToken())); } else {//w w w . ja v a 2 s. c o m message.fail(ERROR_CODE_AUTHENTICATION_FAILED, validation.cause().getMessage()); } }); }
From source file:org.eclipse.hono.service.auth.BaseAuthorizationService.java
License:Open Source License
private void processMessage(final Message<JsonObject> message) { final JsonObject body = message.body(); final String authSubject = body.getString(AuthorizationConstants.AUTH_SUBJECT_FIELD); final HonoUser user = new HonoUser() { @Override//from w w w . j a v a 2 s . c om public String getName() { return authSubject; } @Override public Authorities getAuthorities() { return null; } @Override public String getToken() { return null; } @Override public boolean isExpired() { return false; } }; final Activity permission = Activity.valueOf(body.getString(AuthorizationConstants.PERMISSION_FIELD)); final ResourceIdentifier resource = ResourceIdentifier .fromString(body.getString(AuthorizationConstants.RESOURCE_FIELD)); isAuthorized(user, resource, permission).setHandler(authAttempt -> { boolean hasPermission = false; if (authAttempt.succeeded()) { hasPermission = authAttempt.result(); } LOG.debug("subject [{}] is {}allowed to {} on resource [{}]", authSubject, hasPermission ? "" : "not ", permission, resource); message.reply(hasPermission ? AuthorizationConstants.ALLOWED : AuthorizationConstants.DENIED); }); }
From source file:org.eclipse.hono.service.credentials.BaseCredentialsService.java
License:Open Source License
/** * Sends a response to a credentials request over the Vertx event bus. * //from w w w. j av a 2s. c o m * @param request The message to respond to. * @param result The credentials result that should be conveyed in the response. */ protected final void reply(final Message<JsonObject> request, final CredentialsResult<JsonObject> result) { final JsonObject body = request.body(); final String tenantId = body.getString(RequestResponseApiConstants.FIELD_TENANT_ID); final String deviceId = body.getString(RequestResponseApiConstants.FIELD_DEVICE_ID); request.reply(CredentialsConstants.getServiceReplyAsJson(tenantId, deviceId, result)); }
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()); }/* ww w.ja va 2 s .co 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
/** * Sends a response to a registration request over the Vertx event bus. * //from w w w . j av a 2 s . c o m * @param request The message to respond to. * @param result The registration result that should be conveyed in the response. */ protected final void reply(final Message<JsonObject> request, final RegistrationResult result) { final JsonObject body = request.body(); final String tenantId = body.getString(RequestResponseApiConstants.FIELD_TENANT_ID); final String deviceId = body.getString(RequestResponseApiConstants.FIELD_DEVICE_ID); request.reply(RegistrationConstants.getServiceReplyAsJson(tenantId, deviceId, result)); }
From source file:org.entcore.auth.controllers.AuthController.java
License:Open Source License
@BusAddress("wse.oauth") public void oauthResourceServer(final Message<JsonObject> message) { if (message.body() == null) { message.reply(new JsonObject()); return;//from ww w . j av a 2 s.c o m } validToken(message); }
From source file:org.entcore.auth.controllers.AuthController.java
License:Open Source License
private void validToken(final Message<JsonObject> message) { protectedResource.handleRequest(new JsonRequestAdapter(message.body()), new jp.eisbahn.oauth2.server.async.Handler<Try<OAuthError, ProtectedResource.Response>>() { @Override/*from ww w . j av a 2s . c om*/ public void handle(Try<OAuthError, ProtectedResource.Response> resp) { ProtectedResource.Response response; try { response = resp.get(); JsonObject r = new JsonObject().put("status", "ok") .put("client_id", response.getClientId()) .put("remote_user", response.getRemoteUser()).put("scope", response.getScope()); message.reply(r); } catch (OAuthError e) { message.reply(new JsonObject().put("error", e.getType())); } } }); }
From source file:org.entcore.cas.controllers.ConfigurationController.java
License:Open Source License
@BusAddress(value = "cas.configuration", local = false) public void cas(Message<JsonObject> message) { switch (message.body().getString("action", "")) { case "list-services": message.reply(new JsonObject().put("status", "ok").put("result", services.getInfos(message.body().getString("accept-language", "fr")))); break;//from w w w . j av a 2s .co m case "add-patterns": String service = message.body().getString("service"); JsonArray patterns = message.body().getJsonArray("patterns"); message.reply(new JsonObject().put("status", services.addPatterns(service, Arrays.copyOf(patterns.getList().toArray(), patterns.size(), String[].class)) ? "ok" : "error")); break; default: message.reply(new JsonObject().put("status", "error").put("message", "invalid.action")); } }
From source file:org.entcore.cas.controllers.CredentialController.java
License:Open Source License
@BusAddress("cas") public void busEvents(Message<JsonObject> message) { String action = message.body().getString("action", ""); switch (action) { case "logout": credential.logout(message.body().getString("userId")); break;// w w w .ja va 2s . c om default: message.reply(new JsonObject().put("status", "error").put("message", "invalid.action")); } }