List of usage examples for org.apache.http.auth AuthScope AuthScope
public AuthScope(final String host, final int port)
From source file:io.cloudslang.content.httpclient.build.auth.CredentialsProviderBuilderTest.java
@Test public void createDefaultCredentialsProvider() { CredentialsProvider credentialsProvider = getCredentialsProvider(""); Credentials credentials = credentialsProvider.getCredentials(new AuthScope("host", 80)); assertThat(credentials, instanceOf(UsernamePasswordCredentials.class)); UsernamePasswordCredentials userCredentials = (UsernamePasswordCredentials) credentials; assertEquals("pass", userCredentials.getPassword()); }
From source file:com.mockey.model.ProxyServerModel.java
public AuthScope getAuthScope() { return new AuthScope(getProxyHost(), getProxyPort()); }
From source file:de.fraunhofer.iosb.ilt.stc.auth.AuthBasic.java
@Override public void setAuth(SensorThingsService service) { try {/*from w w w . j av a 2 s .co m*/ CredentialsProvider credsProvider = new BasicCredentialsProvider(); URL url = service.getEndpoint().toURL(); credsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()), new UsernamePasswordCredentials(editorUsername.getValue(), editorPassword.getValue())); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider) .build(); service.setClient(httpclient); } catch (MalformedURLException ex) { LOGGER.error("Failed to initialise basic auth.", ex); } }
From source file:org.sonar.updatecenter.server.HttpDownloader.java
File downloadFile(URI fileURI, File toFile, String login, String password) { LOG.info("Download " + fileURI + " in " + toFile); DefaultHttpClient client = new DefaultHttpClient(); try {//w ww .j a v a 2 s. c om if (StringUtils.isNotBlank(login)) { client.getCredentialsProvider().setCredentials(new AuthScope(fileURI.getHost(), fileURI.getPort()), new UsernamePasswordCredentials(login, password)); } HttpGet httpget = new HttpGet(fileURI); byte[] data = client.execute(httpget, new ByteResponseHandler()); if (data != null) { FileUtils.writeByteArrayToFile(toFile, data); } } catch (Exception e) { LOG.error("Fail to download " + fileURI + " to " + toFile, e); FileUtils.deleteQuietly(toFile); } finally { client.getConnectionManager().shutdown(); } return toFile; }
From source file:org.artifactory.util.ProxyPreemptiveAuthInterceptor.java
@Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState proxyAuthState = clientContext.getProxyAuthState(); // If there's no auth scheme available yet, try to initialize it preemptively if (proxyAuthState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); RouteInfo route = clientContext.getHttpRoute(); if (route == null) { log.debug("No route found for {}", clientContext.getTargetHost()); return; }/*from ww w. java2s .c om*/ HttpHost proxyHost = route.getProxyHost(); if (proxyHost == null) { log.warn("No proxy host found in route {} for host {}", route, clientContext.getTargetHost()); return; } Credentials creds = credsProvider .getCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort())); if (creds == null) { log.info("No credentials found for proxy: " + proxyHost); return; } proxyAuthState.update(new BasicScheme(ChallengeState.PROXY), creds); } }
From source file:org.droidparts.http.wrapper.DefaultHttpClientWrapper.java
@Override protected void setProxy(String protocol, String host, int port, String user, String password) { HttpHost proxyHost = new HttpHost(host, port, protocol); httpClient.getParams().setParameter(DEFAULT_PROXY, proxyHost); if (!isEmpty(user) && !isEmpty(password)) { AuthScope authScope = new AuthScope(host, port); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password); httpClient.getCredentialsProvider().setCredentials(authScope, credentials); }//from w w w. ja v a 2 s .co m }
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); }/*from w w w .jav a 2 s . com*/ 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//from w w w . ja va 2 s .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)); }
From source file:com.marklogic.client.test.util.TestServerBootstrapper.java
private void invokeBootstrapExtension() throws ClientProtocolException, IOException { DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", port), new UsernamePasswordCredentials(username, password)); HttpPost post = new HttpPost("http://" + host + ":" + port + "/v1/resources/bootstrap"); HttpResponse response = client.execute(post); @SuppressWarnings("unused") HttpEntity entity = response.getEntity(); System.out.println("Invoked bootstrap extension. Response is " + response.toString()); }