List of usage examples for org.apache.http.impl.client BasicCredentialsProvider BasicCredentialsProvider
public BasicCredentialsProvider()
From source file:org.eclipse.cft.server.core.internal.client.RestUtils.java
public static ClientHttpRequestFactory createRequestFactory(HttpProxyConfiguration httpProxyConfiguration, boolean trustSelfSignedCerts, boolean disableRedirectHandling) { HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties(); if (trustSelfSignedCerts) { httpClientBuilder.setSslcontext(buildSslContext()); httpClientBuilder.setHostnameVerifier(BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); }/*www . j a v a2 s . co m*/ if (disableRedirectHandling) { httpClientBuilder.disableRedirectHandling(); } if (httpProxyConfiguration != null) { HttpHost proxy = new HttpHost(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort()); httpClientBuilder.setProxy(proxy); if (httpProxyConfiguration.isAuthRequired()) { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials( new AuthScope(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort()), new UsernamePasswordCredentials(httpProxyConfiguration.getUsername(), httpProxyConfiguration.getPassword())); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); httpClientBuilder.setRoutePlanner(routePlanner); } HttpClient httpClient = httpClientBuilder.build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient); return requestFactory; }
From source file:org.springframework.xd.shell.security.SecuredShellAccessWithSslTest.java
@Test public void testSpringXDTemplate() throws Exception { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "whosThere")); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider) .setSSLSocketFactory(new SSLConnectionSocketFactory(new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build())) .build());/*from w w w . j ava2 s .c om*/ SpringXDTemplate template = new SpringXDTemplate(requestFactory, new URI("https://localhost:" + adminPort)); PagedResources<ModuleDefinitionResource> moduleDefinitions = template.moduleOperations() .list(RESTModuleType.sink); assertThat(moduleDefinitions.getLinks().size(), greaterThan(0)); }
From source file:fr.pilato.elasticsearch.crawler.fs.client.ElasticsearchClient.java
private ElasticsearchClient(List<Node> nodes, String username, String password) { List<HttpHost> hosts = new ArrayList<>(nodes.size()); for (Node node : nodes) { hosts.add(new HttpHost(node.getHost(), node.getPort(), node.getScheme().toLowerCase())); }/*from w w w. j a v a 2 s . c o m*/ RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()])); if (username != null) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); builder.setHttpClientConfigCallback( httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); } client = builder.build(); }
From source file:org.opennms.opennms.pris.plugins.defaults.source.HttpRequisitionSource.java
@Override public Object dump() throws Exception { Requisition requisition = null;// w w w .j av a 2s . c o m if (getUrl() != null) { HttpClientBuilder builder = HttpClientBuilder.create(); // If username and password was found, inject the credentials if (getUserName() != null && getPassword() != null) { CredentialsProvider provider = new BasicCredentialsProvider(); // Create the authentication scope AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM); // Create credential pair UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(getUserName(), getPassword()); // Inject the credentials provider.setCredentials(scope, credentials); // Set the default credentials provider builder.setDefaultCredentialsProvider(provider); } HttpClient client = builder.build(); HttpGet request = new HttpGet(getUrl()); HttpResponse response = client.execute(request); try { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); JAXBContext jaxbContext = JAXBContext.newInstance(Requisition.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); requisition = (Requisition) jaxbUnmarshaller.unmarshal(bufferedReader); } catch (JAXBException e) { LOGGER.error("The response did not contain a valid requisition as xml.", e); } LOGGER.debug("Got Requisition {}", requisition); } else { LOGGER.error("Parameter requisition.url is missing in requisition.properties"); } if (requisition == null) { LOGGER.error("Requisition is null for unknown reasons"); return null; } LOGGER.info("HttpRequisitionSource delivered for requisition '{}'", requisition.getNodes().size()); return requisition; }
From source file:com.jfrog.bintray.client.impl.HttpClientConfigurator.java
public HttpClientConfigurator() { builder.setUserAgent(BintrayClient.USER_AGENT); credsProvider = new BasicCredentialsProvider(); }
From source file:org.apache.jena.fuseki.embedded.TestFusekiTestAuth.java
@Test public void testServer_auth() { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(USER, PASSWORD); credsProvider.setCredentials(AuthScope.ANY, credentials); HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) { }// w w w. ja va 2 s. c om }
From source file:org.nuxeo.connect.registration.RegistrationHelper.java
protected static HttpClientContext getHttpClientContext(String url, String login, String password) { HttpClientContext context = HttpClientContext.create(); // Set credentials provider CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); if (login != null) { Credentials ba = new UsernamePasswordCredentials(login, password); credentialsProvider.setCredentials(AuthScope.ANY, ba); }/*from w w w . ja v a 2 s. co m*/ context.setCredentialsProvider(credentialsProvider); // Create AuthCache instance for preemptive authentication AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); try { authCache.put(URIUtils.extractHost(new URI(url)), basicAuth); } catch (URISyntaxException e) { throw new RuntimeException(e); } context.setAuthCache(authCache); // Create request configuration RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setConnectTimeout(10000); // Configure the http proxy if needed ProxyHelper.configureProxyIfNeeded(requestConfigBuilder, credentialsProvider, url); context.setRequestConfig(requestConfigBuilder.build()); return context; }
From source file:com.sulacosoft.bitcoindconnector4j.BitcoindApiHandler.java
public BitcoindApiHandler(String host, int port, String protocol, String uri, String username, String password) {//from w ww. j a v a 2s .c o m this.uri = uri; httpClient = HttpClients.createDefault(); targetHost = new HttpHost(host, port, protocol); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(username, password)); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setAuthCache(authCache); }
From source file:org.codice.alliance.nsili.endpoint.requests.FtpDestinationSink.java
@Override public void writeFile(InputStream fileData, long size, String name, String contentType, List<Metacard> metacards) throws IOException { CloseableHttpClient httpClient = null; String urlPath = protocol + "://" + fileLocation.host_name + ":" + port + "/" + fileLocation.path_name + "/" + name;// w w w .j a va2 s. c o m LOGGER.debug("Writing ordered file to URL: {}", urlPath); try { HttpPut putMethod = new HttpPut(urlPath); putMethod.addHeader(HTTP.CONTENT_TYPE, contentType); HttpEntity httpEntity = new InputStreamEntity(fileData, size); putMethod.setEntity(httpEntity); if (StringUtils.isNotEmpty(fileLocation.user_name) && fileLocation.password != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(fileLocation.host_name, port), new UsernamePasswordCredentials(fileLocation.user_name, fileLocation.password)); httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); } else { httpClient = HttpClients.createDefault(); } httpClient.execute(putMethod); fileData.close(); putMethod.releaseConnection(); } finally { if (httpClient != null) { httpClient.close(); } } }
From source file:securitytools.veracode.VeracodeAsyncClient.java
/** * Constructs a new asynchronous VeracodeClient using the specified * configuration./* w w w . j a va 2 s . c o m*/ * * @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); } }