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); } }
private Credentials promptForCredentials( final AuthScheme authScheme, final HttpParams params, final AuthScope authscope) { LOG.debug("Credentials required"); Credentials creds = null; CredentialsProvider credProvider = (CredentialsProvider)params.getParameter(CredentialsProvider.PROVIDER); if (credProvider != null) { try { creds = credProvider.getCredentials( authScheme, authscope.getHost(), authscope.getPort(), false); } catch (CredentialsNotAvailableException e) { LOG.warn(e.getMessage()); } if (creds != null) { this.state.setCredentials(authscope, creds); if (LOG.isDebugEnabled()) { LOG.debug(authscope + " new credentials given"); } } } else { LOG.debug("Credentials provider not available"); } return creds; }
/** * Creates a copy of the given credentials scope. * * @since 3.0 */ public AuthScope(final AuthScope authscope) { super(); if (authscope == null) { throw new IllegalArgumentException("Scope may not be null"); } this.host = authscope.getHost(); this.port = authscope.getPort(); this.realm = authscope.getRealm(); this.scheme = authscope.getScheme(); }
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; }
/** * Set the basic credentials. You must have previously set the server and * port using setServer. * * @param username * @param password */ private void setBasicCredentials(String username, String password) { log.debug("server: " + server + " port: " + port + " u: '" + username + "' p '" + password + "'"); client.getState().setCredentials(new AuthScope(server, port), new UsernamePasswordCredentials(username, password)); }
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")); }
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);
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); } } }
private int executeDelete(String url) { LOGGER.info("Executed module delete: " + url); GetMethod method = new GetMethod(url); try { HttpState httpState = new HttpState(); httpState.setCredentials(new AuthScope(null, AuthScope.ANY_PORT), new UsernamePasswordCredentials("admin", "admin")); HttpClient httpClient = new HttpClient(); int statusCode = httpClient.executeMethod(null, method, httpState); LOGGER.info("Status code result for delete: " + statusCode); return statusCode; } catch (Throwable t) { LOGGER.log(Level.SEVERE, "Error: " + t.getMessage()); t.printStackTrace(); } finally { method.releaseConnection(); } throw new RuntimeException("Programmatic error. You shouldn't be here."); }
HttpClientParams clientParams = new HttpClientParams(); clientParams.setAuthenticationPreemptive(isPreemptiveAuthentication()); clientParams.setContentCharset(getContentCharSet()); clientParams.setParameter(HttpClientParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler( connectionRetryAttempts, false)); connMgr.setParams(connMgrParams); HttpClient httpClient = new HttpClient(clientParams, connMgr); httpClient.setHostConfiguration(hostConfig); AuthScope proxyAuthScope = new AuthScope(proxyHost, proxyPort); UsernamePasswordCredentials proxyCredentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword); httpClient.getState().setProxyCredentials(proxyAuthScope, proxyCredentials);
private HttpClient getClient() { if (httpClient == null) { final MultiThreadedHttpConnectionManager connManager = new MultiThreadedHttpConnectionManager(); httpClient = new HttpClient(connManager); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); if (useProxyAuthentication()) { httpClient.getState().setProxyCredentials( new AuthScope(proxyHost, proxyPort, AuthScope.ANY_REALM), createCredentials(proxyUserName, proxyPasswd)); httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, getUserAgent()); httpClient.getParams().setParameter(CredentialsProvider.PROVIDER, new IvyCredentialsProvider());
protected void setProxy(HttpClient client) { String host = System.getProperty("http.proxyHost"); String port = System.getProperty("http.proxyPort"); String user = System.getProperty("http.proxyUser"); String password = System.getProperty("http.proxyPassword"); if (host != null && port != null) { try { int portInteger = Integer.parseInt(port); client.getHostConfiguration().setProxy(host, portInteger); if (user != null && password != null) { client.getState().setProxyCredentials( new AuthScope(host, portInteger), new UsernamePasswordCredentials(user, password)); } } catch (NumberFormatException e) { logger.error("Proxy port not an integer", e); } } }
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); }
List authPrefs = new ArrayList(); authPrefs.add(AuthPolicy.NTLM); client.getState().setProxyCredentials(new AuthScope(null, proxyPort, null), new NTCredentials(user, password, "", domain)); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); if(user != null && password !=null) { authPrefs.add(AuthPolicy.BASIC); client.getState().setProxyCredentials(new AuthScope(null, proxyPort, null), new UsernamePasswordCredentials(user, password)); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
protected HttpClient doClientConnect() throws Exception { HttpState state = new HttpState(); if (getProxyUsername() != null) { Credentials credentials; if (isProxyNtlmAuthentication()) { credentials = new NTCredentials(getProxyUsername(), getProxyPassword(), getProxyHostname(), ""); } else { credentials = new UsernamePasswordCredentials(getProxyUsername(), getProxyPassword()); } AuthScope authscope = new AuthScope(getProxyHostname(), getProxyPort()); state.setProxyCredentials(authscope, credentials); } HttpClient client = new HttpClient(); client.setState(state); client.setHttpConnectionManager(getClientConnectionManager()); return client; }
/** * Constructor. * * @param metadataURL the URL to fetch the metadata * @param requestTimeout the time, in milliseconds, to wait for the metadata server to respond * * @throws MetadataProviderException thrown if the URL is not a valid URL or the metadata can not be retrieved from * the URL */ @Deprecated public HTTPMetadataProvider(String metadataURL, int requestTimeout) throws MetadataProviderException { super(); try { metadataURI = new URI(metadataURL); } catch (URISyntaxException e) { throw new MetadataProviderException("Illegal URL syntax", e); } HttpClientParams clientParams = new HttpClientParams(); clientParams.setSoTimeout(requestTimeout); httpClient = new HttpClient(clientParams); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(requestTimeout); authScope = new AuthScope(metadataURI.getHost(), metadataURI.getPort()); }
/** * @param host * @param port * @param realm * @param schema * @param username * @param password */ public void setBasicAuth(String host, int port, String realm, String schema, String username, String password) { httpState.setCredentials(new AuthScope("www.verisign.com", 443, realm, schema), new UsernamePasswordCredentials("username", "password")); authEnabled = true; }
/** * Enable NTLM authentication on http client * * @param httpClient HttpClient instance */ public static void addNTLM(HttpClient httpClient) { // disable preemptive authentication httpClient.getParams().setParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, false); // register the jcifs based NTLMv2 implementation AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, NTLMv2Scheme.class); ArrayList<String> authPrefs = new ArrayList<String>(); authPrefs.add(AuthPolicy.NTLM); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // make sure NTLM is always active needNTLM = true; // separate domain from username in credentials AuthScope authScope = new AuthScope(null, -1); NTCredentials credentials = (NTCredentials) httpClient.getState().getCredentials(authScope); if (credentials != null && credentials.getDomain() == null) { setCredentials(httpClient, credentials.getUserName(), credentials.getPassword()); } }
/** * 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; }
/** * 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); }