/** * Sets the {@link Credentials credentials} for the given authentication * realm on the given host. The <code>null</code> realm signifies default * credentials for the given host, which should be used when no * {@link Credentials credentials} have been explictly supplied for the * challenging realm. The <code>null</code> host signifies default * credentials, which should be used when no {@link Credentials credentials} * have been explictly supplied for the challenging host. Any previous * credentials for the given realm on the given host will be overwritten. * * @param realm the authentication realm * @param host the host the realm belongs to * @param credentials the authentication {@link Credentials credentials} * for the given realm. * * @see #getCredentials(String, String) * @see #setProxyCredentials(String, String, Credentials) * * @deprecated use #setCredentials(AuthScope, Credentials) */ public synchronized void setCredentials(String realm, String host, Credentials credentials) { LOG.trace("enter HttpState.setCredentials(String, String, Credentials)"); credMap.put(new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME), credentials); }
/** * Sets the {@link Credentials credentials} for the given proxy authentication * realm on the given proxy host. The <code>null</code> proxy realm signifies * default credentials for the given proxy host, which should be used when no * {@link Credentials credentials} have been explictly supplied for the * challenging proxy realm. The <code>null</code> proxy host signifies default * credentials, which should be used when no {@link Credentials credentials} * have been explictly supplied for the challenging proxy host. Any previous * credentials for the given proxy realm on the given proxy host will be * overwritten. * * @param realm the authentication realm * @param proxyHost the proxy host * @param credentials the authentication credentials for the given realm * * @see #getProxyCredentials(AuthScope) * @see #setCredentials(AuthScope, Credentials) * * @deprecated use #setProxyCredentials(AuthScope, Credentials) */ public synchronized void setProxyCredentials( String realm, String proxyHost, Credentials credentials ) { LOG.trace("enter HttpState.setProxyCredentials(String, String, Credentials"); proxyCred.put(new AuthScope(proxyHost, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME), credentials); }
/** * Get the {@link Credentials credentials} for the proxy host with the given * authentication scope. * * If the <i>realm</i> exists on <i>host</i>, return the coresponding credentials. * If the <i>host</i> exists with a <tt>null</tt> <i>realm</i>, return the corresponding * credentials. * If the <i>realm</i> exists with a <tt>null</tt> <i>host</i>, return the * corresponding credentials. If the <i>realm</i> does not exist, return * the default Credentials. If there are no default credentials, return * <code>null</code>. * * @param realm the authentication realm * @param proxyHost the proxy host the realm is on * @return the credentials * @see #setProxyCredentials(String, String, Credentials) * * @deprecated use #getProxyCredentials(AuthScope) */ public synchronized Credentials getProxyCredentials(String realm, String proxyHost) { LOG.trace("enter HttpState.getCredentials(String, String"); return matchCredentials(this.proxyCred, new AuthScope(proxyHost, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME)); }
/** * Get the {@link Credentials credentials} for the given authentication scope on the * given host. * * If the <i>realm</i> exists on <i>host</i>, return the coresponding credentials. * If the <i>host</i> exists with a <tt>null</tt> <i>realm</i>, return the corresponding * credentials. * If the <i>realm</i> exists with a <tt>null</tt> <i>host</i>, return the * corresponding credentials. If the <i>realm</i> does not exist, return * the default Credentials. If there are no default credentials, return * <code>null</code>. * * @param realm the authentication realm * @param host the host the realm is on * @return the credentials * * @see #setCredentials(String, String, Credentials) * * @deprecated use #getCredentials(AuthScope) */ public synchronized Credentials getCredentials(String realm, String host) { LOG.trace("enter HttpState.getCredentials(String, String"); return matchCredentials(this.credMap, new AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME)); }
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);
return false; AuthScope authscope = new AuthScope( conn.getProxyHost(), conn.getProxyPort(), authscheme.getRealm(),
AuthScope authscope = new AuthScope( host, port, authscheme.getRealm(),
AuthScope authscope = new AuthScope( conn.getProxyHost(), conn.getProxyPort(), authscheme.getRealm(),
AuthScope authscope = new AuthScope( host, port, authscheme.getRealm(),
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)); } }
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { final String host = (String) stream.readObject(); final int port = stream.readInt(); final String realm = (String) stream.readObject(); final String scheme = (String) stream.readObject(); authScope_ = new AuthScope(host, port, realm, scheme); } }
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); }
/** * 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; }
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); }
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")); }
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; }
protected void initCredentials() { if (username != null && password != null) { AuthScope authscope = new AuthScope( getAuthHost() == null ? AuthScope.ANY_HOST : getAuthHost(), AuthScope.ANY_PORT); Credentials credentials = new UsernamePasswordCredentials(getUsername(), getPassword()); httpClient.getState().setCredentials(authscope, credentials); } }