Example usage for io.vertx.core.http HttpServerOptions setPemKeyCertOptions

List of usage examples for io.vertx.core.http HttpServerOptions setPemKeyCertOptions

Introduction

In this page you can find the example usage for io.vertx.core.http HttpServerOptions setPemKeyCertOptions.

Prototype

@Override
    public HttpServerOptions setPemKeyCertOptions(PemKeyCertOptions options) 

Source Link

Usage

From source file:de.braintags.netrelay.NetRelay.java

License:Open Source License

private void importCertificate(HttpServerOptions httpOpts) {
    String certPath = settings.getCertificatePath();
    String password = settings.getCertificatePassword();

    if (certPath.matches("^.*\\.(pem|PEM)$")) {
        // Use a PEM key/cert pair
        if (settings.getCertificateKeyPath() == null) {
            throw new IllegalArgumentException("The certificateKeyPath is not set for pem certificate");
        }/*from  w w w. j  a  v  a 2  s .c o m*/
        httpOpts.setPemKeyCertOptions(
                new PemKeyCertOptions().setCertPath(certPath).setKeyPath(settings.getCertificateKeyPath()));
        httpOpts.setSsl(true);
    } else {
        throw new IllegalArgumentException("Please specify the certificate as PEM file in the format pkcs8");
    }

}

From source file:org.workspace7.k8s.auth.proxy.K8sWebProxyVerticle.java

License:Apache License

/**
 * @param keyCloakOAuth2/*from   w  w w . jav  a  2 s  .c o m*/
 * @param next
 */
protected void startWebApp(AsyncResult<OAuth2Auth> keyCloakOAuth2, Handler<AsyncResult<HttpServer>> next) {

    Router router = Router.router(vertx);

    final String proxyUri = "https://" + config().getString("k8s_proxy_host") + ":"
            + config().getInteger("k8s_proxy_port");

    if (keyCloakOAuth2.succeeded()) {

        OAuth2AuthHandler keycloakOAuthHandler = OAuth2AuthHandler.create(keyCloakOAuth2.result(), proxyUri);
        keycloakOAuthHandler.setupCallback(router.get("/callback"));

        //router.route().handler(BodyHandler.create());

        router.route("/api/*").handler(keycloakOAuthHandler);
        router.route("/ui/*").handler(keycloakOAuthHandler);

        //Handle UI Requests
        router.route("/ui/").handler(this::handleUIPath);

        //Handle API Requests
        router.route("/api/*").handler(this::handleApiPath);

        router.get("/").handler(ctx -> ctx.reroute("/ui/"));

        //These options are for setting up the server (k8s-proxy)
        HttpServerOptions httpServerOptions = new HttpServerOptions().setSsl(true);

        //Server HTTPS
        httpServerOptions.setPemKeyCertOptions(proxyPemOptions());
        httpServerOptions.setTrustStoreOptions(proxyTrustOptions());

        vertx.createHttpServer(httpServerOptions).requestHandler(router::accept)
                .listen(config().getInteger("k8s_proxy_port"), config().getString("k8s_proxy_host"), next);
    } else {
        _logger.error("Unable to start proxy : {}", keyCloakOAuth2.cause());
        next.handle(Future.failedFuture(keyCloakOAuth2.cause()));
    }
}