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:de.unioninvestment.eai.portal.portlet.crud.domain.model.authentication.Realm.java
/** * Applies credentials to target {@link HttpClient} with Basic * Authentication (PLEASE ONLY USE THIS TOGETHER WITH SSL). * /*w w w . j a va 2 s .com*/ * @param httpClient */ public void applyBasicAuthentication(DefaultHttpClient httpClient) { String username = null; String password = null; Cryptor cryptor = null; PortletPreferences preferences = VaadinPortletService.getCurrentPortletRequest().getPreferences(); CredentialsConfig credentials = config.getCredentials(); String usernameKey = credentials.getUsername().getPreferenceKey(); if (usernameKey != null) { username = preferences.getValue(usernameKey, null); } String passwordKey = credentials.getPassword().getPreferenceKey(); if (passwordKey != null) { password = preferences.getValue(passwordKey, null); } String encryptionAlgorithm = credentials.getPassword().getEncryptionAlgorithm(); if (encryptionAlgorithm != null) { cryptor = cryptorFactory.getCryptor(encryptionAlgorithm); } String plaintextPassword = cryptor == null ? password : cryptor.decrypt(password); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, plaintextPassword)); }
From source file:org.ops4j.pax.web.itest.DigestAuthenticationTest.java
@Test public void shouldPermitAccess() throws Exception { assertThat(servletContext.getContextPath(), is("/digest")); String path = String.format("http://localhost:%d/digest/hello", getHttpPort()); HttpClientContext context = HttpClientContext.create(); BasicCredentialsProvider cp = new BasicCredentialsProvider(); cp.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("mustermann", "mustermann")); CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(cp).build(); HttpGet httpGet = new HttpGet(path); HttpResponse response = client.execute(httpGet, context); int statusCode = response.getStatusLine().getStatusCode(); assertThat(statusCode, is(200));/* w w w .j a v a2s. c o m*/ String text = EntityUtils.toString(response.getEntity()); assertThat(text, containsString("Hello from Pax Web!")); }
From source file:org.trustedanalytics.servicebroker.hdfs.users.UaaClientTokenRetriver.java
private RestTemplate createRestTemplate() { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( uaaConfiguration.getClientId(), uaaConfiguration.getClientSecret())); HttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider) .build();/*from w ww.j a va 2 s .c o m*/ return new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient)); }
From source file:goofyhts.torrentkinesis.http.client.DefaultHttpClient.java
@Override public void open() { client = HttpClients.createDefault(); context = new HttpClientContext(); CredentialsProvider credProv = new BasicCredentialsProvider(); credProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); context.setCredentialsProvider(credProv); }
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 ww. j ava 2 s. c om }
From source file:org.droidparts.net.http.RESTClient.java
public void authenticateBasic(String username, String password) { authenticateBasic(username, password, AuthScope.ANY); }
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); }/* w w w. j a v a2s . c o 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.microsoft.azure.hdinsight.spark.common.SparkBatchSubmission.java
/** * Set http request credential using username and password * @param username : username/* ww w .j a v a 2s . c om*/ * @param password : password */ public void setCredentialsProvider(String username, String password) { credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(username, password)); }
From source file:ro.cosu.vampires.server.rest.controllers.AbstractControllerTest.java
protected static HttpClient getHttpClient() { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(User.admin().id(), User.admin().id())); return HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build(); }