private void init(String host, int port, String userName, String password) { this.host = host; this.port = port; this.userName = userName; this.password = password; this.baseUrl = "http://" + host + ":" + port + "/kylin/api"; client = new HttpClient(); if (userName != null && password != null) { client.getParams().setAuthenticationPreemptive(true); Credentials creds = new UsernamePasswordCredentials(userName, password); client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), creds); } }
String proxyPassword, String nonProxyHosts) { HttpClient client = new HttpClient(); client.getHostConfiguration().setProxy(proxyHost, proxyPort); if (StringUtils.isNotBlank(proxyUser)) { client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxyUser, proxyPassword)); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, credentials);
/** * Adds an array of {@link Cookie HTTP cookies}. Cookies are added individually and * in the given array order. If any of the given cookies has already expired it will * not be added, but existing values will still be removed. * * @param cookies the {@link Cookie cookies} to be added * * @see #addCookie(Cookie) * * */ public synchronized void addCookies(Cookie[] cookies) { LOG.trace("enter HttpState.addCookies(Cookie[])"); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { this.addCookie(cookies[i]); } } }
private void addHttpAuth(Settings settings, SecureSettings secureSettings, Object[] authSettings) { if (StringUtils.hasText(settings.getNetworkHttpAuthUser())) { HttpState state = (authSettings[1] != null ? (HttpState) authSettings[1] : new HttpState()); authSettings[1] = state; state.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getNetworkHttpAuthUser(), secureSettings.getSecureProperty(ConfigurationOptions.ES_NET_HTTP_AUTH_PASS))); if (log.isDebugEnabled()) { log.info("Using detected HTTP Auth credentials..."); } } }
hostConfig.setProxy(proxyHost, proxyPort); proxyInfo = proxyInfo.concat(String.format(Locale.ROOT, "[%s proxy %s:%s]", (sslEnabled ? "HTTPS" : "HTTP"), proxyHost, proxyPort)); log.warn(String.format("HTTPS proxy user specified but no/empty password defined - double check the [%s] property", ConfigurationOptions.ES_NET_PROXY_HTTPS_PASS)); HttpState state = new HttpState(); state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getNetworkProxyHttpsUser(), secureSettings.getSecureProperty(ConfigurationOptions.ES_NET_PROXY_HTTPS_PASS))); log.warn(String.format("HTTP proxy user specified but no/empty password defined - double check the [%s] property", ConfigurationOptions.ES_NET_PROXY_HTTP_PASS)); HttpState state = new HttpState(); state.setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getNetworkProxyHttpUser(), secureSettings.getSecureProperty(ConfigurationOptions.ES_NET_PROXY_HTTP_PASS)));
method.getParams().setParameter("http.socket.timeout", DEFAULT_CONNECT_TIMEOUT_MILLIS > 0 ? DEFAULT_CONNECT_TIMEOUT_MILLIS : new Integer(30 * 1000)); HttpClient client = new HttpClient(); if (Util.fixEmptyAndTrim(name) != null && !isNoProxyHost(host, noProxyHost)) { client.getHostConfiguration().setProxy(name, port); Credentials credentials = createCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); client.getState().setProxyCredentials(scope, credentials);
private HttpClient createHttpClient() { HttpClient client = new HttpClient(); client.getParams().setSoTimeout(this.soTimeout); if (this.getProxyHost() != null) { client.getHostConfiguration().setProxy(this.proxyHost, this.proxyPort); if (this.proxyUsername != null && this.proxyPassword != null) { client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(this.proxyUsername, this.proxyPassword)); } } return client; } }
public String sendReport(Map<String, String> values) throws IOException { HttpClient httpClient = new HttpClient(); HostConfiguration hostConfiguration = new HostConfiguration(); if (!StringUtils.isBlank(proxy)) { hostConfiguration.setProxy(proxy, proxyPort); if (StringUtils.isNotBlank(user) && StringUtils.isNotBlank(password)) { httpClient.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); } } httpClient.setHostConfiguration(hostConfiguration); PostMethod method = new PostMethod(getSendUrl()); addHttpPostParams(values, method); int executeMethod = httpClient.executeMethod(method); LOGGER.info("HTTP result of report send POST: " + executeMethod); return IOUtils.toString(method.getResponseBodyAsStream()); }
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); } } }
public void start() { client = new HttpClient(); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(hostUrl, hostPort, "http"); client.setHostConfiguration(hostConfig); // Fix for non-buffereing large WAR files during deploy client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(userName, password); client.getState().setCredentials(new AuthScope(hostUrl, hostPort, AuthScope.ANY_REALM), defaultcreds); start = new GetMethod(startPath); stop = new GetMethod(stopPath); undeploy = new GetMethod(undeployPath); deploy = new PutMethod(deployPath); }
/** * @param username * @param password * @param httpClient */ public static void setCredentials(String username, String password, HttpClient httpClient) { if (username != null && password != null && httpClient != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting credentials with username " + username + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort()); } httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getState().setCredentials( new AuthScope(httpClient.getHostConfiguration().getHost(), httpClient.getHostConfiguration().getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password)); } }
public void init() { client = new HttpClient(new MultiThreadedHttpConnectionManager()); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); client.getParams().setCookiePolicy(CookiePolicy.RFC_2109); client.setState(httpState); if (authPrefs != null) { client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); } if (proxyHost != null) { client.getHostConfiguration().setProxy(proxyHost, proxyPort); if (proxyUserPassword != null) { httpState.setProxyCredentials(new AuthScope(proxyHost, proxyPort), proxyUserPassword); } } }
/** * Constructor * * @param hostName Chargify domain * @param apiToken Chargify password */ public ChargifyWrapper(String hostName, String apiToken) { setDomain(hostName); setApiToken(apiToken); client = new HttpClient(); NetUtil.configureHttpProxy(client); client.getHostConfiguration().setHost(getDomain()); client.getState().setCredentials( new AuthScope(getDomain() + "." + CHARGIFY_ENDPOINT, 443, CHARGIFY_AUTH_REALM), new UsernamePasswordCredentials(getApiToken(), "x") ); }
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 resetCredentials() { client.getState().clearCredentials(); if (user != null && password != null) { AuthScope authscope = AuthScope.ANY; Credentials credentials = new UsernamePasswordCredentials(user, password); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(authscope, credentials); } else { client.getParams().setAuthenticationPreemptive(false); } }
public void init() { ParameterCheck.mandatory("baseUrl", baseUrl); StringBuilder sb = new StringBuilder(); sb.append(baseUrl + "/admin/cores"); this.adminUrl = sb.toString(); httpClient = httpClientFactory.getHttpClient(); HttpClientParams params = httpClient.getParams(); params.setBooleanParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true); httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin")); }
"Found 'http.proxyHost' Java System property. Using it as proxy server. Port: " + proxyPort); HostConfiguration hostConfig = client.getHostConfiguration(); hostConfig.setProxy(proxyHost, proxyPort); + " setting proxy auth credentials"); HttpState state = client.getState(); if (state == null) { state = new HttpState(); client.setState(state); Credentials credentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); state.setProxyCredentials(authscope, credentials);
/** * @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())); } } }
public void setAlternateAuth(String host, int port, String username, String password, List<String> schemaList) { httpState.setCredentials(new AuthScope("www.verisign.com", 443), new UsernamePasswordCredentials("username", "password")); authEnabled = true; client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemaList); }
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; }