Credentials credentials = createCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); client.getState().setProxyCredentials(scope, credentials);
client.getHostConfiguration().setProxy(proxyHost, proxyPort); if (StringUtils.isNotBlank(proxyUser)) { client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxyUser, proxyPassword)); if (credentials != null) { client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, credentials);
hostconfig, this.params, (state == null ? getState() : state)); methodDirector.executeMethod(method); return method.getStatusCode();
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); } }
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); } }
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); } }
+ " setting proxy auth credentials"); HttpState state = client.getState(); if (state == null) { state = new HttpState();
+ " setting proxy auth credentials"); HttpState state = client.getState(); if (state == null) { state = new HttpState();
public static InputStream getInputStreamFromUrl(String url, String user, String password) { try { Pair<String, Integer> hostAndPort = validateUrl(url); HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager()); if ((user != null) && (password != null)) { httpclient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } // Execute the method. GetMethod method = new GetMethod(url); int statusCode = httpclient.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { s_logger.error("Failed to read from URL: " + url); return null; } return method.getResponseBodyAsStream(); } catch (Exception ex) { s_logger.error("Failed to read from URL: " + url); return null; } }
private void checkCredentials(String user, String password) { try { Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl); if ((user != null) && (password != null)) { client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } else { s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); } } catch (IllegalArgumentException iae) { errorString = iae.getMessage(); status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; inited = false; } }
/** * @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)); } }
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())); } } }
@Ignore @Test public void testRestAPI() throws IOException { HttpClient client = new HttpClient(); // To be avoided unless in debug mode Credentials defaultcreds = new UsernamePasswordCredentials("admin", "111111"); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, defaultcreds); PutMethod method = new PutMethod("http://localhost:8080/agent/api/36"); final HttpMethodParams params = new HttpMethodParams(); params.setParameter("action", "approve"); method.setParams(params); final int i = client.executeMethod(method); System.out.println(method.getResponseBodyAsString()); } }
public TestUtils() { this.adminHTTPClient = new HttpClient(); this.adminHTTPClient.getState().setCredentials(AuthScope.ANY, ADMIN_CREDENTIALS); this.adminHTTPClient.getParams().setAuthenticationPreemptive(true); }
private void setBasicAuth(String host, int port) { String basicAuth = ClientProperties.getBasicAuth(); if (Strings.isNullOrEmpty(basicAuth)) return; List<String> splits = Splitter.on(':').trimResults().splitToList(basicAuth); if (splits.size() < 2) return; String userName = splits.get(0); String passWord = splits.get(1); httpClient.getParams().setAuthenticationPreemptive(true); Credentials credentials = new UsernamePasswordCredentials(userName, passWord); AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM); httpClient.getState().setCredentials(authScope, credentials); }
public TestUtils() { this.httpClient = new HttpClient(); this.httpClient.getState().setCredentials(AuthScope.ANY, SUPER_ADMIN_CREDENTIALS); this.httpClient.getParams().setAuthenticationPreemptive(true); this.rest = new RestTestUtils(this); }
public HttpClient createHttpClient(HttpMethod httpMethodProxyRequest) { HttpClient client = new HttpClient(); if (userName != null) { //client.getParams().setAuthenticationPreemptive(true); httpMethodProxyRequest.setDoAuthentication(true); Credentials defaultcreds = new UsernamePasswordCredentials(userName, password); client.getState().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM), defaultcreds); } return client; }
private void configureCredentials() { if (server.getUsername() != null) { httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(server.getUsername(), server.getPassword()); httpClient.getState().setCredentials(AuthScope.ANY, defaultcreds); } }
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())); }