@NotNull static HttpClientBuilder getBuilder() { final HttpClientBuilder builder = HttpClients.custom().setSSLContext(CertificateManager.getInstance().getSslContext()). setMaxConnPerRoute(100000).setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE); final HttpConfigurable proxyConfigurable = HttpConfigurable.getInstance(); final List<Proxy> proxies = proxyConfigurable.getOnlyBySettingsSelector().select(URI.create(EduStepicNames.STEPIC_URL)); final InetSocketAddress address = proxies.size() > 0 ? (InetSocketAddress)proxies.get(0).address() : null; if (address != null) { builder.setProxy(new HttpHost(address.getHostName(), address.getPort())); } final ConfirmingTrustManager trustManager = CertificateManager.getInstance().getTrustManager(); try { SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[]{trustManager}, new SecureRandom()); builder.setSSLContext(sslContext); } catch (NoSuchAlgorithmException | KeyManagementException e) { LOG.error(e.getMessage()); } return builder; }
@Nullable public static Reader getReaderByUrl(final String surl, final HttpConfigurable httpConfigurable, final ProgressIndicator pi) throws IOException { if (surl.startsWith(JAR_PROTOCOL)) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(BrowserUtil.getDocURL(surl)); if (file == null) { return null; } return new StringReader(VfsUtil.loadText(file)); } URL url = BrowserUtil.getURL(surl); if (url == null) { return null; } httpConfigurable.prepareURL(url.toString()); final URLConnection urlConnection = url.openConnection(); final String contentEncoding = urlConnection.getContentEncoding(); final InputStream inputStream = pi != null ? UrlConnectionUtil.getConnectionInputStreamWithException(urlConnection, pi) : urlConnection.getInputStream(); //noinspection IOResourceOpenedButNotSafelyClosed return contentEncoding != null ? new InputStreamReader(inputStream, contentEncoding) : new InputStreamReader(inputStream); }
@NotNull private Config getNetworkConfig(@NotNull ApplicationSettings settings) { ProxyConfig proxyConfig; try { final HttpConfigurable iConfig = HttpConfigurable.getInstance(); if (iConfig.isHttpProxyEnabledForUrl(settings.serverRoot)) { proxyConfig = new ProxyConfig(iConfig.PROXY_HOST, iConfig.PROXY_PORT, iConfig.getProxyLogin(), iConfig.getPlainProxyPassword()); } else { proxyConfig = null; } } catch (Exception ignored) { // if that fails, we pretend there is no proxy. This might fail do to subtle changes in the HttpConfigurable class between intellij versions. proxyConfig = null; } return new Config(settings.apiKey, settings.userId, settings.workspaceId, settings.serverRoot, settings.trackingRoot, settings.isTrackingEnabled, settings.connectTimeout, settings.requestTimeout, settings.isApacheLoggingEnabled, settings.isJsonDebugEnabled, proxyConfig, applicationUserAgent); }
@Nullable private URL createVersionsUrl() { final String serviceUrl = getServiceUrl(); if (StringUtil.isNotEmpty(serviceUrl)) { try { final String url = serviceUrl + "/" + FILE_NAME; HttpConfigurable.getInstance().prepareURL(url); return new URL(url); } catch (MalformedURLException ignored) { } catch (IOException e) { // no route to host, unknown host, etc. } } return null; }
@NotNull private MantisConnectPortType createSoap() throws Exception { if (isUseProxy()) { for (KeyValue<String, String> pair : HttpConfigurable.getJvmPropertiesList(false, null)) { String key = pair.getKey(), value = pair.getValue(); // Axis uses another names for username and password properties // see http://axis.apache.org/axis/java/client-side-axis.html for complete list if (key.equals(JavaProxyProperty.HTTP_USERNAME)) { AxisProperties.setProperty("http.proxyUser", value); } else if (key.equals(JavaProxyProperty.HTTP_PASSWORD)) { AxisProperties.setProperty("http.proxyPassword", value); } else { AxisProperties.setProperty(key, value); } } } return new MantisConnectLocator().getMantisConnectPort(new URL(getUrl() + SOAP_API_LOCATION)); }
protected void configureHttpClient(HttpClient client) { client.getParams().setConnectionManagerTimeout(3000); client.getParams().setSoTimeout(TaskSettings.getInstance().CONNECTION_TIMEOUT); if (isUseProxy()) { HttpConfigurable proxy = HttpConfigurable.getInstance(); client.getHostConfiguration().setProxy(proxy.PROXY_HOST, proxy.PROXY_PORT); if (proxy.PROXY_AUTHENTICATION) { AuthScope authScope = new AuthScope(proxy.PROXY_HOST, proxy.PROXY_PORT); Credentials credentials = getCredentials(proxy.PROXY_LOGIN, proxy.getPlainProxyPassword(), proxy.PROXY_HOST); client.getState().setProxyCredentials(authScope, credentials); } } if (isUseHttpAuthentication()) { client.getParams().setCredentialCharset("UTF-8"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword())); } else { client.getState().clearCredentials(); client.getParams().setAuthenticationPreemptive(false); } }
private void setupSshAuthenticator() throws IOException { GitXmlRpcSshService ssh = ServiceManager.getService(GitXmlRpcSshService.class); myEnv.put(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath()); mySshHandler = ssh.registerHandler(new GitSSHGUIHandler(myProject)); myEnvironmentCleanedUp = false; myEnv.put(GitSSHHandler.SSH_HANDLER_ENV, Integer.toString(mySshHandler)); int port = ssh.getXmlRcpPort(); myEnv.put(GitSSHHandler.SSH_PORT_ENV, Integer.toString(port)); LOG.debug(String.format("handler=%s, port=%s", mySshHandler, port)); final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); boolean useHttpProxy = httpConfigurable.USE_HTTP_PROXY && !isSshUrlExcluded(httpConfigurable, ObjectUtils.assertNotNull(myUrls)); myEnv.put(GitSSHHandler.SSH_USE_PROXY_ENV, String.valueOf(useHttpProxy)); if (useHttpProxy) { myEnv.put(GitSSHHandler.SSH_PROXY_HOST_ENV, StringUtil.notNullize(httpConfigurable.PROXY_HOST)); myEnv.put(GitSSHHandler.SSH_PROXY_PORT_ENV, String.valueOf(httpConfigurable.PROXY_PORT)); boolean proxyAuthentication = httpConfigurable.PROXY_AUTHENTICATION; myEnv.put(GitSSHHandler.SSH_PROXY_AUTHENTICATION_ENV, String.valueOf(proxyAuthentication)); if (proxyAuthentication) { myEnv.put(GitSSHHandler.SSH_PROXY_USER_ENV, StringUtil.notNullize(httpConfigurable.PROXY_LOGIN)); myEnv.put(GitSSHHandler.SSH_PROXY_PASSWORD_ENV, StringUtil.notNullize(httpConfigurable.getPlainProxyPassword())); } } }
@Nullable public static Proxy getIdeaDefinedProxy(@NotNull final SVNURL url) { // SVNKit authentication implementation sets repositories as noProxy() to provide custom proxy authentication logic - see for instance, // SvnAuthenticationManager.getProxyManager(). But noProxy() setting is not cleared correctly in all cases - so if svn command // (for command line) is executed on thread where repository url was added as noProxy() => proxies are not retrieved for such commands // and execution logic is incorrect. // To prevent such behavior repositoryUrl is manually removed from noProxy() list (for current thread). // NOTE, that current method is only called from code flows for executing commands through command line client and should not be called // from SVNKit code flows. CommonProxy.getInstance().removeNoProxy(url.getProtocol(), url.getHost(), url.getPort()); final List<Proxy> proxies = CommonProxy.getInstance().select(URI.create(url.toString())); if (proxies != null && !proxies.isEmpty()) { for (Proxy proxy : proxies) { if (HttpConfigurable.isRealProxy(proxy) && Proxy.Type.HTTP.equals(proxy.type())) { return proxy; } } } return null; }
/** * Find the proxy login username * * @return */ public static String getProxyLogin() { try { // try to get login name using method existing in IDEA release 163.1188 and above final Method proxyLoginMethod = HttpConfigurable.getInstance().getClass().getDeclaredMethod(PROXY_LOGIN_METHOD); return (String) proxyLoginMethod.invoke(HttpConfigurable.getInstance(), null); } catch (Exception newImplementationException) { try { logger.warn("Failed to get proxy login using getProxyLogin() so attempting old way", newImplementationException); // try to get login name using global variable existing before IDEA release 163.1188 final Field proxyLoginField = HttpConfigurable.getInstance().getClass().getDeclaredField(PROXY_LOGIN_FIELD); return (String) proxyLoginField.get(HttpConfigurable.getInstance()); } catch (Exception oldImplementationException) { logger.warn("Failed to get proxy login using PROXY_LOGIN field", oldImplementationException); return StringUtils.EMPTY; } } }
@Override protected void doOKAction() { if (shouldPromptForProxyPassword(false)) { HttpConfigurable hc = HttpConfigurable.getInstance(); hc.setPlainProxyPassword(myLoginForm.getProxyPassword()); } if (myLoginForm.getCredentials().getType() == Credentials.Type.Alternate && "http".equals(getUri().getScheme())) { if (Messages.showYesNoDialog(myLoginForm.getContentPane(), "You're about to send your credentials over unsecured HTTP connection. Continue?", getTitle(), null) != Messages.YES) { return; } } if (myOkActionCallback == null || myOkActionCallback.value(this)) { super.doOKAction(); } }
public static HTTPProxyInfo getCurrent() { // axis will override the higher-level settings with system properties, so explicitly clear them CommonProxy.isInstalledAssertion(); if (TFSConfigurationManager.getInstance().useIdeaHttpProxy()) { final HttpConfigurable hc = HttpConfigurable.getInstance(); if (hc.USE_HTTP_PROXY) { if (hc.PROXY_AUTHENTICATION) { // here we assume proxy auth dialog was shown if needed, see promptForPassword() caller return new HTTPProxyInfo(hc.PROXY_HOST, hc.PROXY_PORT, hc.PROXY_LOGIN, hc.getPlainProxyPassword()); } else { return new HTTPProxyInfo(hc.PROXY_HOST, hc.PROXY_PORT, null, null); } } } return new HTTPProxyInfo(null, -1, null, null); }
/** * Spuštění stahování * * @param project aktuální projekt * @param tagName aktuální release * @param task akce, která se spustí při stahování */ private void execute( @NotNull Project project, @NotNull String tagName, @NotNull Consumer<HttpURLConnection> task) { HttpURLConnection connection = null; try { connection = HttpConfigurable.getInstance().openHttpConnection( String.format( ZIP_URL_PATTERN, tagName, tagName ) ); task.consume(connection); } catch (IOException e) { warn(project, e.getMessage()) ; } finally { if (connection != null) { connection.disconnect(); } } }
private static HttpURLConnection post(URL url, byte[] bytes) throws IOException { HttpURLConnection connection = (HttpURLConnection)HttpConfigurable.getInstance().openConnection(url.toString()); connection.setReadTimeout(10 * 1000); connection.setConnectTimeout(10 * 1000); connection.setRequestMethod(HTTP_POST); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestProperty(HTTP_CONTENT_TYPE, String.format("%s; charset=%s", HTTP_WWW_FORM, ENCODING)); connection.setRequestProperty(HTTP_CONTENT_LENGTH, Integer.toString(bytes.length)); OutputStream out = new BufferedOutputStream(connection.getOutputStream()); try { out.write(bytes); out.flush(); } finally { out.close(); } return connection; }
@Nullable private static Reader getReaderByUrl(final String surl, final HttpConfigurable httpConfigurable, final ProgressIndicator pi) throws IOException { if (surl.startsWith(JAR_PROTOCOL)) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(BrowserUtil.getDocURL(surl)); if (file == null) { return null; } return new StringReader(VfsUtilCore.loadText(file)); } URL url = BrowserUtil.getURL(surl); if (url == null) { return null; } final URLConnection urlConnection = httpConfigurable.openConnection(url.toString()); final String contentEncoding = guessEncoding(url); final InputStream inputStream = pi != null ? UrlConnectionUtil.getConnectionInputStreamWithException(urlConnection, pi) : urlConnection.getInputStream(); //noinspection IOResourceOpenedButNotSafelyClosed return contentEncoding != null ? new MyReader(inputStream, contentEncoding) : new MyReader(inputStream); }
protected void configureHttpClient(HttpClient client) { client.getParams().setConnectionManagerTimeout(3000); client.getParams().setSoTimeout(TaskSettings.getInstance().CONNECTION_TIMEOUT); if (isUseProxy()) { HttpConfigurable proxy = HttpConfigurable.getInstance(); client.getHostConfiguration().setProxy(proxy.PROXY_HOST, proxy.PROXY_PORT); if (proxy.PROXY_AUTHENTICATION) { AuthScope authScope = new AuthScope(proxy.PROXY_HOST, proxy.PROXY_PORT); Credentials credentials = getCredentials(proxy.PROXY_LOGIN, proxy.getPlainProxyPassword(), proxy.PROXY_HOST); client.getState().setProxyCredentials(authScope, credentials); } } if (isUseHttpAuthentication()) { client.getParams().setCredentialCharset("UTF-8"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword())); } }
@NotNull private static HttpClient getHttpClient(@Nullable GithubAuthData.BasicAuth basicAuth) { final HttpClient client = new HttpClient(); HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams(); params.setConnectionTimeout(CONNECTION_TIMEOUT); //set connection timeout (how long it takes to connect to remote host) params.setSoTimeout(CONNECTION_TIMEOUT); //set socket timeout (how long it takes to retrieve data from remote host) client.getParams().setContentCharset("UTF-8"); // Configure proxySettings if it is required final HttpConfigurable proxySettings = HttpConfigurable.getInstance(); if (proxySettings.USE_HTTP_PROXY && !StringUtil.isEmptyOrSpaces(proxySettings.PROXY_HOST)) { client.getHostConfiguration().setProxy(proxySettings.PROXY_HOST, proxySettings.PROXY_PORT); if (proxySettings.PROXY_AUTHENTICATION) { client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.PROXY_LOGIN, proxySettings.getPlainProxyPassword())); } } if (basicAuth != null) { client.getParams().setCredentialCharset("UTF-8"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuth.getLogin(), basicAuth.getPassword())); } return client; }
public static RestClient createRestClient(String location, String domain, String project, String username, String password, RestClient.SessionStrategy strategy) { RestClient restClient = factory.create(location, domain, project, username, password, strategy); restClient.setEncoding(null); restClient.setTimeout(10000); HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); IdeaWideProxySelector proxySelector = new IdeaWideProxySelector(httpConfigurable); List<Proxy> proxies = proxySelector.select(VfsUtil.toUri(location)); if (proxies != null) { for (Proxy proxy: proxies) { if (HttpConfigurable.isRealProxy(proxy) && Proxy.Type.HTTP.equals(proxy.type())) { InetSocketAddress address = (InetSocketAddress)proxy.address(); restClient.setHttpProxy(address.getHostName(), address.getPort()); // not sure how IdeaWideAuthenticator & co. is supposed to work, let's try something simple: if(httpConfigurable.PROXY_AUTHENTICATION) { PasswordAuthentication authentication = httpConfigurable.getPromptedAuthentication("HP ALI", address.getHostName()); if(authentication != null) { restClient.setHttpProxyCredentials(authentication.getUserName(), new String(authentication.getPassword())); } } break; } } } return restClient; }
public static Map<Version, String> getAvailableArtifactVersions(String groupId, String artifactId, Collection<URL> repositories) throws IOException { Map<Version, String> availableVersions = new TreeMap<>(Version.descendingOrderComparator()); final String relativePathToArtifact = groupId.replace(".", "/") + "/" + artifactId.replace(".", "/"); String artifactLocation; for (final URL repository : repositories) { artifactLocation = repository.toExternalForm() + "/" + relativePathToArtifact; HttpURLConnection artifactRootConnection = HttpConfigurable.getInstance().openHttpConnection(artifactLocation); String artifactRootPage = StreamUtil.readText(artifactRootConnection.getInputStream(), StandardCharsets.UTF_8); Matcher artifactVersionMatcher = ARTIFACT_ROOT_VERSION_PATTERN.matcher(artifactRootPage); while (artifactVersionMatcher.find()) { String matchedVersion = artifactVersionMatcher.group(1); Version parsedVersion = Version.parseString(matchedVersion); if (parsedVersion != Version.INVALID) { String versionUrl = repository.toExternalForm() + "/" + relativePathToArtifact + "/" + parsedVersion.toString(); availableVersions.put(parsedVersion, versionUrl); } } artifactRootConnection.disconnect(); if (! availableVersions.isEmpty()) { break; } } return availableVersions; }
@Transient @Override public CloudProxySettings getProxySettings() { final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); return new CloudProxySettings() { @Override public boolean useHttpProxy() { return httpConfigurable.USE_HTTP_PROXY; } @Override public String getHost() { return httpConfigurable.PROXY_HOST; } @Override public int getPort() { return httpConfigurable.PROXY_PORT; } @Override public boolean useAuthentication() { return httpConfigurable.PROXY_AUTHENTICATION; } @Override public String getLogin() { return httpConfigurable.PROXY_LOGIN; } @Override public String getPassword() { return httpConfigurable.getPlainProxyPassword(); } }; }
@Nullable private static ConnectionState promptUserForProxy() { int selection = Messages.showIdeaMessageDialog(null, "Unable to access Android SDK add-on list", "Android Studio First Run", new String[]{"Setup Proxy", "Cancel"}, 1, Messages.getErrorIcon(), null); if (selection == 0) { //noinspection ConstantConditions HttpConfigurable.editConfigurable(null); return null; } else { return ConnectionState.NO_CONNECTION; } }
private static void download(@NotNull String url, @NotNull File destination, @NotNull ProgressIndicator indicator) throws IOException { indicator.setText(String.format("Downloading %s", destination.getName())); HttpURLConnection connection = HttpConfigurable.getInstance().openHttpConnection(url); int contentLength = connection.getContentLength(); if (contentLength <= 0) { indicator.setIndeterminate(true); } InputStream readStream = null; OutputStream stream = null; try { readStream = connection.getInputStream(); //noinspection IOResourceOpenedButNotSafelyClosed stream = new BufferedOutputStream(new FileOutputStream(destination)); byte[] buffer = new byte[2 * 1024 * 1024]; int read; int totalRead = 0; final long startTime = System.currentTimeMillis(); for (read = readStream.read(buffer); read > 0; read = readStream.read(buffer)) { totalRead += read; stream.write(buffer, 0, read); long duration = System.currentTimeMillis() - startTime; // Duration is in ms long downloadRate = duration == 0 ? 0 : (totalRead / duration); String message = String.format("Downloading %1$s (%2$s/s)", destination.getName(), WelcomeUIUtils.getSizeLabel(downloadRate * 1000)); indicator.setText(message); if (contentLength > 0) { indicator.setFraction(((double)totalRead) / contentLength); } indicator.checkCanceled(); } } finally { if (stream != null) { stream.close(); } if (readStream != null) { readStream.close(); } } }
public void copyFrom(@NotNull HttpConfigurable ideProxySettings) { myHost = ideProxySettings.PROXY_HOST; myPort = ideProxySettings.PROXY_PORT; if (ideProxySettings.PROXY_AUTHENTICATION) { myUser = ideProxySettings.PROXY_LOGIN; myPassword = ideProxySettings.getPlainProxyPassword(); } myExceptions = ideProxySettings.PROXY_EXCEPTIONS; }
public void testCopyProxySettingsFromIde() { String host = "myproxy.test.com"; int port = 443; HttpConfigurable ideSettings = HttpConfigurable.getInstance(); ideSettings.USE_HTTP_PROXY = true; ideSettings.PROXY_HOST = host; ideSettings.PROXY_PORT = port; GradleProperties.ProxySettings proxySettings = myProperties.getProxySettings(); proxySettings.copyFrom(ideSettings); assertEquals(host, proxySettings.getHost()); assertEquals(port, proxySettings.getPort()); }
public void testSetProxySettings() { String host = "myproxy.test.com"; int port = 443; String user = "johndoe"; String password = "123456"; HttpConfigurable ideSettings = HttpConfigurable.getInstance(); ideSettings.USE_HTTP_PROXY = true; ideSettings.PROXY_HOST = host; ideSettings.PROXY_PORT = port; ideSettings.PROXY_AUTHENTICATION = true; ideSettings.PROXY_LOGIN = user; ideSettings.setPlainProxyPassword(password); GradleProperties.ProxySettings proxySettings = myProperties.getProxySettings(); proxySettings.copyFrom(ideSettings); // Verify that the proxy settings are stored properly in the actual properties file. myProperties.setProxySettings(proxySettings); assertEquals(host, myProperties.getProperty("systemProp.http.proxyHost")); assertEquals(String.valueOf(port), myProperties.getProperty("systemProp.http.proxyPort")); assertEquals(user, myProperties.getProperty("systemProp.http.proxyUser")); assertEquals(password, myProperties.getProperty("systemProp.http.proxyPassword")); proxySettings = myProperties.getProxySettings(); assertEquals(host, proxySettings.getHost()); assertEquals(port, proxySettings.getPort()); // Verify that username and password are removed from properties file, if authentication is disabled in IDE settings. ideSettings.PROXY_AUTHENTICATION = false; proxySettings.copyFrom(ideSettings); myProperties.setProxySettings(proxySettings); assertNull(myProperties.getProperty("systemProp.http.proxyUser")); assertNull(myProperties.getProperty("systemProp.http.proxyPassword")); }
private static void setIdeSettings() { GradleExperimentalSettings.getInstance().SELECT_MODULES_ON_PROJECT_IMPORT = false; // Clear HTTP proxy settings, in case a test changed them. HttpConfigurable ideSettings = HttpConfigurable.getInstance(); ideSettings.USE_HTTP_PROXY = false; ideSettings.PROXY_HOST = ""; ideSettings.PROXY_PORT = 80; GuiTestSuiteState state = getGuiTestSuiteState(); state.setSkipSdkMerge(false); state.setUseCachedGradleModelOnly(false); }
@NotNull @Override public List<KeyValue<String, String>> getExtraJvmArgs() { if (ExternalSystemApiUtil.isInProcessMode(GradleConstants.SYSTEM_ID)) { final List<KeyValue<String, String>> extraJvmArgs = ContainerUtil.newArrayList(); final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); if (!StringUtil.isEmpty(httpConfigurable.PROXY_EXCEPTIONS)) { List<String> hosts = StringUtil.split(httpConfigurable.PROXY_EXCEPTIONS, ","); if (!hosts.isEmpty()) { final String nonProxyHosts = StringUtil.join(hosts, StringUtil.TRIMMER, "|"); extraJvmArgs.add(KeyValue.create("http.nonProxyHosts", nonProxyHosts)); extraJvmArgs.add(KeyValue.create("https.nonProxyHosts", nonProxyHosts)); } } if (httpConfigurable.USE_HTTP_PROXY && StringUtil.isNotEmpty(httpConfigurable.PROXY_LOGIN)) { extraJvmArgs.add(KeyValue.create("http.proxyUser", httpConfigurable.PROXY_LOGIN)); extraJvmArgs.add(KeyValue.create("https.proxyUser", httpConfigurable.PROXY_LOGIN)); final String plainProxyPassword = httpConfigurable.getPlainProxyPassword(); extraJvmArgs.add(KeyValue.create("http.proxyPassword", plainProxyPassword)); extraJvmArgs.add(KeyValue.create("https.proxyPassword", plainProxyPassword)); } extraJvmArgs.addAll(HttpConfigurable.getJvmPropertiesList(false, null)); return extraJvmArgs; } return Collections.emptyList(); }
protected static boolean isSshUrlExcluded(@NotNull final HttpConfigurable httpConfigurable, @NotNull Collection<String> urls) { return ContainerUtil.exists(urls, new Condition<String>() { @Override public boolean value(String url) { String host = URLUtil.parseHostFromSshUrl(url); return ((IdeaWideProxySelector)httpConfigurable.getOnlyBySettingsSelector()).isProxyException(host); } }); }
private static void showFailedAuthenticateProxy() { HttpConfigurable instance = HttpConfigurable.getInstance(); String message = instance.USE_HTTP_PROXY || instance.USE_PROXY_PAC ? "Failed to authenticate to proxy. You can change proxy credentials in HTTP proxy settings." : "Failed to authenticate to proxy."; PopupUtil.showBalloonForActiveComponent(message, MessageType.ERROR); }
private static void setDefaultFixedProxySettings() { final HttpConfigurable h = HttpConfigurable.getInstance(); h.USE_PROXY_PAC = false; h.USE_HTTP_PROXY = true; h.AUTHENTICATION_CANCELLED = false; // doesn't matter, only significant for serialization h.KEEP_PROXY_PASSWORD = false; h.LAST_ERROR = null; }
private void initialize() { useHttpProxyViaSystemProperties = StringUtils.equalsIgnoreCase(System.getProperty(PROP_PROXY_SET), "true"); if (!useHttpProxyViaSystemProperties) { useHttpProxyViaIntelliJProperties = PluginServiceProvider.getInstance().isInsideIDE() && HttpConfigurable.getInstance() != null && HttpConfigurable.getInstance().USE_HTTP_PROXY; } else { useHttpProxyViaIntelliJProperties = false; } }
@Override public boolean isAuthenticationRequired() { initialize(); // We don't do authentication if we are using the system properties final boolean result = !useHttpProxyViaSystemProperties && useHttpProxyViaIntelliJProperties && HttpConfigurable.getInstance().PROXY_AUTHENTICATION; logger.info("isAuthenticationRequired: " + result); return result; }
@Override public String getProxyHost() { initialize(); // default to Fiddler proxy host String proxyHost = "127.0.0.1"; if (useHttpProxyViaSystemProperties && System.getProperty(PROP_PROXY_HOST) != null) { proxyHost = System.getProperty(PROP_PROXY_HOST); } else if (useHttpProxyViaIntelliJProperties) { proxyHost = HttpConfigurable.getInstance().PROXY_HOST; } logger.info("getProxyHost: " + proxyHost); return proxyHost; }
@Override public int getProxyPort() { initialize(); // default to Fiddler proxy port int proxyPort = 8888; if (useHttpProxyViaSystemProperties && System.getProperty(PROP_PROXY_PORT) != null) { proxyPort = SystemHelper.toInt(System.getProperty(PROP_PROXY_PORT), proxyPort); } else if (useHttpProxyViaIntelliJProperties) { proxyPort = HttpConfigurable.getInstance().PROXY_PORT; } logger.info("getProxyPort: " + proxyPort); return proxyPort; }
@Override public String getPassword() { logger.info("getPassword called"); initialize(); if (useHttpProxyViaIntelliJProperties) { return HttpConfigurable.getInstance().getPlainProxyPassword(); } else { return null; } }
public static boolean shouldPromptForProxyPassword(boolean strictOnly) { HttpConfigurable hc = HttpConfigurable.getInstance(); return TFSConfigurationManager.getInstance().useIdeaHttpProxy() && hc.USE_HTTP_PROXY && hc.PROXY_AUTHENTICATION && !hc.KEEP_PROXY_PASSWORD && (!strictOnly || StringUtil.isEmpty(hc.getPlainProxyPassword())); }
public static boolean shouldPromptForPassword() { if (TFSConfigurationManager.getInstance().useIdeaHttpProxy()) { final HttpConfigurable hc = HttpConfigurable.getInstance(); return hc.USE_HTTP_PROXY && hc.PROXY_AUTHENTICATION && !hc.KEEP_PROXY_PASSWORD; } return false; }
public static InputStream loadUrl(final String url) throws Exception { final InputStream[] inputStreams = new InputStream[]{null}; final Exception[] exception = new Exception[]{null}; Future<?> downloadThreadFuture = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { public void run() { try { HttpURLConnection connection; if (ApplicationManager.getApplication() != null) { connection = HttpConfigurable.getInstance().openHttpConnection(url); } else { connection = (HttpURLConnection) new URL(url).openConnection(); connection.setReadTimeout(CONNECTION_TIMEOUT); connection.setConnectTimeout(CONNECTION_TIMEOUT); } connection.connect(); inputStreams[0] = connection.getInputStream(); } catch (IOException e) { exception[0] = e; } } }); try { downloadThreadFuture.get(5, TimeUnit.SECONDS); } catch (TimeoutException ignored) { } if (!downloadThreadFuture.isDone()) { downloadThreadFuture.cancel(true); throw new Exception(IdeBundle.message("updates.timeout.error")); } if (exception[0] != null) throw exception[0]; return inputStreams[0]; }
protected static Document readDocumentCancelable(final ProgressIndicator indicator, String url) throws JDOMException, IOException { final HttpURLConnection urlConnection = HttpConfigurable.getInstance().openHttpConnection(url); Thread t = new Thread(new Runnable() { @Override public void run() { try { //noinspection InfiniteLoopStatement while (true) { if (indicator.isCanceled()) { urlConnection.disconnect(); } //noinspection BusyWait Thread.sleep(100); } } catch (InterruptedException ignored) { } } }); t.start(); try { urlConnection.setRequestProperty("accept", "application/xml"); InputStream inputStream = urlConnection.getInputStream(); try { return new SAXBuilder().build(inputStream); } finally { inputStream.close(); } } finally { t.interrupt(); } }