/** * Constructor. Parses options immediately. * @param options the options */ public AbstractOptions(Map<String, String> options) { parse(options); }
/** * @see io.apiman.common.config.options.AbstractOptions#parse(java.util.Map) */ @Override protected void parse(Map<String, String> options) { setUsername(getVar(options, BASIC_USERNAME)); setPassword(getVar(options, BASIC_PASSWORD)); setRequireSSL(parseBool(options, BASIC_REQUIRE_SSL, true)); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + connectionTimeout; result = prime * result + idleTimeout; result = prime * result + (keepAlive ? 1231 : 1237); result = prime * result + ((tlsOptions == null) ? 0 : tlsOptions.hashCode()); result = prime * result + (tryUseCompression ? 1231 : 1237); result = prime * result + (isSsl ? 0 : 1); return result; } /* (non-Javadoc)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { String[] allowedProtocols = arrayDifference(optionsMap.getAllowedProtocols(), optionsMap.getDisallowedProtocols(), getDefaultProtocols()); String[] allowedCiphers = arrayDifference(optionsMap.getAllowedCiphers(), optionsMap.getDisallowedCiphers(), getDefaultCipherSuites()); return build(optionsMap.getTrustStore(), optionsMap.getTrustStorePassword(), optionsMap.isAllowAnyHost(), optionsMap.isTrustSelfSigned());
/** * Constructor. * @param metricsServer * @param options */ public HawkularMetricsClient(URL metricsServer, HttpConnectorOptions options) { this(metricsServer); httpClient.setReadTimeout(options.getReadTimeout(), TimeUnit.SECONDS); httpClient.setWriteTimeout(options.getWriteTimeout(), TimeUnit.SECONDS); httpClient.setConnectTimeout(options.getConnectTimeout(), TimeUnit.SECONDS); httpClient.setFollowRedirects(options.isFollowRedirects()); httpClient.setFollowSslRedirects(options.isFollowRedirects()); }
/** * Constructor. * @param config map of configuration options */ public HttpConnectorFactory(Map<String, String> config) { this.tlsOptions = new TLSOptions(config); this.connectorOptions = new HttpConnectorOptions(config); this.okClient = createHttpClient(); }
/** * @see io.apiman.common.config.options.AbstractOptions#parse(java.util.Map) */ @Override protected void parse(Map<String, String> options) { String read = options.get("http.timeouts.read"); //$NON-NLS-1$ String write = options.get("http.timeouts.write"); //$NON-NLS-1$ String connect = options.get("http.timeouts.connect"); //$NON-NLS-1$ String redirects = options.get("http.followRedirects"); //$NON-NLS-1$ if (read != null) { setReadTimeout(Integer.parseInt(read)); } else { setReadTimeout(DEFAULT_READ_TIMEOUT); } if (write != null) { setWriteTimeout(Integer.parseInt(write)); } else { setWriteTimeout(DEFAULT_WRITE_TIMEOUT); } if (connect != null) { setConnectTimeout(Integer.parseInt(connect)); } else { setConnectTimeout(DEFAULT_CONNECT_TIMEOUT); } if (redirects != null) { setFollowRedirects(Boolean.parseBoolean(redirects)); } else { setFollowRedirects(DEFAULT_FOLLOW_REDIRECTS); } }
private void verifyConnection() { switch (options.getRequiredAuthType()) { case BASIC: basicOptions = new BasicAuthOptions(api.getEndpointProperties()); if (!options.isSsl() && basicOptions.isRequireSSL()) throw new ConnectorException("Endpoint security requested (BASIC auth) but endpoint is not secure (SSL)."); break; case MTLS: if (!options.isSsl()) throw new ConnectorException("Mutual TLS specified, but endpoint is not HTTPS."); break; case DEFAULT: break; } }
/** * Constructor. */ @SuppressWarnings("nls") public HawkularMetricsAccessor(Map<String, String> config) { String endpoint = config.get("hawkular.endpoint"); Map<String, String> httpOptions = new HashMap<>(); httpOptions.put("http.timeouts.read", config.get("http.timeouts.read")); httpOptions.put("http.timeouts.write", config.get("http.timeouts.write")); httpOptions.put("http.timeouts.connect", config.get("http.timeouts.connect")); httpOptions.put("http.followRedirects", config.get("http.followRedirects")); client = new HawkularMetricsClient(endpoint, new HttpConnectorOptions(httpOptions)); }
/** * Creates the SSL strategy based on configured TLS options. * @param authType * @return an appropriate SSL strategy */ protected SSLSessionStrategy getSslStrategy(RequiredAuthType authType) { try { if (authType == RequiredAuthType.MTLS) { if (mutualAuthSslStrategy == null) { mutualAuthSslStrategy = SSLSessionStrategyFactory.buildMutual(tlsOptions); } return mutualAuthSslStrategy; } else { if (standardSslStrategy == null) { if (tlsOptions.isDevMode()) { standardSslStrategy = SSLSessionStrategyFactory.buildUnsafe(); } else { standardSslStrategy = SSLSessionStrategyFactory.buildStandard(tlsOptions); } } return standardSslStrategy; } } catch (Exception e) { throw new RuntimeException(e); } }
/** * Constructor * @param vertx a vertx instance * @param config the config */ public ConnectorFactory(Vertx vertx, Map<String, String> config) { this.vertx = vertx; this.config = config; this.tlsOptions = new TLSOptions(config); }
private Future<List<Api>> fetchPolicyConfig() { log.debug("Loading policy configuration from {0}...", policyConfigUri); Future<List<Api>> apiResultFuture = Future.future(); Map<String, String> filteredConfig = AbstractOptions.getSubmap(config, "policyConfig."); new PolicyConfigLoader(vertx, policyConfigUri, filteredConfig) .setApiResultHandler(apis -> { this.policyConfigApis = apis; apiResultFuture.complete(); }) .setExceptionHandler(apiResultFuture::fail) .load(); return apiResultFuture; }
protected static boolean parseBool(Map<String, String> optionsMap, String key) { return parseBool(optionsMap, key, false); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; ApimanHttpConnectorOptions other = (ApimanHttpConnectorOptions) obj; if (connectionTimeout != other.connectionTimeout) return false; if (idleTimeout != other.idleTimeout) return false; if (keepAlive != other.keepAlive) return false; if (tlsOptions == null) { if (other.tlsOptions != null) return false; } else if (!tlsOptions.equals(other.tlsOptions)) return false; if (tryUseCompression != other.tryUseCompression) return false; return true; }
/** * @see io.apiman.common.config.options.AbstractOptions#parse(java.util.Map) */ @Override protected void parse(Map<String, String> options) { trustStore = getVar(options, TLS_TRUSTSTORE); trustStorePassword = getVar(options, TLS_TRUSTSTOREPASSWORD); clientKeyStore = getVar(options, TLS_KEYSTORE); keyStorePassword = getVar(options, TLS_KEYSTOREPASSWORD); keyAliases = split(getVar(options, TLS_KEYALIASES), ','); keyPassword = getVar(options, TLS_KEYPASSWORD); allowedProtocols = split(getVar(options, TLS_ALLOWEDPROTOCOLS), ','); allowedCiphers = split(getVar(options, TLS_ALLOWEDCIPHERS), ','); disallowedCiphers = split(getVar(options, TLS_DISALLOWEDCIPHERS), ','); allowAnyHost = parseBool(options, TLS_ALLOWANYHOST); trustSelfSigned = parseBool(options, TLS_ALLOWSELFSIGNED); devMode = parseBool(options, TLS_DEVMODE); }
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException { String[] allowedProtocols = arrayDifference(optionsMap.getAllowedProtocols(), optionsMap.getDisallowedProtocols(), getDefaultProtocols()); String[] allowedCiphers = arrayDifference(optionsMap.getAllowedCiphers(), optionsMap.getDisallowedCiphers(), getDefaultCipherSuites()); return build(optionsMap.getTrustStore(), optionsMap.getTrustStorePassword(), optionsMap.isAllowAnyHost(), optionsMap.isTrustSelfSigned());
/** * Constructor. * @param metricsServer * @param options */ public HawkularMetricsClient(URL metricsServer, HttpConnectorOptions options) { this(metricsServer); httpClient.setReadTimeout(options.getReadTimeout(), TimeUnit.SECONDS); httpClient.setWriteTimeout(options.getWriteTimeout(), TimeUnit.SECONDS); httpClient.setConnectTimeout(options.getConnectTimeout(), TimeUnit.SECONDS); httpClient.setFollowRedirects(options.isFollowRedirects()); httpClient.setFollowSslRedirects(options.isFollowRedirects()); }
/** * Constructor. * @param config map of configuration options */ public HttpConnectorFactory(Map<String, String> config) { this.tlsOptions = new TLSOptions(config); this.connectorOptions = new HttpConnectorOptions(config); this.okClient = createHttpClient(); }
/** * Creates the SSL strategy based on configured TLS options. * @param authType * @return an appropriate SSL strategy */ protected SSLSessionStrategy getSslStrategy(RequiredAuthType authType) { try { if (authType == RequiredAuthType.MTLS) { if (mutualAuthSslStrategy == null) { mutualAuthSslStrategy = SSLSessionStrategyFactory.buildMutual(tlsOptions); } return mutualAuthSslStrategy; } else { if (standardSslStrategy == null) { if (tlsOptions.isDevMode()) { standardSslStrategy = SSLSessionStrategyFactory.buildUnsafe(); } else { standardSslStrategy = SSLSessionStrategyFactory.buildStandard(tlsOptions); } } return standardSslStrategy; } } catch (Exception e) { throw new RuntimeException(e); } }
private Future<List<Api>> fetchPolicyConfig() { log.debug("Loading policy configuration from {0}...", policyConfigUri); Future<List<Api>> apiResultFuture = Future.future(); Map<String, String> filteredConfig = AbstractOptions.getSubmap(config, "policyConfig."); new PolicyConfigLoader(vertx, policyConfigUri, filteredConfig) .setApiResultHandler(apis -> { this.policyConfigApis = apis; apiResultFuture.complete(); }) .setExceptionHandler(apiResultFuture::fail) .load(); return apiResultFuture; }