private void completeAuth(Object[] authSettings) { if (authSettings[1] != null) { client.setState((HttpState) authSettings[1]); client.getParams().setAuthenticationPreemptive(true); } }
client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials(AuthScope.ANY, credentials);
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); } }
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)); } }
@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()); } }
/** * Configure the client to use preemptive authentication (HTTP Basic Authentication only) */ public AbderaClient usePreemptiveAuthentication(boolean val) { client.getParams().setAuthenticationPreemptive(val); return this; }
@Override public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method) throws ProponoException { httpClient.getParams().setAuthenticationPreemptive(true); final String header = "Basic " + credentials; method.setRequestHeader("Authorization", header); } }
@Override public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method) throws ProponoException { httpClient.getParams().setAuthenticationPreemptive(true); method.setRequestHeader("Authorization", authToken); } }
private void completeAuth(Object[] authSettings) { if (authSettings[1] != null) { client.setState((HttpState) authSettings[1]); client.getParams().setAuthenticationPreemptive(true); } }
private void completeAuth(Object[] authSettings) { if (authSettings[1] != null) { client.setState((HttpState) authSettings[1]); client.getParams().setAuthenticationPreemptive(true); } }
private Credentials getCredentials(String username, String password){ client.getParams().setAuthenticationPreemptive(true); int domainIndex = username.indexOf('\\'); if (domainIndex > 0 && username.length() > domainIndex + 1) { return new NTCredentials( username.substring(domainIndex+1), password, "localhost", // TODO: resolve local host name username.substring(0, domainIndex)); } return new UsernamePasswordCredentials(username,password); }
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 HttpClient getHttpClient() { HttpClient client = new HttpClient(); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials( new AuthScope(host, Integer.valueOf(port), "realm"), new UsernamePasswordCredentials(username, password)); return client; }
public void setBasicCredentials(String username, String password) { getClient().getParams().setAuthenticationPreemptive(true); getClient().getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); }
private HttpClient getHttpClient() { HttpClient client = new HttpClient(); client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()); client.getState().setCredentials( new AuthScope(repositoryInfo.getHost(), repositoryInfo.getPort(), AuthScope.ANY_REALM), defaultcreds); return client; }
@Override public void afterPropertiesSet() throws Exception { if (getCredentials() != null) { getHttpClient().getState().setCredentials(getAuthScope(), getCredentials()); getHttpClient().getParams().setAuthenticationPreemptive(true); } }