List of usage examples for io.vertx.core.json JsonObject put
public JsonObject put(String key, Object value)
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 ww w . j av 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")); }//from w ww.ja va 2 s.co m 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.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 ww w . j a v a 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.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")); }/*from ww w .j a va 2s.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.platforms.vertx3.common.config.InheritingHttpServerOptionsConverter.java
License:Apache License
public static void toJson(InheritingHttpServerOptions obj, JsonObject json) { json.put("acceptBacklog", obj.getAcceptBacklog()); json.put("acceptUnmaskedFrames", obj.isAcceptUnmaskedFrames()); if (obj.getAlpnVersions() != null) { JsonArray array = new JsonArray(); obj.getAlpnVersions().forEach(item -> array.add(item.name())); json.put("alpnVersions", array); }/*w w w. j av a 2s .com*/ if (obj.getClientAuth() != null) { json.put("clientAuth", obj.getClientAuth().name()); } json.put("clientAuthRequired", obj.isClientAuthRequired()); json.put("compressionLevel", obj.getCompressionLevel()); json.put("compressionSupported", obj.isCompressionSupported()); if (obj.getCrlPaths() != null) { JsonArray array = new JsonArray(); obj.getCrlPaths().forEach(item -> array.add(item)); json.put("crlPaths", array); } if (obj.getCrlValues() != null) { JsonArray array = new JsonArray(); obj.getCrlValues().forEach(item -> array.add(item.getBytes())); json.put("crlValues", array); } json.put("decompressionSupported", obj.isDecompressionSupported()); if (obj.getEnabledCipherSuites() != null) { JsonArray array = new JsonArray(); obj.getEnabledCipherSuites().forEach(item -> array.add(item)); json.put("enabledCipherSuites", array); } if (obj.getEnabledSecureTransportProtocols() != null) { JsonArray array = new JsonArray(); obj.getEnabledSecureTransportProtocols().forEach(item -> array.add(item)); json.put("enabledSecureTransportProtocols", array); } json.put("handle100ContinueAutomatically", obj.isHandle100ContinueAutomatically()); if (obj.getHost() != null) { json.put("host", obj.getHost()); } json.put("http2ConnectionWindowSize", obj.getHttp2ConnectionWindowSize()); json.put("idleTimeout", obj.getIdleTimeout()); if (obj.getInitialSettings() != null) { json.put("initialSettings", obj.getInitialSettings().toJson()); } if (obj.getJdkSslEngineOptions() != null) { json.put("jdkSslEngineOptions", obj.getJdkSslEngineOptions().toJson()); } if (obj.getKeyStoreOptions() != null) { json.put("keyStoreOptions", obj.getKeyStoreOptions().toJson()); } json.put("logActivity", obj.getLogActivity()); json.put("maxChunkSize", obj.getMaxChunkSize()); json.put("maxHeaderSize", obj.getMaxHeaderSize()); json.put("maxInitialLineLength", obj.getMaxInitialLineLength()); json.put("maxWebsocketFrameSize", obj.getMaxWebsocketFrameSize()); json.put("maxWebsocketMessageSize", obj.getMaxWebsocketMessageSize()); if (obj.getOpenSslEngineOptions() != null) { json.put("openSslEngineOptions", obj.getOpenSslEngineOptions().toJson()); } if (obj.getPemKeyCertOptions() != null) { json.put("pemKeyCertOptions", obj.getPemKeyCertOptions().toJson()); } if (obj.getPemTrustOptions() != null) { json.put("pemTrustOptions", obj.getPemTrustOptions().toJson()); } if (obj.getPfxKeyCertOptions() != null) { json.put("pfxKeyCertOptions", obj.getPfxKeyCertOptions().toJson()); } if (obj.getPfxTrustOptions() != null) { json.put("pfxTrustOptions", obj.getPfxTrustOptions().toJson()); } json.put("port", obj.getPort()); json.put("receiveBufferSize", obj.getReceiveBufferSize()); json.put("reuseAddress", obj.isReuseAddress()); json.put("sendBufferSize", obj.getSendBufferSize()); json.put("soLinger", obj.getSoLinger()); json.put("ssl", obj.isSsl()); json.put("tcpKeepAlive", obj.isTcpKeepAlive()); json.put("tcpNoDelay", obj.isTcpNoDelay()); json.put("trafficClass", obj.getTrafficClass()); if (obj.getTrustStoreOptions() != null) { json.put("trustStoreOptions", obj.getTrustStoreOptions().toJson()); } json.put("useAlpn", obj.isUseAlpn()); json.put("usePooledBuffers", obj.isUsePooledBuffers()); if (obj.getWebsocketSubProtocols() != null) { json.put("websocketSubProtocols", obj.getWebsocketSubProtocols()); } }
From source file:io.apiman.gateway.platforms.vertx3.components.jdbc.VertxJdbcClientImpl.java
License:Apache License
/** * Translate our abstracted {@link JdbcOptionsBean} into a Vert.x-specific config. * * We are assuming that the user is using HikariCP. *//* w w w.ja v a 2s .co m*/ @SuppressWarnings("nls") protected JsonObject parseConfig(JdbcOptionsBean config) { JsonObject jsonConfig = new JsonObject(); nullSafePut(jsonConfig, "provider_class", HikariCPDataSourceProvider.class.getCanonicalName()); // Vert.x thing nullSafePut(jsonConfig, "jdbcUrl", config.getJdbcUrl()); nullSafePut(jsonConfig, "username", config.getUsername()); nullSafePut(jsonConfig, "password", config.getPassword()); nullSafePut(jsonConfig, "autoCommit", config.isAutoCommit()); nullSafePut(jsonConfig, "connectionTimeout", config.getConnectionTimeout()); nullSafePut(jsonConfig, "idleTimeout", config.getIdleTimeout()); nullSafePut(jsonConfig, "maxLifetime", config.getMaxLifetime()); nullSafePut(jsonConfig, "minimumIdle", config.getMinimumIdle()); nullSafePut(jsonConfig, "maximumPoolSize", config.getMaximumPoolSize()); nullSafePut(jsonConfig, "poolName", config.getPoolName()); JsonObject dsProperties = new JsonObject(); for (Entry<String, Object> entry : config.getDsProperties().entrySet()) { dsProperties.put(entry.getKey(), entry.getValue()); } jsonConfig.put("properties", dsProperties); return jsonConfig; }
From source file:io.apiman.gateway.platforms.vertx3.components.jdbc.VertxJdbcClientImpl.java
License:Apache License
private <T> void nullSafePut(JsonObject jsonObject, String key, T value) { if (value == null) return;/* w w w .j ava 2s .co m*/ jsonObject.put(key, value); }
From source file:io.apiman.gateway.platforms.vertx3.io.VertxApiRequestConverter.java
License:Apache License
public static void toJson(VertxApiRequest obj, JsonObject json) { if (obj.getApiKey() != null) { json.put("apiKey", obj.getApiKey()); }/* www. ja va2 s.co m*/ if (obj.getDestination() != null) { json.put("destination", obj.getDestination()); } if (obj.getHeaders() != null) { JsonObject map = new JsonObject(); obj.getHeaders().forEach((pair) -> map.put(pair.getKey(), pair.getValue())); json.put("headers", map); } if (obj.getQueryParams() != null) { JsonObject map = new JsonObject(); obj.getQueryParams().forEach((pair) -> map.put(pair.getKey(), pair.getValue())); json.put("queryParams", map); } if (obj.getRawRequest() != null) { json.put("rawRequest", obj.getRawRequest()); } if (obj.getRemoteAddr() != null) { json.put("remoteAddr", obj.getRemoteAddr()); } if (obj.getApiId() != null) { json.put("serviceId", obj.getApiId()); } if (obj.getApiOrgId() != null) { json.put("serviceOrgId", obj.getApiOrgId()); } if (obj.getApiVersion() != null) { json.put("serviceVersion", obj.getApiVersion()); } json.put("transportSecure", obj.isTransportSecure()); if (obj.getType() != null) { json.put("type", obj.getType()); } }
From source file:io.apiman.gateway.platforms.vertx3.io.VertxApiResponseConverter.java
License:Apache License
public static void toJson(VertxApiResponse obj, JsonObject json) { if (obj.getAttributes() != null) { JsonObject map = new JsonObject(); obj.getAttributes().forEach((key, value) -> map.put(key, value)); json.put("attributes", map); }//w w w.ja v a 2 s . c o m json.put("code", obj.getCode()); if (obj.getHeaders() != null) { JsonObject map = new JsonObject(); obj.getHeaders().forEach((pair) -> map.put(pair.getKey(), pair.getValue())); json.put("headers", map); } if (obj.getMessage() != null) { json.put("message", obj.getMessage()); } }
From source file:io.apiman.gateway.platforms.vertx3.io.VertxPolicyFailureConverter.java
License:Apache License
public static void toJson(VertxPolicyFailure obj, JsonObject json) { json.put("failureCode", obj.getFailureCode()); if (obj.getHeaders() != null) { JsonObject map = new JsonObject(); obj.getHeaders().forEach((pair) -> map.put(pair.getKey(), pair.getValue())); json.put("headers", map); }//from ww w.j ava2 s. c o m if (obj.getMessage() != null) { json.put("message", obj.getMessage()); } if (obj.getRaw() != null) { json.put("raw", obj.getRaw()); } json.put("responseCode", obj.getResponseCode()); if (obj.getType() != null) { json.put("type", obj.getType().name()); } }