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() 

Source Link

Document

Create a succeeded future with a null result

Usage

From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.KeycloakOAuth2.java

License:Apache License

@Override
public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap,
        Handler<AsyncResult<Void>> resultHandler) {

    OAuth2FlowType flowType = getFlowType(config.get("flowType"));
    JsonObject params = new JsonObject();
    if (config.get("username") != null) {
        params.put("username", config.get("username"));
    }/*from   w  w w.j  a v  a  2  s .c  o m*/
    if (config.get("password") != null) {
        params.put("password", config.get("password"));
    }

    OAuth2Auth oauth2 = KeycloakAuth.create(vertx, flowType, mapToJson(config));

    oauth2.getToken(params, tokenResult -> {
        if (tokenResult.succeeded()) {
            log.debug("OAuth2 Keycloak exchange succeeded.");
            AccessToken token = tokenResult.result();
            headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token"));
            resultHandler.handle(Future.succeededFuture());
        } else {
            log.error("Access Token Error: {0}.", tokenResult.cause().getMessage());
            resultHandler.handle(Future.failedFuture(tokenResult.cause()));
        }
    });
    return this;
}

From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.KeycloakOAuth2Client.java

License:Apache License

@Override
public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap,
        AsyncResultHandler<Void> resultHandler) {

    OAuth2FlowType flowType = getFlowType(config.get("flowType"));
    JsonObject params = new JsonObject();
    if (config.get("username") != null) {
        params.put("username", config.get("username"));
    }// w  w  w.  j a  va2s  .c om
    if (config.get("password") != null) {
        params.put("password", config.get("password"));
    }

    OAuth2Auth oauth2 = OAuth2Auth.createKeycloak(vertx, flowType, mapToJson(config));

    oauth2.getToken(params, tokenResult -> {
        if (tokenResult.succeeded()) {
            log.debug("OAuth2 Keycloak exchange succeeded.");
            AccessToken token = tokenResult.result();
            headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token"));
            resultHandler.handle(Future.succeededFuture());
        } else {
            log.error("Access Token Error: {0}.", tokenResult.cause().getMessage());
            resultHandler.handle(Future.failedFuture(tokenResult.cause()));
        }
    });
    return this;
}

From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.NoneAuth.java

License:Apache License

@Override
public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap,
        Handler<AsyncResult<Void>> resultHandler) {
    resultHandler.handle(Future.succeededFuture());
    return this;
}

From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.OAuth2.java

License:Apache License

@Override
public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap,
        Handler<AsyncResult<Void>> resultHandler) {
    OAuth2ClientOptions credentials = new OAuth2ClientOptions(mapToJson(config));
    if (config.get("oauthUri") != null) {
        credentials.setSite(config.get("oauthUri"));
    }/*from   w  w w.j  av  a 2  s.  com*/
    if (config.get("clientId") != null) {
        credentials.setClientID(config.get("clientId"));
    }

    OAuth2FlowType flowType = getFlowType(config.get("flowType"));
    JsonObject params = new JsonObject();
    if (config.get("username") != null) {
        params.put("username", config.get("username"));
    }
    if (config.get("password") != null) {
        params.put("password", config.get("password"));
    }

    OAuth2Auth oauth2 = OAuth2Auth.create(vertx, flowType, credentials);

    oauth2.getToken(params, tokenResult -> {
        if (tokenResult.succeeded()) {
            log.debug("OAuth2 exchange succeeded.");
            AccessToken token = tokenResult.result();
            headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token"));
            resultHandler.handle(Future.succeededFuture());
        } else {
            log.error("Access Token Error: {0}.", tokenResult.cause().getMessage());
            resultHandler.handle(Future.failedFuture(tokenResult.cause()));
        }
    });
    return this;
}

From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.OAuth2Client.java

License:Apache License

@Override
public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap,
        AsyncResultHandler<Void> resultHandler) {
    OAuth2ClientOptions credentials = new OAuth2ClientOptions(mapToJson(config));
    if (config.get("oauthUri") != null) {
        credentials.setSite(config.get("oauthUri"));
    }/*  www  . j  ava 2 s.co m*/
    if (config.get("clientId") != null) {
        credentials.setClientID(config.get("clientId"));
    }

    OAuth2FlowType flowType = getFlowType(config.get("flowType"));
    JsonObject params = new JsonObject();
    if (config.get("username") != null) {
        params.put("username", config.get("username"));
    }
    if (config.get("password") != null) {
        params.put("password", config.get("password"));
    }

    OAuth2Auth oauth2 = OAuth2Auth.create(vertx, flowType, credentials);

    oauth2.getToken(params, tokenResult -> {
        if (tokenResult.succeeded()) {
            log.debug("OAuth2 exchange succeeded.");
            AccessToken token = tokenResult.result();
            headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token"));
            resultHandler.handle(Future.succeededFuture());
        } else {
            log.error("Access Token Error: {0}.", tokenResult.cause().getMessage());
            resultHandler.handle(Future.failedFuture(tokenResult.cause()));
        }
    });
    return this;
}

From source file:io.apiman.gateway.platforms.vertx3.api.auth.BasicAuth.java

License:Apache License

private static AuthProvider authenticateBasic(JsonObject apimanConfig) {
    return (authInfo, resultHandler) -> {
        String storedUsername = apimanConfig.getString("username");
        String storedPassword = apimanConfig.getString("password");

        if (storedUsername == null || storedPassword == null) {
            resultHandler.handle(Future.failedFuture("Credentials not set in configuration."));
            return;
        }//  w ww.  j a  va2  s .  c om

        String username = authInfo.getString("username");
        String password = StringUtils.chomp(authInfo.getString("password"));

        if (storedUsername.equals(username) && storedPassword.equals(password)) {
            resultHandler.handle(Future.succeededFuture());
        } else {
            resultHandler.handle(Future.failedFuture("No such user, or password incorrect."));
        }
    };
}

From source file:io.apiman.gateway.platforms.vertx3.services.impl.IngestorToPolicyImpl.java

License:Apache License

public void succeeded() {
    log.debug(String.format("%s indicated #succeeded", uuid));
    resultHandler.handle(Future.succeededFuture());
}

From source file:io.apiman.gateway.platforms.vertx3.services.impl.PolicyToIngestorServiceImpl.java

License:Apache License

@Override
public void end(Handler<AsyncResult<Void>> resultHandler) {
    log.debug(uuid + " ended");
    endHandler.handle((Void) null);
    resultHandler.handle(Future.succeededFuture());
}

From source file:io.engagingspaces.graphql.servicediscovery.publisher.SchemaPublisher.java

License:Open Source License

/**
 * Un-publishes the schema definition given its schema registration.
 *
 * @param registration  the schema registration
 * @param resultHandler the result handler
 *//*from w  w  w .java 2  s  .  c om*/
default void unpublish(SchemaRegistration registration, Handler<AsyncResult<Void>> resultHandler) {
    Objects.requireNonNull(resultHandler, "Un-publication result handler cannot be null");
    GraphQLService.unpublish(registration, rh -> {
        if (rh.succeeded()) {
            schemaRegistrar().unregister(registration);
            resultHandler.handle(Future.succeededFuture());
        } else {
            resultHandler.handle(Future.failedFuture(rh.cause()));
        }
    });
}

From source file:io.engagingspaces.graphql.servicediscovery.publisher.SchemaRegistrar.java

License:Open Source License

/**
 * Closes the registrar and releases all its resources.
 *
 * @param closeAction  the action to perform for closing registered schema's
 * @param closeHandler the close handler
 *//*from w  ww  . j  a  v  a2s  .co  m*/
protected void close(BiConsumer<SchemaRegistration, Handler<AsyncResult<Void>>> closeAction,
        Handler<AsyncResult<Void>> closeHandler) {
    Objects.requireNonNull(closeHandler, "Schema registrar close handler cannot be null");
    if (!registrations().isEmpty()) {
        // Execute the close action against each of the published schema's (e.g. un-publishing)
        List<Future> futures = new ArrayList<>();
        registrations().forEach(registration -> closeAction.accept(registration, rh -> futures
                .add(rh.succeeded() ? Future.succeededFuture() : Future.failedFuture(rh.cause()))));

        handleCloseCompletion(closeHandler, futures);
    } else {
        doClose(closeHandler);
    }
}