List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:io.flowly.auth.ExtJwtAuthProvider.java
License:Open Source License
@Override public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) { try {/*from w w w .ja v a2 s .co m*/ final JsonObject payload = jwt.decode(authInfo.getString("jwt")); final JsonObject options = authInfo.getJsonObject("options", EMPTY_OBJECT); // All dates in JWT are of type NumericDate // a NumericDate is: numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until // the specified UTC date/time, ignoring leap seconds final long now = System.currentTimeMillis() / 1000; if (payload.containsKey("exp") && !options.getBoolean("ignoreExpiration", false)) { if (now >= payload.getLong("exp")) { resultHandler.handle(Future.failedFuture("Expired JWT token: exp <= now")); return; } } if (payload.containsKey("iat")) { Long iat = payload.getLong("iat"); // issue at must be in the past if (iat > now) { resultHandler.handle(Future.failedFuture("Invalid JWT token: iat > now")); return; } } if (payload.containsKey("nbf")) { Long nbf = payload.getLong("nbf"); // not before must be after now if (nbf > now) { resultHandler.handle(Future.failedFuture("Invalid JWT token: nbf > now")); return; } } if (options.containsKey("audience")) { JsonArray audiences = options.getJsonArray("audience", EMPTY_ARRAY); JsonArray target = payload.getJsonArray("aud", EMPTY_ARRAY); if (Collections.disjoint(audiences.getList(), target.getList())) { resultHandler .handle(Future.failedFuture("Invalid JWT audience. expected: " + audiences.encode())); return; } } if (options.containsKey("issuer")) { if (!options.getString("issuer").equals(payload.getString("iss"))) { resultHandler.handle(Future.failedFuture("Invalid JWT issuer")); return; } } resultHandler.handle(Future.succeededFuture(new ExtJwtUser(payload, permissionsClaimKey))); } catch (RuntimeException e) { resultHandler.handle(Future.failedFuture(e)); } }
From source file:io.github.bckfnn.actioner.Main.java
License:Apache License
protected void loadPrincipal(String loginId, String password, Handler<AsyncResult<JsonObject>> handler) { handler.handle(Future.failedFuture("loadPrincipal not implemented")); }
From source file:io.github.bckfnn.ftp.FtpClient.java
License:Apache License
/** * Connect to the server./*from ww w. j a v a 2 s. c o m*/ * @param handler callback handler that is called when the connection is completed. */ public void connect(Handler<AsyncResult<Void>> handler) { next = resp(handler, when("220", c -> { handler.handle(Future.succeededFuture()); })); client = vertx.createNetClient(); client.connect(port, host, res -> { socket = res.result(); if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else { RecordParser parser = RecordParser.newDelimited("\n", this::output); socket.handler(parser); } }); }
From source file:io.github.bckfnn.ftp.FtpClient.java
License:Apache License
public static <R> Handler<AsyncResult<Response>> resp(Handler<AsyncResult<R>> handler, When... whens) { return ar -> { if (ar.succeeded()) { Response r = ar.result(); for (When w : whens) { if (w.match(r)) { return; }/*w ww . j ava2s .c o m*/ } handler.handle(Future.failedFuture(r.code + " " + r.messages.get(0))); } else { handler.handle(Future.failedFuture(ar.cause())); } }; }
From source file:io.github.bckfnn.ftp.Response.java
License:Apache License
public void fail(String msg) { handler.handle(Future.failedFuture(new RuntimeException(msg))); }
From source file:io.github.bckfnn.ftp.Response.java
License:Apache License
public void fail() { handler.handle(Future.failedFuture(new RuntimeException(code + " " + messages.get(0)))); }
From source file:io.github.cdelmas.spike.vertx.infrastructure.auth.FacebookOauthTokenVerifier.java
License:Apache License
@Override public void authenticate(JsonObject credentials, Handler<AsyncResult<User>> resultHandler) { String token = credentials.getString("token"); httpClient.getAbs("https://graph.facebook.com:443/v2.4/me?access_token=" + token) .handler(response -> response.bodyHandler(buffer -> { JsonObject json = new JsonObject(buffer.toString()); if (response.statusCode() != 200) { String message = json.getJsonObject("error").getString("message"); resultHandler.handle(Future.failedFuture(message)); } else { resultHandler.handle(Future.succeededFuture( new MyUser(Long.parseLong(json.getString("id")), json.getString("name"), token))); }/*w ww .j a v a 2 s . c o m*/ })).exceptionHandler(error -> resultHandler.handle(Future.failedFuture(error.getMessage()))).end(); }
From source file:io.github.cdelmas.spike.vertx.infrastructure.auth.MyUser.java
License:Apache License
@Override protected void doIsPermitted(String permission, Handler<AsyncResult<Boolean>> resultHandler) { resultHandler.handle(Future.failedFuture("Not implemented yet")); }
From source file:io.github.pflima92.plyshare.common.configuration.ConfigurationProviderVertxEBProxy.java
License:Apache License
public ConfigurationProvider getConfiguration(String name, Handler<AsyncResult<JsonObject>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w ww .j av a 2 s . com JsonObject _json = new JsonObject(); _json.put("name", name); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "getConfiguration"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); return this; }
From source file:io.github.pflima92.plyshare.microservice.utility.MailServiceVertxEBProxy.java
License:Apache License
public MailService send(MailMessage message, Handler<AsyncResult<MailResult>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/* w w w . j ava 2 s .c o m*/ JsonObject _json = new JsonObject(); _json.put("message", message == null ? null : message.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "send"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future .succeededFuture(res.result().body() == null ? null : new MailResult(res.result().body()))); } }); return this; }