List of usage examples for org.apache.http.auth AuthScope ANY_REALM
String ANY_REALM
To view the source code for org.apache.http.auth AuthScope ANY_REALM.
Click Source Link
From source file:com.madrobot.net.client.XMLRPCClient.java
/** * Convenience constructor. Creates new instance based on server String address * //from w ww . java 2 s .co m * @param XMLRPC * server address * @param HTTP * Server - Basic Authentication - Username * @param HTTP * Server - Basic Authentication - Password */ public XMLRPCClient(URI uri, String username, String password) { this(uri); ((DefaultHttpClient) client).getCredentialsProvider().setCredentials( new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password)); }
From source file:com.rightscale.provider.rest.DashboardSession.java
private void setupBasicAuth(StatefulClient client) { AuthScope authScope = new AuthScope(_baseURI.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_REALM); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(_username, _password); AbstractHttpClient realClient = (AbstractHttpClient) client.getRealClient(); realClient.getCredentialsProvider().setCredentials(authScope, creds); realClient.addRequestInterceptor(createBasicAuthInterceptor(), 0); }
From source file:org.switchyard.component.http.OutboundHandler.java
private AuthScope createAuthScope(String host, String portStr, String realm) throws HttpConsumeException { URL url = null;// w w w .ja v a 2 s . c o m try { url = new URL(_baseAddress); } catch (MalformedURLException mue) { final String m = HttpMessages.MESSAGES.invalidHttpURL(); LOGGER.error(m, mue); throw new HttpConsumeException(m, mue); } if (realm == null) { realm = AuthScope.ANY_REALM; } int port = url.getPort(); if (host == null) { host = url.getHost(); } if (portStr != null) { port = Integer.valueOf(portStr).intValue(); } return new AuthScope(host, port, realm); }
From source file:com.intuit.tank.httpclient4.TankHttpClient4.java
@Override public void addAuth(AuthCredentials creds) { String host = (StringUtils.isBlank(creds.getHost()) || "*".equals(creds.getHost())) ? AuthScope.ANY_HOST : creds.getHost();/* w w w . j a va2 s . c om*/ String realm = (StringUtils.isBlank(creds.getRealm()) || "*".equals(creds.getRealm())) ? AuthScope.ANY_REALM : creds.getRealm(); int port = NumberUtils.toInt(creds.getPortString(), AuthScope.ANY_PORT); String scheme = creds.getScheme() != null ? creds.getScheme().getRepresentation() : AuthScope.ANY_SCHEME; AuthScope scope = new AuthScope(host, port, realm, scheme); if (AuthScheme.NTLM == creds.getScheme()) { context.getCredentialsProvider().setCredentials(scope, new NTCredentials(creds.getUserName(), creds.getPassword(), "tank-test", creds.getRealm())); } else { context.getCredentialsProvider().setCredentials(scope, new UsernamePasswordCredentials(creds.getUserName(), creds.getPassword())); } }
From source file:com.hp.mercury.ci.jenkins.plugins.OOBuildStep.java
private static void initializeHttpClient(DescriptorImpl descriptor) { final int maxConnectionsPerRoute = 100; final int maxConnectionsTotal = 100; ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager(); threadSafeClientConnManager.setDefaultMaxPerRoute(maxConnectionsPerRoute); threadSafeClientConnManager.setMaxTotal(maxConnectionsTotal); httpClient = new DefaultHttpClient(threadSafeClientConnManager); if (descriptor.isIgnoreSsl()) { threadSafeClientConnManager.getSchemeRegistry() .register(new Scheme("https", 443, new FakeSocketFactory())); } else if (descriptor.getKeystorePath() != null) { try {/*from w w w. j av a 2 s. co m*/ SSLSocketFactory sslSocketFactory = sslSocketFactoryFromCertificateFile( descriptor.getKeystorePath(), decrypt(descriptor.getKeystorePassword()).toCharArray()); sslSocketFactory.setHostnameVerifier(new BrowserCompatHostnameVerifier()); // For less strict rules in dev mode you can try //sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier()); threadSafeClientConnManager.getSchemeRegistry() .register(new Scheme("https", 443, sslSocketFactory)); } catch (NoSuchAlgorithmException e) { LOG.error("Could not register https scheme: ", e); } catch (KeyManagementException e) { LOG.error("Could not register https scheme: ", e); } catch (KeyStoreException e) { LOG.error("Could not register https scheme: ", e); } catch (UnrecoverableKeyException e) { LOG.error("Could not register https scheme: ", e); } catch (IOException e) { LOG.error("Could not load keystore file: ", e); } catch (CertificateException e) { LOG.error("Could not load keystore file: ", e); } } final HttpParams params = httpClient.getParams(); final int timeoutInSeconds = descriptor.getTimeout() * 1000; HttpConnectionParams.setConnectionTimeout(params, timeoutInSeconds); HttpConnectionParams.setSoTimeout(params, timeoutInSeconds); HttpProtocolParams.setUseExpectContinue(httpClient.getParams(), false); for (OOServer s : descriptor.getOoServers(true).values()) { URL url = null; try { url = new URL(s.getUrl()); } catch (MalformedURLException mue) { //can't happen, we pre-validate the URLS during configuration and set active to false if bad. } //check why it doesn't use the credentials provider httpClient.getCredentialsProvider().setCredentials( new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM, "basic"), new UsernamePasswordCredentials(s.getUsername(), decrypt(s.getPassword()))); } }
From source file:org.eclipse.mylyn.commons.repositories.http.tests.CommonHttpClientTest.java
@Test public void testHttpAuthenticationTypeHttp() throws Exception { RepositoryLocation location = new RepositoryLocation(); location.setUrl("http://mylyn.org/"); location.setCredentials(AuthenticationType.HTTP, new UserCredentials("username", "password")); HttpGet request = new HttpGet(location.getUrl()); CommonHttpClient client = new CommonHttpClient(location); HttpResponse response = client.execute(request, null); try {// ww w. j a va2s . co m AuthScope authScope = new AuthScope("mylyn.org", 80, AuthScope.ANY_REALM); Credentials httpCredentials = client.getHttpClient().getCredentialsProvider().getCredentials(authScope); assertEquals(new UsernamePasswordCredentials("username", "password"), httpCredentials); } finally { HttpUtil.release(request, response, null); } }
From source file:com.madrobot.net.client.XMLRPCClient.java
/** * Convenience constructor. Creates new instance based on server String address * /* w ww . j av a 2 s . c o m*/ * @param XMLRPC * server address * @param HTTP * Server - Basic Authentication - Username * @param HTTP * Server - Basic Authentication - Password * @param HttpClient * to use */ public XMLRPCClient(URI uri, String username, String password, HttpClient client) { this(uri, client); ((DefaultHttpClient) this.client).getCredentialsProvider().setCredentials( new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password)); }
From source file:com.jfrog.bintray.client.impl.HttpClientConfigurator.java
private void configureProxy(ProxyConfig proxy) { if (proxy != null) { config.setProxy(new HttpHost(proxy.getHost(), proxy.getPort())); if (proxy.getUserName() != null) { Credentials creds = null;/*from w w w . j a va2s . c o m*/ if (proxy.getNtDomain() == null) { creds = new UsernamePasswordCredentials(proxy.getUserName(), proxy.getPassword()); List<String> authPrefs = Arrays.asList(AuthSchemes.DIGEST, AuthSchemes.BASIC, AuthSchemes.NTLM); config.setProxyPreferredAuthSchemes(authPrefs); // preemptive proxy authentication builder.addInterceptorFirst(new ProxyPreemptiveAuthInterceptor()); } else { try { String ntHost = StringUtils.isBlank(proxy.getNtHost()) ? InetAddress.getLocalHost().getHostName() : proxy.getNtHost(); creds = new NTCredentials(proxy.getUserName(), proxy.getPassword(), ntHost, proxy.getNtDomain()); } catch (UnknownHostException e) { log.error("Failed to determine required local hostname for NTLM credentials.", e); } } if (creds != null) { credsProvider.setCredentials( new AuthScope(proxy.getHost(), proxy.getPort(), AuthScope.ANY_REALM), creds); if (proxy.getRedirectToHosts() != null) { for (String hostName : proxy.getRedirectToHosts()) { credsProvider.setCredentials( new AuthScope(hostName, AuthScope.ANY_PORT, AuthScope.ANY_REALM), creds); } } } } } }
From source file:org.eclipse.mylyn.commons.repositories.http.tests.CommonHttpClientTest.java
@Test public void testHttpAuthenticationTypeRepository() throws Exception { RepositoryLocation location = new RepositoryLocation(); location.setUrl("http://mylyn.org/"); location.setCredentials(AuthenticationType.REPOSITORY, new UserCredentials("username", "password")); HttpGet request = new HttpGet(location.getUrl()); CommonHttpClient client = new CommonHttpClient(location); AuthScope authScope = new AuthScope("mylyn.org", 80, AuthScope.ANY_REALM); // credentials should be ignored HttpResponse response = client.execute(request, null); try {/*from ww w . j av a 2 s . c o m*/ Credentials httpCredentials = client.getHttpClient().getCredentialsProvider().getCredentials(authScope); assertEquals(null, httpCredentials); } finally { HttpUtil.release(request, response, null); } client.setHttpAuthenticationType(AuthenticationType.REPOSITORY); // credentials should now be used response = client.execute(request, null); try { Credentials httpCredentials = client.getHttpClient().getCredentialsProvider().getCredentials(authScope); assertEquals(new UsernamePasswordCredentials("username", "password"), httpCredentials); } finally { HttpUtil.release(request, response, null); } }
From source file:fr.ippon.wip.http.hc.HttpClientExecutor.java
/** * This method updates the CredentialsProvider associated to the current * PortletSession and the windowID with the provided login and password. * Basic and NTLM authentication schemes are supported. This method uses the * current fr.ippon.wip.state.PortletWindow to retrieve the authentication * schemes requested by remote server./*from www. ja v a2 s .co m*/ * * @param login * @param password * @param portletRequest * Used to get current javax.portlet.PortletSession and windowID */ public void login(String login, String password, PortletRequest portletRequest) { HttpClientResourceManager resourceManager = HttpClientResourceManager.getInstance(); CredentialsProvider credentialsProvider = resourceManager.getCredentialsProvider(portletRequest); PortletWindow portletWindow = PortletWindow.getInstance(portletRequest); List<String> schemes = portletWindow.getRequestedAuthSchemes(); if (schemes.contains("Basic")) { // Creating basic credentials AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "Basic"); Credentials credentials = new UsernamePasswordCredentials(login, password); credentialsProvider.setCredentials(scope, credentials); } if (schemes.contains("NTLM")) { // Creating ntlm credentials AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "NTLM"); Credentials credentials = new NTCredentials(login, password, "", ""); credentialsProvider.setCredentials(scope, credentials); } }