Credentials credentials = createCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); client.getState().setProxyCredentials(scope, credentials);
private Credentials promptForProxyCredentials( final AuthScheme authScheme, final HttpParams params, final AuthScope authscope) { LOG.debug("Proxy credentials required"); Credentials creds = null; CredentialsProvider credProvider = (CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER); if (credProvider != null) { try { creds = credProvider.getCredentials( authScheme, authscope.getHost(), authscope.getPort(), true); } catch (CredentialsNotAvailableException e) { LOG.warn(e.getMessage()); } if (creds != null) { this.state.setProxyCredentials(authscope, creds); if (LOG.isDebugEnabled()) { LOG.debug(authscope + " new credentials given"); } } } else { LOG.debug("Proxy credentials provider not available"); } return creds; }
client.getHostConfiguration().setProxy(proxyHost, proxyPort); if (StringUtils.isNotBlank(proxyUser)) { client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxyUser, proxyPassword));
state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getNetworkProxyHttpsUser(), secureSettings.getSecureProperty(ConfigurationOptions.ES_NET_PROXY_HTTPS_PASS))); state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getNetworkProxyHttpUser(), secureSettings.getSecureProperty(ConfigurationOptions.ES_NET_PROXY_HTTP_PASS)));
state.setProxyCredentials(authscope, credentials);
state.setProxyCredentials(authscope, credentials);
private void checkProxy(Proxy proxy) { if (proxy != null) { client.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort()); if (proxy.getUserName() != null) { Credentials proxyCreds = new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword()); client.getState().setProxyCredentials(AuthScope.ANY, proxyCreds); } } }
/** * @param proxy * @param httpClient */ public static void setProxy(Proxy proxy, HttpClient httpClient) { if (proxy != null && httpClient != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting proxy with host " + proxy.getHost() + " and port " + proxy.getPort() + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort()); } httpClient.getHostConfiguration().setProxy(proxy.getHost(), proxy.getPort()); if (proxy.getUserName() != null && proxy.getPassword() != null) { httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword())); } } }
/** * Sets proxy authentication information. This method must be called before any * calls to the API if you require proxy authentication. * * @param proxyUsername Username to access proxy * @param proxyPassword Password to access proxy * @since 1.8 */ public void setProxyAuthenticationConfiguration(String proxyUsername, String proxyPassword) { httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxyUsername, proxyPassword)); }
/** * Sets proxy authentication information. This method must be called before any * calls to the API if you require proxy authentication. * * @param proxyUsername Username to access proxy * @param proxyPassword Password to access proxy */ public void setProxyAuthenticationConfiguration(String proxyUsername, String proxyPassword) { httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxyUsername, proxyPassword)); }
/** * Specify the auth credentials for the proxy server */ public AbderaClient setProxyCredentials(String host, int port, String realm, String scheme, Credentials credentials) { host = host != null ? host : AuthScope.ANY_HOST; port = port > -1 ? port : AuthScope.ANY_PORT; AuthScope scope = new AuthScope(host, port, realm != null ? realm : AuthScope.ANY_REALM, scheme != null ? scheme : AuthScope.ANY_SCHEME); client.getState().setProxyCredentials(scope, credentials); return this; }
@Override public HttpClient configureHttpClient(HttpClient client) { if (proxy) { client.getState().setProxyCredentials(AuthScope.ANY, this.credentials); } else { client.getState().setCredentials(AuthScope.ANY, this.credentials); } return client; }
private static InputStream requestDoc(URL url) throws IOException { HttpClient client = new HttpClient(); ProxyManager proxyManager = new ProxyManager(); ProxyHost proxy = proxyManager.getProxyHost(url); if (proxy != null) { LOG.debug("for server " + url + " using proxy: '" + proxy.getHostName() + "'"); } else { LOG.debug("for server " + url + " not using proxy!"); } client.getHostConfiguration().setProxyHost(proxy); client.getState().setProxyCredentials(AuthScope.ANY, proxyManager.getProxyCredentials(url)); GetMethod method = new GetMethod(url.toString()); client.executeMethod(method); return method.getResponseBodyAsStream(); }
HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(URIget); HostConfiguration hostCfg = new HostConfiguration(); HttpState state = client.getState(); //setting a proxy, for example: state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword())); hostCfg.setProxyHost(new ProxyHost(getProxyHost(), getProxyPort())); //method.getParams().setSoTimeout(timeout); for example a timeout client.executeMethod(hostCfg, method); //calling the server String resp = method.getResponseBodyAsString(); //the response body
public void configureHttpClient(HttpClient client) { Credentials credentials = new UsernamePasswordCredentials(username, password); if (proxy) { client.getState().setProxyCredentials(AuthScope.ANY, credentials); } else { client.getState().setCredentials(AuthScope.ANY, credentials); } }
public void configureHttpClient(HttpClient client) { Credentials credentials = new NTCredentials(username, password, host, domain); if (proxy) { client.getState().setProxyCredentials(AuthScope.ANY, credentials); } else { client.getState().setCredentials(AuthScope.ANY, credentials); } }
private void initHttpClient() { m_client = new HttpClient(); ProxyManager proxyManager = new ProxyManager(); ProxyHost proxy = proxyManager.getProxyHost(m_endpointUrl); if (proxy != null) { LOG.debug("for server " + getURL() + " using proxy: '" + proxy.getHostName() + "'"); } else { LOG.debug("for server " + getURL() + " not using proxy!"); } m_client.getHostConfiguration().setProxyHost(proxy); m_client.getState().setProxyCredentials(AuthScope.ANY, proxyManager.getProxyCredentials(getURL())); }
private void initHttpClient() { m_client = new HttpClient(); ProxyManager proxyManager = new ProxyManager(); ProxyHost proxy = proxyManager.getProxyHost(getURL()); if (proxy != null) { LOG.debug("for server " + getURL() + " using proxy: '" + proxy.getHostName() + "'"); } else { LOG.debug("for server " + getURL() + " not using proxy!"); } m_client.getHostConfiguration().setProxyHost(proxy); m_client.getState().setProxyCredentials(AuthScope.ANY, proxyManager.getProxyCredentials(getURL())); }
private HttpClient createHttpClientViaProxy() { if (!param.isUseProxyChain()) { return createHttpClient(); } httpConnManagerProxy = new MultiThreadedHttpConnectionManager(); setCommonManagerParams(httpConnManagerProxy); HttpClient clientProxy = new HttpClient(httpConnManagerProxy); clientProxy.getHostConfiguration().setProxy(param.getProxyChainName(), param.getProxyChainPort()); if (param.isUseProxyChainAuth()) { clientProxy.getState().setProxyCredentials(getAuthScope(param), getNTCredentials(param)); } return clientProxy; }
private void configureCredentials(final Config config, HttpClient client) { String username = config.get("http.basicauth.username"); String password = config.get("http.basicauth.password"); if (username != null && password != null) { Credentials defaultcreds = new UsernamePasswordCredentials(username, password); client.getState().setCredentials(AuthScope.ANY, defaultcreds); } String proxyUsername = config.get("http.proxy.username"); String proxyPassword = config.get("http.proxy.password"); if (proxyUsername != null && proxyPassword != null) { Credentials defaultcreds = new UsernamePasswordCredentials(proxyUsername, proxyPassword); client.getState().setProxyCredentials(AuthScope.ANY, defaultcreds); } } }