Example usage for io.vertx.core Future succeededFuture

List of usage examples for io.vertx.core Future succeededFuture

Introduction

In this page you can find the example usage for io.vertx.core Future succeededFuture.

Prototype

static <T> Future<T> succeededFuture(T result) 

Source Link

Document

Created a succeeded future with the specified result.

Usage

From source file:io.flowly.auth.ExtJwtUser.java

License:Open Source License

@Override
public void doIsPermitted(String permission, Handler<AsyncResult<Boolean>> handler) {
    if (principal().getBoolean(ObjectKeys.GURU)) {
        handler.handle(Future.succeededFuture(true));
        return;//from   ww  w.j  a v  a  2  s  . c  om
    } else if (permissions != null) {
        Permission permissionToTest = new Permission(permission);

        for (Object jwtPermission : permissions) {
            if (permissionToTest.isSubSet((JsonObject) jwtPermission)) {
                handler.handle(Future.succeededFuture(true));
                return;
            }
        }
    }

    logger.debug("User has no permission [" + permission + "]");
    handler.handle(Future.succeededFuture(false));
}

From source file:io.github.bckfnn.ftp.FtpClient.java

License:Apache License

/**
 * Perform a list of the file or directories specifed by path. 
 * @param path the path to list./*  ww  w .  j a  va2 s  .  c  o m*/
 * @param handler callback handler that is called when the list is completed.
 */
public void list(String path, Handler<AsyncResult<Buffer>> handler) {
    Buffer data = Buffer.buffer();

    pasv(handler, datasocket -> {
        datasocket.handler(b -> {
            data.appendBuffer(b);
        });
    }, $ -> {
        write("LIST" + (path != null ? " " + path : ""), resp(handler, when("125", "150", list -> {
            handle(resp(handler, when("226", "250", listdone -> {
                handler.handle(Future.succeededFuture(data));
            })));
        })));
    });
}

From source file:io.github.bckfnn.ftp.FtpClient.java

License:Apache License

private void output(Buffer buf) {
    if (response == null) {
        response = new Response(next);
    }/*from   w w w .  j a  v  a 2  s . co m*/
    Pattern p = Pattern.compile("(\\d\\d\\d)([ -])(.*)");
    Matcher m = p.matcher(buf.toString().trim());

    if (m.matches()) {
        String code = m.group(1);
        log.debug(code + " " + m.group(2) + " " + m.group(3));
        if (code.equals("421")) {
            socket.close();
            endHandler.handle(null);
            return;
        }
        if (response == null) {
            fail("unexpected response " + buf);
            return;
        }
        response.setCode(m.group(1));
        response.addMessage(m.group(3));

        if (m.group(2).equals(" ")) {
            Response response = this.response;
            this.response = null;
            log.trace("handling {}", response);
            next.handle(Future.succeededFuture(response));
        } else if (m.group(2).equals("-")) {
            log.info("waiting for more");
        }
    }
}

From source file:io.github.bckfnn.ftp.Response.java

License:Apache License

public void succes() {
    handler.handle(Future.succeededFuture(this));
}

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)));
                }/*from ww  w .j  a  va 2  s . co  m*/
            })).exceptionHandler(error -> resultHandler.handle(Future.failedFuture(error.getMessage()))).end();
}

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 w w  .  j  av  a2s . c  o m
    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;
    }//from   w w w . ja va2  s  .co  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;
}

From source file:io.github.pflima92.plyshare.microservice.utility.NotificationServiceVertxEBProxy.java

License:Apache License

public NotificationService createNotification(Handler<AsyncResult<JsonObject>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from  w w w .  j  a  va2s.  c om*/
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "createNotification");
    _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.gravitee.am.gateway.handler.vertx.auth.handler.impl.ClientCredentialsAuthHandlerImpl.java

License:Apache License

protected final void parseAuthorization(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) {
    String clientId = context.request().getParam(OAuth2Constants.CLIENT_ID);
    String clientSecret = context.request().getParam(OAuth2Constants.CLIENT_SECRET);

    if (clientId != null && clientSecret != null) {
        JsonObject clientCredentials = new JsonObject().put(USERNAME_FIELD, clientId).put(PASSWORD_FIELD,
                clientSecret);/*w  w  w.  j  av a  2 s .co m*/
        handler.handle(Future.succeededFuture(clientCredentials));
    } else {
        handler.handle(Future.failedFuture(UNAUTHORIZED));
    }
}

From source file:io.gravitee.am.gateway.handler.vertx.auth.handler.impl.OAuth2ClientAuthHandlerImpl.java

License:Apache License

protected final void parseAuthorization(RoutingContext context, Handler<AsyncResult<JsonObject>> handler) {
    try {//from  w w w. ja  v  a2  s . com
        final String providerId = context.request().getParam(PROVIDER_PARAMETER);
        final String clientId = getQueryParams(
                context.session().get(RedirectAuthHandler.DEFAULT_RETURN_URL_PARAM))
                        .get(OAuth2Constants.CLIENT_ID);

        if (providerId != null) {
            identityProviderManager.get(providerId).map(authenticationProvider -> {
                if (!(authenticationProvider instanceof OAuth2AuthenticationProvider)) {
                    throw new AuthenticationServiceException("OAuth2 Provider " + providerId + "is not social");
                }
                return (OAuth2AuthenticationProvider) authenticationProvider;
            }).subscribe(authenticationProvider -> {
                try {
                    String password = context.request()
                            .getParam(authenticationProvider.configuration().getCodeParameter());
                    JsonObject clientCredentials = new JsonObject().put(USERNAME_PARAMETER, OAUTH2_IDENTIFIER)
                            .put(PASSWORD_PARAMETER, password).put(PROVIDER_PARAMETER, providerId)
                            .put(OAuth2Constants.CLIENT_ID, clientId)
                            .put(OAuth2Constants.REDIRECT_URI, buildRedirectUri(context.request()));
                    handler.handle(Future.succeededFuture(clientCredentials));
                } catch (Exception e) {
                    handler.handle(Future.failedFuture(e));
                }
            }, error -> handler.handle(Future.failedFuture(error)));
        } else {
            handler.handle(Future.failedFuture(UNAUTHORIZED));
        }
    } catch (Exception e) {
        logger.error("Failed to parseAuthorization for OAuth 2.0 provider", e);
        handler.handle(Future.failedFuture(UNAUTHORIZED));
    }
}