in hawtio-system/src/main/java/io/hawt/web/proxy/ProxyServlet.java [130:188]
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
ConfigManager config = (ConfigManager) getServletContext().getAttribute(ConfigManager.CONFIG_MANAGER);
enabled = !config.getBoolean(DISABLE_PROXY, false);
if (!enabled) {
LOG.info("Proxy servlet is disabled");
// proxy servlet is disabled so won't run any further initialisation
return;
}
String allowlistStr = config.get(PROXY_ALLOWLIST, servletConfig.getInitParameter(PROXY_ALLOWLIST));
boolean probeLocal = config.getBoolean(LOCAL_ADDRESS_PROBING, true);
allowlist = new ProxyAllowlist(allowlistStr, probeLocal);
String doForwardIPString = servletConfig.getInitParameter(P_FORWARDEDFOR);
if (doForwardIPString != null) {
this.doForwardIP = Boolean.parseBoolean(doForwardIPString);
}
String doLogStr = servletConfig.getInitParameter(P_LOG);
if (doLogStr != null) {
this.doLog = Boolean.parseBoolean(doLogStr);
}
cookieStore = new BasicCookieStore();
HttpClientBuilder httpClientBuilder = HttpClients.custom()
.setDefaultCookieStore(cookieStore)
.useSystemProperties();
if (System.getProperty(PROXY_ACCEPT_SELF_SIGNED_CERTS) != null) {
acceptSelfSignedCerts = Boolean.parseBoolean(System.getProperty(PROXY_ACCEPT_SELF_SIGNED_CERTS));
} else if (System.getenv(PROXY_ACCEPT_SELF_SIGNED_CERTS_ENV) != null) {
acceptSelfSignedCerts = Boolean.parseBoolean(System.getenv(PROXY_ACCEPT_SELF_SIGNED_CERTS_ENV));
}
if (acceptSelfSignedCerts) {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, (X509Certificate[] x509Certificates, String s) -> true);
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
SSLUtil.createSSLContext(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpClientBuilder.setSSLSocketFactory(sslsf);
} catch (NoSuchAlgorithmException e) {
throw new ServletException(e);
} catch (KeyStoreException e) {
throw new ServletException(e);
} catch (KeyManagementException e) {
throw new ServletException(e);
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
proxyClient = httpClientBuilder.build();
}