List of usage examples for org.apache.http.auth AuthScope ANY
AuthScope ANY
To view the source code for org.apache.http.auth AuthScope ANY.
Click Source Link
From source file:com.liferay.jenkins.tools.RemoteStringGetter.java
@Override public String getString(String url) throws Exception { url = convertURL(url);/*from ww w . jav a 2 s. co m*/ logger.debug("Fetching string from {}", url); CredentialsProvider provider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(username, password); provider.setCredentials(AuthScope.ANY, credentials); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout).build(); HttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider) .setDefaultRequestConfig(requestConfig).build(); HttpResponse httpResponse = httpClient.execute(new HttpGet(url)); int statusCode = httpResponse.getStatusLine().getStatusCode(); logger.debug("Successfully fetched {}", url); return IOUtils.toString(httpResponse.getEntity().getContent(), Charset.defaultCharset()); }
From source file:org.wildfly.test.integration.elytron.http.PasswordMechTestBase.java
@Test public void testSuccess() throws Exception { HttpGet request = new HttpGet(new URI(url.toExternalForm() + "role1")); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user1", "password1"); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, credentials); try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider) .build()) {/*from w w w .ja v a2s. c o m*/ try (CloseableHttpResponse response = httpClient.execute(request)) { int statusCode = response.getStatusLine().getStatusCode(); assertEquals("Unexpected status code in HTTP response.", SC_OK, statusCode); assertEquals("Unexpected content of HTTP response.", SimpleServlet.RESPONSE_BODY, EntityUtils.toString(response.getEntity())); } } }
From source file:com.imagesleuth.imagesleuthclient2.Getter.java
public Getter(String url, String user, String password) { Test.testNull(url);//from w ww .ja v a 2 s.c o m Test.testNull(user); Test.testNull(password); this.url = url; harray.add(new BasicHeader("Authorization", "Basic " + Base64.encodeBase64String((user + ":" + password).getBytes()))); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password); credsProvider.setCredentials(AuthScope.ANY, credentials); requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(30000).build(); }
From source file:com.microsoft.azure.hdinsight.common.task.YarnHistoryTask.java
public YarnHistoryTask(@NotNull IClusterDetail clusterDetail, @NotNull String path, @NotNull FutureCallback<String> callback) { super(callback); this.clusterDetail = clusterDetail; this.path = path; try {/*from ww w.java 2 s .co m*/ credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword())); } catch (HDIException e) { e.printStackTrace(); } }
From source file:org.fcrepo.camel.FcrepoHttpClientBuilder.java
/** * Build an HttpClient/* w w w. j a v a 2 s. com*/ * * @return an HttpClient */ public CloseableHttpClient build() { if (isBlank(username) || isBlank(password)) { return HttpClients.createDefault(); } else { LOGGER.debug("Accessing fcrepo with user credentials"); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); AuthScope scope = null; if (isBlank(host)) { scope = new AuthScope(AuthScope.ANY); } else { scope = new AuthScope(new HttpHost(host)); } credsProvider.setCredentials(scope, new UsernamePasswordCredentials(username, password)); return HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); } }
From source file:org.fcrepo.client.FcrepoHttpClientBuilder.java
/** * Build an HttpClient// ww w . j a va2 s. co m * * @return an HttpClient */ public CloseableHttpClient build() { if (isBlank(username) || isBlank(password)) { return HttpClients.createSystem(); } else { LOGGER.debug("Accessing fcrepo with user credentials"); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); AuthScope scope = null; if (isBlank(host)) { scope = new AuthScope(AuthScope.ANY); } else { scope = new AuthScope(new HttpHost(host)); } credsProvider.setCredentials(scope, new UsernamePasswordCredentials(username, password)); return HttpClients.custom().setDefaultCredentialsProvider(credsProvider).useSystemProperties().build(); } }
From source file:org.opencastproject.remotetest.server.DigestAuthenticationTest.java
@Test public void testDigestAuthenticatedGet() throws Exception { UsernamePasswordCredentials creds = new UsernamePasswordCredentials("matterhorn_system_account", "CHANGE_ME"); DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet get = new HttpGet(BASE_URL + "/welcome.html"); get.addHeader("X-Requested-Auth", "Digest"); try {/*from w ww .j a va 2 s .c o m*/ httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpResponse response = httpclient.execute(get); String content = IOUtils.toString(response.getEntity().getContent(), "UTF-8"); Assert.assertTrue(content.contains("Opencast Matterhorn")); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:org.dthume.couchdb.maven.AbstractOnlineCouchMojo.java
/** * @return the server configuration for this execution */// ww w . j a v a2s. c o m protected final Server getServer() { final ServerImpl server = new ServerImpl(host, port); if (!StringUtils.isBlank(username)) { final Credentials creds = new UsernamePasswordCredentials(username, password); server.setCredentials(AuthScope.ANY, creds); } return server; }
From source file:org.eclipse.microprofile.health.tck.SimpleHttp.java
protected Response getUrlContents(String theUrl, boolean useAuth, boolean followRedirects) { StringBuilder content = new StringBuilder(); int code;//w w w . ja v a 2s .c o m try { HttpClientBuilder builder = HttpClientBuilder.create(); if (!followRedirects) { builder.disableRedirectHandling(); } if (useAuth) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "password"); provider.setCredentials(AuthScope.ANY, credentials); builder.setDefaultCredentialsProvider(provider); } HttpClient client = builder.build(); HttpResponse response = client.execute(new HttpGet(theUrl)); code = response.getStatusLine().getStatusCode(); if (response.getEntity() != null) { BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); String line; while ((line = bufferedReader.readLine()) != null) { content.append(line + "\n"); } bufferedReader.close(); } } catch (Exception e) { throw new RuntimeException(e); } return new Response(code, content.toString()); }