DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials( new AuthScope("localhost", 443), new UsernamePasswordCredentials("username", "password"));
private static void addProxyCredentials(ApacheHttpTransport transport, String protocol) { Preconditions.checkArgument(protocol.equals("http") || protocol.equals("https")); String proxyHost = System.getProperty(protocol + ".proxyHost"); String proxyUser = System.getProperty(protocol + ".proxyUser"); String proxyPassword = System.getProperty(protocol + ".proxyPassword"); if (proxyHost == null || proxyUser == null || proxyPassword == null) { return; } String defaultProxyPort = protocol.equals("http") ? "80" : "443"; int proxyPort = Integer.parseInt(System.getProperty(protocol + ".proxyPort", defaultProxyPort)); DefaultHttpClient httpClient = (DefaultHttpClient) transport.getHttpClient(); httpClient .getCredentialsProvider() .setCredentials( new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); }
DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials( new AuthScope("PROXY HOST", 8080), new UsernamePasswordCredentials("username", "password")); HttpHost targetHost = new HttpHost("TARGET HOST", 443, "https"); HttpHost proxy = new HttpHost("PROXY HOST", 8080); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
&& config.getProxyPassword() != null) { httpclient.getCredentialsProvider().setCredentials( new AuthScope(proxyHost, proxyPort), new NTCredentials(config.getProxyUsername(),
@Override protected HttpContext createHttpContext() { HttpContext context = new BasicHttpContext(); context.setAttribute( ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes()); context.setAttribute( ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs()); context.setAttribute( ClientContext.COOKIE_STORE, getCookieStore()); context.setAttribute( ClientContext.CREDS_PROVIDER, getCredentialsProvider()); return context; }
public void configure(DefaultHttpClient httpClient, SolrParams config) { super.configure(httpClient, config); logger.info("Setting up SPNego auth..."); //Enable only SPNEGO authentication scheme. final AuthSchemeRegistry registry = new AuthSchemeRegistry(); registry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, false)); httpClient.setAuthSchemes(registry); // Get the credentials from the JAAS configuration rather than here final Credentials useJaasCreds = new Credentials() { public String getPassword() { return null; } public Principal getUserPrincipal() { return null; } }; final SolrPortAwareCookieSpecFactory cookieFactory = new SolrPortAwareCookieSpecFactory(); httpClient.getCookieSpecs().register(cookieFactory.POLICY_NAME, cookieFactory); httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookieFactory.POLICY_NAME); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, useJaasCreds); httpClient.addRequestInterceptor(bufferedEntityInterceptor); }
public BrocadeVcsApi(String address, String username, String password) { _host = address; _adminuser = username; _adminpass = password; _client = new DefaultHttpClient(); _client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(_adminuser, _adminpass)); }
DefaultHttpClient httpclient = new DefaultHttpClient(); // register ntlm auth scheme httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); httpclient.getCredentialsProvider().setCredentials( // Limit the credentials only to the specified domain and port new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), // Specify credentials, most of the time only user/pass is needed new NTCredentials(username, password, "", "") ); HttpUriRequest httpget = new HttpGet(your_URL); HttpResponse response = httpclient.execute(httpget); String responseBody = EntityUtils.toString(response.getEntity()); Log.i(tag,"responseBody =>>>>>>>>>>"+responseBody);
client.getCredentialsProvider().setCredentials( new AuthScope(null, -1), new UsernamePasswordCredentials(mUsername, mPassword));
private static HttpResponse executeRequestWithAuth( final DefaultHttpClient client, final HttpUriRequest method, final Credentials credentials ) throws IOException, ClientProtocolException { client.getCredentialsProvider().setCredentials( AuthScope.ANY, credentials ); final BasicHttpContext localcontext = new BasicHttpContext(); // Generate BASIC scheme object and stick it to the local // execution context final BasicScheme basicAuth = new BasicScheme(); localcontext.setAttribute( "preemptive-auth", basicAuth ); // System.out.println( "cookies: " + method.getParams().getCookiePolicy() ); //method.getParams().setCookiePolicy(CookiePolicy.RFC_2109); return client.execute( method, localcontext ); }
protected DefaultHttpClient getClient() { if (httpClient == null) { if (nmsUrl.getSchema().equalsIgnoreCase("http")) { httpClient = getHttpClient(); } else { httpClient = getHttpsClient(); } AuthScope authScope = new AuthScope(nmsUrl.getHost(), nmsUrl.getPort(), AuthScope.ANY_SCHEME, "basic"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(nmsUrl.getUsername(), nmsUrl.getPassword()); httpClient.getCredentialsProvider().setCredentials(authScope, credentials); } return httpClient; }
client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, pass));
&& config.getProxyPassword() != null) { httpclient.getCredentialsProvider().setCredentials( new AuthScope(proxyHost, proxyPort), new NTCredentials(config.getProxyUsername(),
HttpParams params = new BasicHttpParams(); params.setParameter(AuthPNames.PROXY_AUTH_PREF, getClientAuthPrefs()); DefaultHttpClient httpclient = new DefaultHttpClient(cm, params); httpclient.getCredentialsProvider().setCredentials( new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPass));
public SyncopeBackingEngine(String address, String version, String adminUser, String adminPassword) { this.address = address; version2 = version != null && (version.equals("2.x") || version.equals("2")); client = new DefaultHttpClient(); Credentials creds = new UsernamePasswordCredentials(adminUser, adminPassword); client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); }
/** * Clear any user credentials that have been set for this client. */ public void clearCredentials() { client.getCredentialsProvider().clear(); doAuthentication = false; }
public void setProxy(DefaultHttpClient httpclient) { final String PROXY_IP = "<insert your IP here>"; final int PROXY_PORT = <insert_PROXY_PORT#>; httpclient.getCredentialsProvider().setCredentials( new AuthScope(PROXY_IP, PROXY_PORT), new UsernamePasswordCredentials( "username", "password")); HttpHost proxy = new HttpHost(PROXY_IP, PROXY_PORT); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }
DefaultHttpClient httpclient = new DefaultHttpClient(); HttpHost proxy = new HttpHost("myproxy.com", 9191); httpclient.getCredentialsProvider().setCredentials( new AuthScope(PROXY, PROXY_PORT), new UsernamePasswordCredentials("username", "password")); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
try { Credentials credentials = new UsernamePasswordCredentials("admin", "password"); //-u admin:password DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); HttpPut put = new HttpPut("http://localhost:8080/my-server/file.ext"); //-X PUT put.setEntity(new FileEntity(new File("/absolute/path/file/to/upload/file.ext"), "image/png")); //@ - absolute path httpClient.execute(put); } catch(Exception e) { //-f, fail silently }
DefaultHttpClient httpclient = new DefaultHttpClient(); ResponseHandler<String> responseHandler = new BasicResponseHandler(); httpclient.getCredentialsProvider().setCredentials( new AuthScope("localhost", 8080), new UsernamePasswordCredentials("username", "password")); HttpGet httpget = new HttpGet(urlStr); System.out.println("executing request" + httpget.getRequestLine()); String response = httpclient.execute(httpget, responseHandler); System.out.println("Response :: " + response);