List of usage examples for org.apache.http.auth AuthScope ANY
AuthScope ANY
To view the source code for org.apache.http.auth AuthScope ANY.
Click Source Link
From source file:com.squeezecontrol.image.HttpFetchingImageStore.java
public HttpFetchingImageStore(String baseUrl, String username, String password) { this.baseUrl = baseUrl; HttpParams params = new BasicHttpParams(); // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpConnectionParams.setStaleCheckingEnabled(params, false); // Default connection and socket timeout of 20 seconds. Tweak to taste. HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); HttpConnectionParams.setSocketBufferSize(params, 8192); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager mgr = new ThreadSafeClientConnManager(params, schemeRegistry); mClient = new DefaultHttpClient(mgr, params); if (username != null && !"".equals(username)) { Credentials defaultcreds = new UsernamePasswordCredentials("dag", "test"); mClient.getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds); }/*from www. j a v a2 s . c om*/ }
From source file:org.apache.maven.wagon.providers.http.BasicAuthScope.java
/** * Create an authScope given the /repository/host and /repository/password * and the /server/basicAuth or /server/proxyBasicAuth host, port and realm * settings. The basicAuth setting should override the repository settings * host and/or port if host, port or realm is set to "ANY". * <p/>/*w ww . j a v a2 s.c o m*/ * Realm can also be set to a specific string and will be set if * /server/basicAuthentication/realm is non-null * * @param host The server setting's /server/host value * @param port The server setting's /server/port value * @return */ public AuthScope getScope(String host, int port) { if (getHost() != null // && "ANY".compareTo(getHost()) == 0 // && getPort() != null // && "ANY".compareTo(getPort()) == 0 // && getRealm() != null // && "ANY".compareTo(getRealm()) == 0) { return AuthScope.ANY; } String scopeHost = host; if (getHost() != null) { if ("ANY".compareTo(getHost()) == 0) { scopeHost = AuthScope.ANY_HOST; } else { scopeHost = getHost(); } } int scopePort = port > -1 ? port : AuthScope.ANY_PORT; // -1 for server/port settings does this, but providing an override here // in // the BasicAuthScope config if (getPort() != null) { if ("ANY".compareTo(getPort()) == 0) { scopePort = AuthScope.ANY_PORT; } else { scopePort = Integer.parseInt(getPort()); } } String scopeRealm = AuthScope.ANY_REALM; if (getRealm() != null) { if ("ANY".compareTo(getRealm()) != 0) { scopeRealm = getRealm(); } else { scopeRealm = getRealm(); } } return new AuthScope(scopeHost, scopePort, scopeRealm); }
From source file:org.sonar.plugins.buildstability.ci.teamcity.TeamCityServer.java
@Override public void doLogin(DefaultHttpClient client) throws IOException { Credentials credentials = new UsernamePasswordCredentials(getUsername(), getPassword()); client.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); }
From source file:org.appenders.log4j2.elasticsearch.jest.BasicCredentials.java
@Override public void applyTo(HttpClientConfig.Builder builder) { BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider(); basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); builder.credentialsProvider(basicCredentialsProvider); }
From source file:org.trustedanalytics.servicebroker.hdfs.config.hgm.HgmHttpsConfiguration.java
@Bean @Qualifier("hgmRestTemplate") public RestTemplate getHgmHttpsRestTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS() .build();// w ww . j ava2 s. c om SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier()); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword())); HttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(connectionFactory) .setDefaultCredentialsProvider(credentialsProvider).build(); ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); return new RestTemplate(requestFactory); }
From source file:com.microsoft.azure.hdinsight.common.task.MultiRestTask.java
public MultiRestTask(@NotNull IClusterDetail clusterDetail, @NotNull List<String> paths, @NotNull FutureCallback<List<String>> callback) { super(callback); this.clusterDetail = clusterDetail; this.paths = paths; try {//from www . j a v a 2 s . c o m credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword())); } catch (HDIException e) { e.printStackTrace(); } }
From source file:com.quartzdesk.executor.core.job.UrlInvokerJob.java
@Override protected void executeJob(final JobExecutionContext context) throws JobExecutionException { log.debug("Inside job: {}", context.getJobDetail().getKey()); JobDataMap jobDataMap = context.getMergedJobDataMap(); // url (required) final String url = jobDataMap.getString(JDM_KEY_URL); if (url == null) { throw new JobExecutionException("Missing required '" + JDM_KEY_URL + "' job data map parameter."); }// ww w . j a v a 2 s .c om // username (optional) String username = jobDataMap.getString(JDM_KEY_USERNAME); // password (optional) String password = jobDataMap.getString(JDM_KEY_PASSWORD); CloseableHttpClient httpClient; if (username != null && password != null) { // use HTTP basic authentication CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password)); httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); } else { // use no HTTP authentication httpClient = HttpClients.custom().build(); } try { HttpPost httpPost = new HttpPost(url); ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse httpResponse) throws IOException { int status = httpResponse.getStatusLine().getStatusCode(); //context.setResult( Integer.toString( status ) ); if (status >= 200 && status < 300) { HttpEntity entity = httpResponse.getEntity(); return entity == null ? null : EntityUtils.toString(entity); } else { throw new ClientProtocolException( "URL: " + url + " returned unexpected response status code: " + status); } } }; log.debug("HTTP request line: {}", httpPost.getRequestLine()); log.info("Invoking target URL: {}", url); String responseText = httpClient.execute(httpPost, responseHandler); log.debug("Response text: {}", responseText); if (!responseText.trim().isEmpty()) { /* * We use the HTTP response text as the Quartz job execution result. This code can then be easily * viewed in the Execution History in the QuartzDesk GUI and it can be, for example, used to trigger * execution notifications. */ context.setResult(responseText); } } catch (IOException e) { throw new JobExecutionException("Error invoking URL: " + url, e); } finally { try { httpClient.close(); } catch (IOException e) { log.error("Error closing HTTP client.", e); } } }
From source file:com.microsoft.azure.hdinsight.common.task.LivyTask.java
public LivyTask(@NotNull IClusterDetail clusterDetail, @NotNull String path, @NotNull FutureCallback<String> callback) { super(callback); this.clusterDetail = clusterDetail; this.path = path; this.callback = callback; try {/*from w ww . j a v a 2s . co m*/ credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword())); } catch (HDIException e) { e.printStackTrace(); } }
From source file:org.apache.camel.component.http4.ProxyHttpClientConfigurer.java
public void configureHttpClient(HttpClient client) { client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(host, port, scheme)); if (username != null && password != null) { Credentials defaultcreds;// ww w .j av a 2s. c o m if (domain != null) { defaultcreds = new NTCredentials(username, password, ntHost, domain); } else { defaultcreds = new UsernamePasswordCredentials(username, password); } ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds); } }
From source file:com.imagesleuth.imagesleuthclient2.Poster.java
public Poster(String url, String user, String password) { Test.testNull(url);/*from www. j a va 2 s. c o m*/ Test.testNull(user); Test.testNull(password); //System.out.println("user: " + user + " password: " + password); harray.add(new BasicHeader("Authorization", "Basic " + Base64.encodeBase64String((user + ":" + password).getBytes()))); urlval = (!url.startsWith("http")) ? "http://" + url + "/api/v1/job" : url + "/api/v1/job"; System.out.println("Poster: post url " + urlval); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password); credsProvider.setCredentials(AuthScope.ANY, credentials); requestConfig = RequestConfig.custom().setSocketTimeout(50000).setConnectTimeout(30000).build(); }