List of usage examples for org.apache.http.auth AuthScope ANY_HOST
String ANY_HOST
To view the source code for org.apache.http.auth AuthScope ANY_HOST.
Click Source Link
From source file:org.elasticsearch.xpack.security.authc.kerberos.SpnegoHttpClientConfigCallbackHandler.java
private void setupSpnegoAuthSchemeSupport(HttpAsyncClientBuilder httpClientBuilder) { final Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()).build(); final GSSManager gssManager = GSSManager.getInstance(); try {/*from w w w. ja va 2 s.co m*/ final GSSName gssUserPrincipalName = gssManager.createName(userPrincipalName, GSSName.NT_USER_NAME); login(); final AccessControlContext acc = AccessController.getContext(); final GSSCredential credential = doAsPrivilegedWrapper(loginContext.getSubject(), (PrivilegedExceptionAction<GSSCredential>) () -> gssManager.createCredential( gssUserPrincipalName, GSSCredential.DEFAULT_LIFETIME, SPNEGO_OID, GSSCredential.INITIATE_ONLY), acc); final KerberosCredentialsProvider credentialsProvider = new KerberosCredentialsProvider(); credentialsProvider.setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthSchemes.SPNEGO), new KerberosCredentials(credential)); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } catch (GSSException e) { throw new RuntimeException(e); } catch (PrivilegedActionException e) { throw new RuntimeException(e.getCause()); } httpClientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry); }
From source file:org.geosdi.geoplatform.gui.server.service.impl.PublisherService.java
@PostConstruct public void init() { logger.info("Reload publisher parameters: URL CLUSTER RELOAD " + urlClusterReload + " - HOST URL CLUSTER RELOAD " + hostUrlClusterReload + " - USERNAME CLUSTER RELOAD " + userNameClusterReload + " - PASSWORD CLUSTER RELOAD " + passwordClusterReload); localContext = new BasicHttpContext(); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 60000); HttpConnectionParams.setSoTimeout(params, 60000); this.httpclient = new DefaultHttpClient(params); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(userNameClusterReload, passwordClusterReload)); httpclient.setCredentialsProvider(credsProvider); }
From source file:org.bedework.synch.shared.cnctrs.AbstractConnectorInstance.java
protected CloseableHttpClient getClient() throws SynchException { if (client != null) { return client; }/*from ww w .j av a2s . c o m*/ final CloseableHttpClient cl = HttpClients.createDefault(); final HttpClientContext context = HttpClientContext.create(); if (info.getPrincipalHref() != null) { final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(info.getPrincipalHref(), cnctr.getSyncher().decrypt(info.getPassword()))); context.setCredentialsProvider(credsProvider); } client = cl; return cl; }
From source file:com.googlecode.sardine.SardineImpl.java
/** * Main constructor./*w w w . j a v a 2 s. c o m*/ */ public SardineImpl(Factory factory, String username, String password, SSLSocketFactory sslSocketFactory, HttpRoutePlanner routePlanner, Integer port) throws SardineException { this.factory = factory; HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 100); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(params, "Sardine/" + Version.getSpecification()); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry .register(new Scheme("http", PlainSocketFactory.getSocketFactory(), port != null ? port : 80)); if (sslSocketFactory != null) schemeRegistry.register(new Scheme("https", sslSocketFactory, port != null ? port : 443)); else schemeRegistry .register(new Scheme("https", SSLSocketFactory.getSocketFactory(), port != null ? port : 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); this.client = new DefaultHttpClient(cm, params); // for proxy configurations if (routePlanner != null) this.client.setRoutePlanner(routePlanner); if ((username != null) && (password != null)) { this.client.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); this.authEnabled = true; } }
From source file:com.globo.aclapi.client.ClientAclAPI.java
private static HttpClient newDefaultHttpClient(SSLSocketFactory socketFactory, HttpParams params, ProxySelector proxySelector) { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", socketFactory, 443)); ClientConnectionManager connectionManager = new ThreadSafeClientConnManager(params, registry); DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, params) { @Override/*from w w w . j ava2s. co m*/ protected HttpContext createHttpContext() { HttpContext httpContext = super.createHttpContext(); AuthSchemeRegistry authSchemeRegistry = new AuthSchemeRegistry(); authSchemeRegistry.register("Bearer", new BearerAuthSchemeFactory()); httpContext.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, authSchemeRegistry); AuthScope sessionScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "Bearer"); Credentials credentials = new TokenCredentials(""); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(sessionScope, credentials); httpContext.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider); return httpContext; } }; httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(registry, proxySelector)); return httpClient; }
From source file:com.marvelution.hudson.plugins.apiv2.client.connectors.HttpClient4Connector.java
/** * Get the {@link AuthScope} for the {@link #server} * /*www. j a va2 s. c o m*/ * @return the {@link AuthScope} */ private AuthScope getAuthScope() { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; try { final URI hostUri = new URI(server.getHost()); host = hostUri.getHost(); if (hostUri.getPort() > -1) { port = hostUri.getPort(); } else if ("http".equalsIgnoreCase(hostUri.getScheme())) { port = 80; } else if ("https".equalsIgnoreCase(hostUri.getScheme())) { port = 443; } } catch (URISyntaxException e) { // Failed to parse the server host URI // Fall-back on preset defaults log.error("Failed to parse the Server host url to an URI", e); } return new AuthScope(host, port, "realm"); }
From source file:com.mediaportal.ampdroid.api.JsonClient.java
private String executeRequest(HttpUriRequest request, int _timeout, String url) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, _timeout); HttpConnectionParams.setSoTimeout(httpParameters, _timeout); HttpConnectionParams.setTcpNoDelay(httpParameters, true); DefaultHttpClient client = new DefaultHttpClient(httpParameters); request.setHeader("User-Agent", Constants.USER_AGENT); if (mUseAuth) { CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(mUser, mPass)); client.setCredentialsProvider(credProvider); }/*from w ww. j ava 2s . c o m*/ HttpResponse httpResponse; try { httpResponse = client.execute(request); responseCode = httpResponse.getStatusLine().getStatusCode(); message = httpResponse.getStatusLine().getReasonPhrase(); HttpEntity entity = httpResponse.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); response = convertStreamToString(instream); // Closing the input stream will trigger connection release instream.close(); return response; } } catch (ClientProtocolException e) { client.getConnectionManager().shutdown(); e.printStackTrace(); } catch (IOException e) { client.getConnectionManager().shutdown(); e.printStackTrace(); } return null; }
From source file:org.megam.api.http.TransportMachinery.java
public static TransportResponse delete(TransportTools nuts) throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpDelete httpdel = new HttpDelete(nuts.urlString()); if (nuts.headers() != null) { for (Map.Entry<String, String> headerEntry : nuts.headers().entrySet()) { //this if condition is set for twilio Rest API to add credentials to DefaultHTTPClient, conditions met twilio work. if (headerEntry.getKey().equalsIgnoreCase("provider") & headerEntry.getValue().equalsIgnoreCase(nuts.headers().get("provider"))) { httpclient.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials( nuts.headers().get("account_sid"), nuts.headers().get("oauth_token"))); }//from ww w .j ava 2 s . c o m //this else part statements for other providers else { httpdel.addHeader(headerEntry.getKey(), headerEntry.getValue()); } } } TransportResponse transportResp = null; try { httpclient.execute(httpdel); //transportResp = new TransportResponse(httpResp.getStatusLine(), httpResp.getEntity(), httpResp.getLocale()); } finally { httpdel.releaseConnection(); } return transportResp; }
From source file:at.general.solutions.android.ical.remote.HttpDownloadThread.java
@Override public void run() { HttpParams params = new BasicHttpParams(); ConnManagerParams.setMaxTotalConnections(params, 100); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setUserAgent(params, USER_AGENT); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); DefaultHttpClient client = new DefaultHttpClient(cm, params); if (useAuthentication) { client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(remoteUsername, remotePassword)); }//from ww w.j a va2 s .c o m HttpGet get = new HttpGet(remoteUrl); try { super.sendInitMessage(R.string.downloading); HttpResponse response = client.execute(get); Log.d(LOG_TAG, response.getStatusLine().getReasonPhrase() + " " + isGoodResponse(response.getStatusLine().getStatusCode())); if (isGoodResponse(response.getStatusLine().getStatusCode())) { HttpEntity entity = response.getEntity(); InputStream instream = entity.getContent(); if (instream == null) { super.sendErrorMessage(R.string.couldnotConnectToRemoteserver); return; } if (entity.getContentLength() > Integer.MAX_VALUE) { super.sendErrorMessage(R.string.remoteFileTooLarge); return; } int i = (int) entity.getContentLength(); if (i < 0) { i = 4096; } String charset = EntityUtils.getContentCharSet(entity); if (charset == null) { charset = encoding; } if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } Reader reader = new InputStreamReader(instream, charset); CharArrayBuffer buffer = new CharArrayBuffer(i); super.sendMaximumMessage(i); try { char[] tmp = new char[1024]; int l; while ((l = reader.read(tmp)) != -1) { buffer.append(tmp, 0, l); super.sendProgressMessage(buffer.length()); } } finally { reader.close(); } super.sendFinishedMessage(buffer.toString()); } else { int errorMsg = R.string.couldnotConnectToRemoteserver; if (isAccessDenied(response.getStatusLine().getStatusCode())) { errorMsg = R.string.accessDenied; } else if (isFileNotFound(response.getStatusLine().getStatusCode())) { errorMsg = R.string.remoteFileNotFound; } super.sendErrorMessage(errorMsg); } } catch (UnknownHostException e) { super.sendErrorMessage(R.string.unknownHostException, e); Log.e(LOG_TAG, "Error occured", e); } catch (Throwable e) { super.sendErrorMessage(R.string.couldnotConnectToRemoteserver, e); Log.e(LOG_TAG, "Error occured", e); } finally { client.getConnectionManager().shutdown(); } }
From source file:nl.nn.adapterframework.http.WebServiceNtlmSender.java
public void configure() throws ConfigurationException { super.configure(); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, getTimeout()); HttpConnectionParams.setSoTimeout(httpParameters, getTimeout()); httpClient = new DefaultHttpClient(connectionManager, httpParameters); httpClient.getAuthSchemes().register("NTLM", new NTLMSchemeFactory()); CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword()); httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new NTCredentials(cf.getUsername(), cf.getPassword(), Misc.getHostname(), getAuthDomain())); if (StringUtils.isNotEmpty(getProxyHost())) { HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort()); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); }//from w w w . j a v a2s . com }