List of usage examples for org.apache.http.auth UsernamePasswordCredentials UsernamePasswordCredentials
public UsernamePasswordCredentials(final String userName, final String password)
From source file:no.back.springextensions.DBFactory.java
/** * Create a new {@link Database} connection * //from w w w.j a v a 2s . com * @return initialized database * @throws IllegalStateException * if not all required properties are set before attempting to * initialize. */ Database initialize() { if (hostname == null) throw new IllegalStateException( "You must specify " + hostname + " before initializing a database connection"); if (database == null) throw new IllegalStateException( "You must specify a " + database + " name before initializing a database connection"); if (!(port >= 0 && port <= 65536)) throw new IllegalStateException( "You must specify a " + port + " within 0-65536 before initializing a database connection"); Server server = new ServerImpl(hostname, port); if (username != null && password != null) { Credentials credentials = new UsernamePasswordCredentials(username, password); AuthScope authScope = new AuthScope(hostname, port, null); server.setCredentials(authScope, credentials); } return new Database(server, database); }
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)) { }/*from w ww. ja v a 2 s . co m*/ }
From source file:com.rackspace.api.clients.veracode.DefaultVeracodeApiClient.java
public DefaultVeracodeApiClient(String baseUri, String username, String password, PrintStream logger) { try {//from w ww. ja va2s. c o m this.baseUri = new URI(baseUri); } catch (URISyntaxException e) { throw new RuntimeException("Veracode Base URI was not correctly entered.", e); } this.logger = logger; this.client = initiateClient(new UsernamePasswordCredentials(username, password)); }
From source file:org.opencastproject.remotetest.server.DigestAuthenticationTest.java
@Test public void testBadDigestAuthenticatedGet() throws Exception { UsernamePasswordCredentials creds = new UsernamePasswordCredentials("matterhorn_system_account", "wrong_password"); DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpGet get = new HttpGet(BASE_URL + "/welcome.html"); get.addHeader("X-Requested-Auth", "Digest"); try {//from ww w . j a v a 2s . c om HttpResponse response = httpclient.execute(get); Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode()); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:at.ac.univie.isc.asio.integration.IntegrationSettings.java
/** * The login credentials for the management api. *//*from w ww . j a v a 2 s . com*/ @Nonnull public IntegrationSettings rootCredentials(final String username, final String password) { this.rootCredentials = new UsernamePasswordCredentials(username, password); return this; }
From source file:org.jfrog.build.client.PreemptiveHttpClient.java
public void setProxyConfiguration(String host, int port, String username, String password) { HttpHost proxy = new HttpHost(host, port); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (username != null) { httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(username, password)); }/*from ww w . j a va2 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 .j a v a 2s .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: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); }/* w ww . ja v a 2s . c om*/ 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.geosdi.geoplatform.connector.server.security.AbstractSecurityConnector.java
/** * Bind Credentials for {@link CredentialsProvider} class * * @param credentialsProvider// ww w . j a v a2s . c o m */ protected void bindCredentials(CredentialsProvider credentialsProvider, URI targetURI) { if (this.authScope == null) { this.authScope = new AuthScope(targetURI.getHost(), targetURI.getPort()); } credentialsProvider.setCredentials(authScope, new UsernamePasswordCredentials(username, password)); }