/** * Configure the proxy with the required credential if needed * * @param httpClientBuilder * @param credsProvider * @param url * @return * @throws java.net.MalformedURLException */ private HttpClientBuilder configureProxy( HttpClientBuilder httpClientBuilder, CredentialsProvider credsProvider, String url) throws DSSException { try { if (proxyPreferenceManager == null) { return httpClientBuilder; } final String protocol = new URL(url).getProtocol(); final boolean proxyHTTPS = Protocol.isHttps(protocol) && proxyPreferenceManager.isHttpsEnabled(); final boolean proxyHTTP = Protocol.isHttp(protocol) && proxyPreferenceManager.isHttpEnabled(); if (!proxyHTTPS && !proxyHTTP) { return httpClientBuilder; } String proxyHost = null; int proxyPort = 0; String proxyUser = null; String proxyPassword = null; if (proxyHTTPS) { LOG.debug("Use proxy https parameters"); final Long port = proxyPreferenceManager.getHttpsPort(); proxyPort = port != null ? port.intValue() : 0; proxyHost = proxyPreferenceManager.getHttpsHost(); proxyUser = proxyPreferenceManager.getHttpsUser(); proxyPassword = proxyPreferenceManager.getHttpsPassword(); } else // noinspection ConstantConditions if (proxyHTTP) { LOG.debug("Use proxy http parameters"); final Long port = proxyPreferenceManager.getHttpPort(); proxyPort = port != null ? port.intValue() : 0; proxyHost = proxyPreferenceManager.getHttpHost(); proxyUser = proxyPreferenceManager.getHttpUser(); proxyPassword = proxyPreferenceManager.getHttpPassword(); } if (DSSUtils.isNotEmpty(proxyUser) && DSSUtils.isNotEmpty(proxyPassword)) { LOG.debug("proxy user: "******":" + proxyPassword); AuthScope proxyAuth = new AuthScope(proxyHost, proxyPort); UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); credsProvider.setCredentials(proxyAuth, proxyCredentials); } LOG.debug("proxy host/port: " + proxyHost + ":" + proxyPort); // TODO SSL peer shut down incorrectly when protocol is https HttpHost proxy = new HttpHost(proxyHost, proxyPort, Protocol.HTTP.getName()); return httpClientBuilder.setProxy(proxy); } catch (MalformedURLException e) { throw new DSSException(e); } }
/** @return the pkcs11File */ public File getPkcs11File() { if (pkcs11File == null) { final String path = userPreferencesDAO.getPKCS11LibraryPath(); if (DSSUtils.isNotEmpty(path)) { pkcs11File = new File(path); } } return pkcs11File; }