List of usage examples for org.apache.http.client.config AuthSchemes DIGEST
String DIGEST
To view the source code for org.apache.http.client.config AuthSchemes DIGEST.
Click Source Link
From source file:com.wudaosoft.net.httpclient.HostConfigBuilder.java
public HostConfig build() { requestConfig = RequestConfig.custom().setExpectContinueEnabled(false) // .setStaleConnectionCheckEnabled(true) .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST)) .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)) .setConnectionRequestTimeout(connectionRequestTimeout).setConnectTimeout(connectTimeout) .setSocketTimeout(socketTimeout).build(); SimpleHostConfig hostCofing = new SimpleHostConfig(requestConfig); hostCofing.setCA(ca);/*from ww w .ja v a 2 s .c o m*/ hostCofing.setCaPassword(caPassword); hostCofing.setCharset(charset); hostCofing.setHost(httpHost); hostCofing.setHostUrl(hostUrl); hostCofing.setHostCount(hostCount); hostCofing.setIsMulticlient(multiclient); hostCofing.setPoolSize(poolSize); hostCofing.setReferer(referer); hostCofing.setUserAgent(userAgent); return hostCofing; }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.RemoteStorageContextCustomizer.java
@VisibleForTesting public void applyAuthenticationConfig(final Builder builder, final RemoteAuthenticationSettings ras, final HttpHost proxyHost) { if (ras != null) { String authScope = "target"; if (proxyHost != null) { authScope = proxyHost.toHostString() + " proxy"; }// w ww. j a v a2s . c o m final List<String> authorisationPreference = Lists.newArrayListWithExpectedSize(3); authorisationPreference.add(AuthSchemes.DIGEST); authorisationPreference.add(AuthSchemes.BASIC); Credentials credentials = null; if (ras instanceof ClientSSLRemoteAuthenticationSettings) { throw new IllegalArgumentException("SSL client authentication not yet supported!"); } else if (ras instanceof NtlmRemoteAuthenticationSettings) { final NtlmRemoteAuthenticationSettings nras = (NtlmRemoteAuthenticationSettings) ras; // Using NTLM auth, adding it as first in policies authorisationPreference.add(0, AuthSchemes.NTLM); log.debug("{} authentication setup for NTLM domain '{}'", authScope, nras.getNtlmDomain()); credentials = new NTCredentials(nras.getUsername(), nras.getPassword(), nras.getNtlmHost(), nras.getNtlmDomain()); } else if (ras instanceof UsernamePasswordRemoteAuthenticationSettings) { final UsernamePasswordRemoteAuthenticationSettings uras = (UsernamePasswordRemoteAuthenticationSettings) ras; log.debug("{} authentication setup for remote storage with username '{}'", authScope, uras.getUsername()); credentials = new UsernamePasswordCredentials(uras.getUsername(), uras.getPassword()); } if (credentials != null) { if (proxyHost != null) { builder.setCredentials(new AuthScope(proxyHost), credentials); builder.getRequestConfigBuilder().setProxyPreferredAuthSchemes(authorisationPreference); } else { builder.setCredentials(AuthScope.ANY, credentials); builder.getRequestConfigBuilder().setTargetPreferredAuthSchemes(authorisationPreference); } } } }
From source file:com.ea.core.bridge.ws.rest.client.AbstractRestClient.java
public AbstractRestClient(URL httpUrl) { super(httpUrl); HttpMessageParserFactory<HttpResponse> responseParserFactory = new DefaultHttpResponseParserFactory() { @Override/*from ww w .j a va 2s . c o m*/ public HttpMessageParser<HttpResponse> create(SessionInputBuffer buffer, MessageConstraints constraints) { LineParser lineParser = new BasicLineParser() { @Override public Header parseHeader(final CharArrayBuffer buffer) { try { return super.parseHeader(buffer); } catch (ParseException ex) { return new BasicHeader(buffer.toString(), null); } } }; return new DefaultHttpResponseParser(buffer, lineParser, DefaultHttpResponseFactory.INSTANCE, constraints) { @Override protected boolean reject(final CharArrayBuffer line, int count) { // try to ignore all garbage preceding a status line infinitely return false; } }; } }; HttpMessageWriterFactory<HttpRequest> requestWriterFactory = new DefaultHttpRequestWriterFactory(); HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory = new ManagedHttpClientConnectionFactory( requestWriterFactory, responseParserFactory); SSLContext sslcontext = SSLContexts.createSystemDefault(); X509HostnameVerifier hostnameVerifier = new BrowserCompatHostnameVerifier(); Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", new SSLConnectionSocketFactory(sslcontext, hostnameVerifier)).build(); DnsResolver dnsResolver = new SystemDefaultDnsResolver() { @Override public InetAddress[] resolve(final String host) throws UnknownHostException { if (host.equalsIgnoreCase("myhost") || host.equalsIgnoreCase("localhost")) { return new InetAddress[] { InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }) }; } else { return super.resolve(host); } } }; PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry, connFactory, dnsResolver); SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).build(); connManager.setDefaultSocketConfig(socketConfig); connManager.setSocketConfig(new HttpHost("somehost", 80), socketConfig); MessageConstraints messageConstraints = MessageConstraints.custom().setMaxHeaderCount(200) .setMaxLineLength(2000).build(); ConnectionConfig connectionConfig = ConnectionConfig.custom() .setMalformedInputAction(CodingErrorAction.IGNORE) .setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(Consts.UTF_8) .setMessageConstraints(messageConstraints).build(); connManager.setDefaultConnectionConfig(connectionConfig); connManager.setConnectionConfig(new HttpHost("somehost", 80), ConnectionConfig.DEFAULT); connManager.setMaxTotal(100); connManager.setDefaultMaxPerRoute(10); connManager.setMaxPerRoute(new HttpRoute(new HttpHost("somehost", 80)), 20); CookieStore cookieStore = new BasicCookieStore(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BEST_MATCH) .setExpectContinueEnabled(true).setStaleConnectionCheckEnabled(true) .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST)) .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)).setConnectionRequestTimeout(3000) .setConnectTimeout(3000).setSocketTimeout(3000).build(); client = HttpClients.custom().setConnectionManager(connManager).setDefaultCookieStore(cookieStore) .setDefaultCredentialsProvider(credentialsProvider) // .setProxy(new HttpHost("myproxy", 8080)) .setDefaultRequestConfig(defaultRequestConfig).build(); }
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 . java 2 s .c om*/ 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.sonatype.nexus.apachehttpclient.Hc4ProviderBase.java
protected void applyAuthenticationConfig(final Builder builder, final RemoteAuthenticationSettings ras, final HttpHost proxyHost) { if (ras != null) { String authScope = "target"; if (proxyHost != null) { authScope = proxyHost.toHostString() + " proxy"; }// w ww . j a v a2s . c om final List<String> authorisationPreference = Lists.newArrayListWithExpectedSize(3); authorisationPreference.add(AuthSchemes.DIGEST); authorisationPreference.add(AuthSchemes.BASIC); Credentials credentials = null; if (ras instanceof ClientSSLRemoteAuthenticationSettings) { throw new IllegalArgumentException("SSL client authentication not yet supported!"); } else if (ras instanceof NtlmRemoteAuthenticationSettings) { final NtlmRemoteAuthenticationSettings nras = (NtlmRemoteAuthenticationSettings) ras; // Using NTLM auth, adding it as first in policies authorisationPreference.add(0, AuthSchemes.NTLM); log.debug("{} authentication setup for NTLM domain '{}'", authScope, nras.getNtlmDomain()); credentials = new NTCredentials(nras.getUsername(), nras.getPassword(), nras.getNtlmHost(), nras.getNtlmDomain()); } else if (ras instanceof UsernamePasswordRemoteAuthenticationSettings) { final UsernamePasswordRemoteAuthenticationSettings uras = (UsernamePasswordRemoteAuthenticationSettings) ras; log.debug("{} authentication setup for remote storage with username '{}'", authScope, uras.getUsername()); credentials = new UsernamePasswordCredentials(uras.getUsername(), uras.getPassword()); } if (credentials != null) { if (proxyHost != null) { builder.setCredentials(new AuthScope(proxyHost), credentials); builder.getRequestConfigBuilder().setProxyPreferredAuthSchemes(authorisationPreference); } else { builder.setCredentials(AuthScope.ANY, credentials); builder.getRequestConfigBuilder().setTargetPreferredAuthSchemes(authorisationPreference); } } } }
From source file:org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientImpl.java
@Override public void setUsernamePassword(AuthenticationType authType, String username, String password) { this.credentials = new UsernamePasswordCredentials(Objects.requireNonNull(username), Objects.requireNonNull(password)); this.credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, credentials); RegistryBuilder<AuthSchemeProvider> authRegistryBuilder = RegistryBuilder.create(); switch (authType) { case BASIC:// w w w. j a v a 2 s. com authRegistryBuilder.register(AuthSchemes.BASIC, new BasicSchemeFactory()); break; case DIGEST: authRegistryBuilder.register(AuthSchemes.DIGEST, new DigestSchemeFactory()); break; default: throw new IllegalArgumentException("Unsupported authentiation type: " + authType); } this.authRegistry = authRegistryBuilder.build(); }
From source file:io.mandrel.requests.http.ApacheHttpRequester.java
public void init() { available = new Semaphore(maxParallel(), true); SSLContext sslContext = SSLContexts.createSystemDefault(); HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(); Registry<ConnectionSocketFactory> sessionStrategyRegistry = RegistryBuilder .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new SSLConnectionSocketFactory(sslContext, hostnameVerifier)).build(); DnsResolver dnsResolver = new SystemDefaultDnsResolver() { @Override/*from w ww .j a v a 2s . c om*/ public InetAddress[] resolve(final String host) throws UnknownHostException { if (host.equalsIgnoreCase("localhost")) { return new InetAddress[] { InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }) }; } else { return new InetAddress[] { nameResolver().resolve(host) }; } } }; // Create a connection manager with custom configuration. PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager( sessionStrategyRegistry, dnsResolver); // Create message constraints MessageConstraints messageConstraints = MessageConstraints.custom().setMaxHeaderCount(maxHeaderCount) .setMaxLineLength(maxLineLength).build(); // Create connection configuration ConnectionConfig connectionConfig = ConnectionConfig.custom() .setMalformedInputAction(CodingErrorAction.IGNORE) .setUnmappableInputAction(CodingErrorAction.IGNORE).setCharset(Consts.UTF_8) .setMessageConstraints(messageConstraints).build(); connManager.setDefaultConnectionConfig(connectionConfig); // Configure total max or per route limits for persistent connections // that can be kept in the pool or leased by the connection manager. connManager.setMaxTotal(maxPersistentConnections()); connManager.setDefaultMaxPerRoute(maxPersistentConnections()); // TODO // Use custom credentials provider if necessary. // CredentialsProvider credentialsProvider = new // BasicCredentialsProvider(); // Create global request configuration defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT) .setExpectContinueEnabled(true).setStaleConnectionCheckEnabled(true) .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST)) .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)).setMaxRedirects(maxRedirects()) .setSocketTimeout(socketTimeout()).setConnectTimeout(connectTimeout()) .setConnectionRequestTimeout(requestTimeOut()).setRedirectsEnabled(followRedirects()).build(); // Create an HttpClient with the given custom dependencies and // configuration. client = HttpClients.custom().setConnectionManager(connManager) // .setDefaultCredentialsProvider(credentialsProvider) .setDefaultRequestConfig(defaultRequestConfig).build(); }