List of usage examples for org.apache.http.impl.auth BasicScheme BasicScheme
public BasicScheme()
From source file:org.gradle.internal.resource.transport.http.HttpClientConfigurer.java
private void configureCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials) { String username = credentials.getUsername(); if (username != null && username.length() > 0) { useCredentials(httpClient, credentials, AuthScope.ANY_HOST, AuthScope.ANY_PORT); // Use preemptive authorisation if no other authorisation has been established httpClient.addRequestInterceptor(new PreemptiveAuth(new BasicScheme()), 0); }/*from w ww . jav a 2 s . c o m*/ }
From source file:com.ccreanga.bitbucket.rest.client.http.BitBucketHttpExecutor.java
public BitBucketHttpExecutor(String baseUrl, BitBucketCredentials credentials) { this.baseUrl = baseUrl; HttpHost targetHost = HttpHost.create(baseUrl); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(5);//from www. j a v a 2 s .co m connectionManager.setDefaultMaxPerRoute(4); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(targetHost), new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword())); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context = HttpClientContext.create(); context.setCredentialsProvider(credentialsProvider); context.setAuthCache(authCache); httpClient = HttpClients.custom().setConnectionManager(connectionManager) .setDefaultCredentialsProvider(credentialsProvider).build(); }
From source file:magicware.scm.redmine.tools.RedmineClient.java
public void fillBasicAuth(String userName, String base64Pwd) { // Basic?/*from w w w . jav a 2s .c om*/ httpclient.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(userName, StringUtils.isEmpty(base64Pwd) ? UUID.randomUUID().toString() : new String(Base64.decodeBase64(base64Pwd)))); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); }
From source file:neembuu.release1.httpclient.NHttpClient.java
public static DefaultHttpClient getNewInstance() { DefaultHttpClient new_httpClient = null; new_httpClient = new DefaultHttpClient(); GlobalTestSettings.ProxySettings proxySettings = GlobalTestSettings.getGlobalProxySettings(); HttpContext context = new BasicHttpContext(); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", new PlainSocketFactory(), 80)); try {// ww w . j a v a 2 s . c o m KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); schemeRegistry.register(new Scheme("https", new SSLSocketFactory(keyStore), 8080)); } catch (Exception a) { a.printStackTrace(System.err); } context.setAttribute(ClientContext.SCHEME_REGISTRY, schemeRegistry); context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, new BasicScheme()/*file.httpClient.getAuthSchemes()*/); context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, new_httpClient.getCookieSpecs()/*file.httpClient.getCookieSpecs()*/ ); BasicCookieStore basicCookieStore = new BasicCookieStore(); context.setAttribute(ClientContext.COOKIE_STORE, basicCookieStore/*file.httpClient.getCookieStore()*/); context.setAttribute(ClientContext.CREDS_PROVIDER, new BasicCredentialsProvider()/*file.httpClient.getCredentialsProvider()*/); HttpConnection hc = new DefaultHttpClientConnection(); context.setAttribute(ExecutionContext.HTTP_CONNECTION, hc); //System.out.println(file.httpClient.getParams().getParameter("http.useragent")); HttpParams httpParams = new BasicHttpParams(); if (proxySettings != null) { AuthState as = new AuthState(); as.setCredentials(new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); as.setAuthScope(AuthScope.ANY); as.setAuthScheme(new BasicScheme()); httpParams.setParameter(ClientContext.PROXY_AUTH_STATE, as); httpParams.setParameter("http.proxy_host", new HttpHost(proxySettings.host, proxySettings.port)); } new_httpClient = new DefaultHttpClient( new SingleClientConnManager(httpParams/*file.httpClient.getParams()*/, schemeRegistry), httpParams/*file.httpClient.getParams()*/); if (proxySettings != null) { new_httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(proxySettings.userName, proxySettings.password)); } return new_httpClient; }
From source file:kuona.jenkins.analyser.JenkinsClient.java
/** * Create an authenticated Jenkins HTTP client * * @param uri Location of the jenkins server (ex. http://localhost:8080) * @param username Username to use when connecting * @param password Password or auth token to use when connecting *///w w w . j a v a 2s.c o m public JenkinsClient(Project project, URI uri, String username, String password) { this(project, uri); if (isNotBlank(username)) { CredentialsProvider provider = client.getCredentialsProvider(); AuthScope scope = new AuthScope(uri.getHost(), uri.getPort(), "realm"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); provider.setCredentials(scope, credentials); localContext = new BasicHttpContext(); localContext.setAttribute("preemptive-auth", new BasicScheme()); client.addRequestInterceptor(new PreemptiveAuth(), 0); } }
From source file:kuona.client.JenkinsHttpClient.java
/** * Create an authenticated Jenkins HTTP client * * @param uri Location of the jenkins server (ex. http://localhost:8080) * @param username Username to use when connecting * @param password Password or auth token to use when connecting *//*from w ww . ja v a 2 s .c o m*/ public JenkinsHttpClient(Project project, URI uri, String username, String password) { this(project, uri); if (isNotBlank(username)) { CredentialsProvider provider = client.getCredentialsProvider(); AuthScope scope = new AuthScope(uri.getHost(), uri.getPort(), "realm"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); provider.setCredentials(scope, credentials); localContext = new BasicHttpContext(); localContext.setAttribute("preemptive-auth", new BasicScheme()); client.addRequestInterceptor(new PreemptiveAuth(), 0); } }
From source file:securitytools.veracode.VeracodeAsyncClient.java
/** * Constructs a new asynchronous VeracodeClient using the specified * configuration./*from www. j a v a 2 s.com*/ * * @param credentials Credentials used to access Veracode services. * @param clientConfiguration Client configuration for options such as proxy * settings, user-agent header, and network timeouts. */ public VeracodeAsyncClient(VeracodeCredentials credentials, ClientConfiguration clientConfiguration) { this.clientConfiguration = clientConfiguration; CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(TARGET), credentials); AuthCache authCache = new BasicAuthCache(); authCache.put(TARGET, new BasicScheme()); context = HttpClientContext.create(); context.setCredentialsProvider(credentialsProvider); context.setAuthCache(authCache); try { client = HttpClientFactory.buildAsync(clientConfiguration); } catch (NoSuchAlgorithmException nsae) { throw new VeracodeClientException(nsae.getMessage(), nsae); } }
From source file:net.homelinux.penecoptero.android.citybikes.app.RESTHelper.java
private static DefaultHttpClient setCredentials(DefaultHttpClient httpclient, String url, String username, String password) throws HttpException, IOException { HttpHost targetHost = new HttpHost(url); final UsernamePasswordCredentials access = new UsernamePasswordCredentials(username, password); httpclient.getCredentialsProvider()//w w w . j a va 2 s .com .setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), access); httpclient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { authState.setAuthScheme(new BasicScheme()); authState.setCredentials(access); } } }, 0); return httpclient; }
From source file:com.consol.citrus.http.client.BasicAuthClientHttpRequestFactory.java
/** * Construct the client factory bean with user credentials. */// w ww . j a v a 2 s .com public HttpComponentsClientHttpRequestFactory getObject() throws Exception { Assert.notNull(credentials, "User credentials not set properly!"); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient) { @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { // we have to use preemptive authentication // therefore add some basic auth cache to the local context AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(new HttpHost(authScope.getHost(), authScope.getPort(), "http"), basicAuth); authCache.put(new HttpHost(authScope.getHost(), authScope.getPort(), "https"), basicAuth); BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); return localcontext; } }; if (httpClient instanceof AbstractHttpClient) { ((AbstractHttpClient) httpClient).getCredentialsProvider().setCredentials(authScope, credentials); } else { log.warn("Unable to set username password credentials for basic authentication, " + "because nested HttpClient implementation does not support a credentials provider!"); } return requestFactory; }
From source file:cz.zcu.kiv.eegdatabase.logic.util.BasicAuthHttpClient.java
@Override protected HttpContext createHttpContext() { HttpContext context = super.createHttpContext(); AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); authCache.put(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); return context; }