List of usage examples for org.apache.http.impl.auth BasicScheme BasicScheme
public BasicScheme()
From source file:com.sinfonier.util.JSonUtils.java
public static void sendPostDucksBoard(Map<String, Object> json, String url, String apiKey) { HttpClient httpClient = new DefaultHttpClient(); Gson gson = new GsonBuilder().create(); String payload = gson.toJson(json); HttpPost post = new HttpPost(url); post.setEntity(new ByteArrayEntity(payload.getBytes(Charset.forName("UTF-8")))); post.setHeader("Content-type", "application/json"); try {/*from ww w . j a v a 2 s .co m*/ post.setHeader(new BasicScheme().authenticate(new UsernamePasswordCredentials(apiKey, "x"), post)); } catch (AuthenticationException e) { e.printStackTrace(); } try { HttpResponse response = httpClient.execute(post); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.esri.geoportal.commons.utils.HttpClientContextBuilder.java
/** * Creates client context./*from w w w . j a v a 2 s .c o m*/ * @param url url * @param cred credentials * @return client context */ public static HttpClientContext createHttpClientContext(URL url, SimpleCredentials cred) { HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(cred.getUserName(), cred.getPassword())); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); // Add AuthCache to the execution context HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); return context; }
From source file:org.siddhiesb.transport.http.conn.ProxyAuthenticator.java
public void authenticatePreemptively(final HttpRequest request, final HttpContext context) throws ProtocolException { BasicScheme basicScheme = new BasicScheme(); basicScheme.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm=\"proxy\"")); Header authresp = basicScheme.authenticate(proxycreds, request, context); request.addHeader(authresp);//from w w w.j ava2 s. c om }
From source file:projekat.rest_client.HttpComponentsClientHttpRequestFactoryBasicAuth.java
private HttpContext createHttpContext() { // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth);/*from w ww. j ava 2s .co m*/ // Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); return localcontext; }
From source file:org.eclipse.aether.transport.http.AuthSchemePool.java
public synchronized AuthScheme get() { AuthScheme authScheme = null;/*from ww w . j av a 2 s.c o m*/ if (!authSchemes.isEmpty()) { authScheme = authSchemes.removeLast(); } else if (AuthPolicy.BASIC.equalsIgnoreCase(schemeName)) { authScheme = new BasicScheme(); } return authScheme; }
From source file:org.springframework.cloud.stream.binder.rabbit.admin.RabbitManagementUtils.java
public static RestTemplate buildRestTemplate(String adminUri, String user, String password) { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); // Set up pre-emptive basic Auth because the rabbit plugin doesn't currently support challenge/response for PUT // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local; from the apache docs... // auth cache BasicScheme basicAuth = new BasicScheme(); URI uri;/*w w w. j a v a 2 s . co m*/ try { uri = new URI(adminUri); } catch (URISyntaxException e) { throw new RabbitAdminException("Invalid URI", e); } authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth); // Add AuthCache to the execution context final HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient) { @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { return localContext; } }); restTemplate.setMessageConverters( Collections.<HttpMessageConverter<?>>singletonList(new MappingJackson2HttpMessageConverter())); return restTemplate; }
From source file:com.cloudhopper.httpclient.util.PreemptiveBasicAuthHttpRequestInterceptor.java
public PreemptiveBasicAuthHttpRequestInterceptor() { this.basicAuthScheme = new BasicScheme(); this.credentials = null; }
From source file:com.impetus.client.couchdb.CouchDBUtils.java
/** * Gets the context.//from ww w .j a va 2 s. co m * * @param httpHost * the http host * @return the context */ public static HttpContext getContext(HttpHost httpHost) { AuthCache authCache = new BasicAuthCache(); authCache.put(httpHost, new BasicScheme()); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, authCache); return context; }
From source file:com.udps.hive.jdbc.HttpBasicAuthInterceptor.java
public HttpBasicAuthInterceptor(String username, String password) { if (username != null) { credentials = new UsernamePasswordCredentials(username, password); }// ww w. j a va2 s.c o m authScheme = new BasicScheme(); }
From source file:org.apache.ambari.view.hive.client.HttpBasicAuthInterceptor.java
public HttpBasicAuthInterceptor(String username, String password, CookieStore cookieStore, String cn, boolean isSSL, Map<String, String> additionalHeaders) { super(cookieStore, cn, isSSL, additionalHeaders); this.authScheme = new BasicScheme(); if (username != null) { this.credentials = new UsernamePasswordCredentials(username, password); }/*ww w . ja v a 2s . com*/ }