List of usage examples for org.apache.http.auth AuthScope ANY_PORT
int ANY_PORT
To view the source code for org.apache.http.auth AuthScope ANY_PORT.
Click Source Link
From source file:org.megam.deccanplato.http.TransportMachinery.java
public static TransportResponse post(TransportTools nuts) throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(nuts.urlString()); System.out.println("NUTS" + nuts.toString()); 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 w w w .ja v a 2 s . com //this else part statements for other providers else { httppost.addHeader(headerEntry.getKey(), headerEntry.getValue()); } } } if (nuts.fileEntity() != null) { httppost.setEntity(nuts.fileEntity()); } if (nuts.pairs() != null && (nuts.contentType() == null)) { httppost.setEntity(new UrlEncodedFormEntity(nuts.pairs())); } if (nuts.contentType() != null) { httppost.setEntity(new StringEntity(nuts.contentString(), nuts.contentType())); } TransportResponse transportResp = null; System.out.println(httppost.toString()); try { HttpResponse httpResp = httpclient.execute(httppost); transportResp = new TransportResponse(httpResp.getStatusLine(), httpResp.getEntity(), httpResp.getLocale()); } finally { httppost.releaseConnection(); } return transportResp; }
From source file:org.janusgraph.diskstorage.es.rest.util.BasicAuthHttpClientConfigCallback.java
public BasicAuthHttpClientConfigCallback(final String realm, final String username, final String password) { Preconditions.checkArgument(StringUtils.isNotEmpty(username), "HTTP Basic Authentication: username must be provided"); Preconditions.checkArgument(StringUtils.isNotEmpty(password), "HTTP Basic Authentication: password must be provided"); credentialsProvider = new BasicCredentialsProvider(); final AuthScope authScope; if (StringUtils.isNotEmpty(realm)) { authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME); } else {/*from w w w . j a va 2 s . c om*/ authScope = AuthScope.ANY; } credentialsProvider.setCredentials(authScope, new UsernamePasswordCredentials(username, password)); }
From source file:com.moarub.kipptapi.KipptAPIToken.java
@Override protected StringBuilder doInBackground(String... u) { String username = u[0];// w w w . j av a2 s . c o m String password = u[1]; DefaultHttpClient client = new DefaultHttpClient(); Credentials creds = new UsernamePasswordCredentials(username, password); client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds); try { HttpGet request = new HttpGet(reqTokenUrl); HttpResponse response = client.execute(request); return ShareMoreUtils.getResponseString(response); } catch (ClientProtocolException e) { Log.d("ApiTokenFailure", "Can't fetch API Token " + e.getMessage()); return null; } catch (IOException e) { Log.d("ApiTokenFailure", "Can't fetch API Token " + e.getMessage()); return null; } }
From source file:org.dataconservancy.archive.impl.fcrepo.ri.RIClient.java
public RIClient(FedoraCredentials credentials, HttpClientConfig httpClientConfig) { this.riEndpoint = credentials.getBaseUrl() + "/risearch"; this.httpClient = new MultiThreadedHttpClient(httpClientConfig); httpClient.getCredentialsProvider().setCredentials( new AuthScope(credentials.getBaseUrl().getHost(), AuthScope.ANY_PORT), new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword())); }
From source file:eu.diacron.crawlservice.app.Util.java
public static String getCrawlid(URL urltoCrawl) { String crawlid = ""; System.out.println("start crawling page"); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(Configuration.REMOTE_CRAWLER_USERNAME, Configuration.REMOTE_CRAWLER_PASS)); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); try {//from ww w .ja va2s . co m //HttpPost httppost = new HttpPost("http://diachron.hanzoarchives.com/crawl"); HttpPost httppost = new HttpPost(Configuration.REMOTE_CRAWLER_URL_CRAWL_INIT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("name", UUID.randomUUID().toString())); urlParameters.add(new BasicNameValuePair("scope", "page")); urlParameters.add(new BasicNameValuePair("seed", urltoCrawl.toString())); httppost.setEntity(new UrlEncodedFormEntity(urlParameters)); System.out.println("Executing request " + httppost.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httppost); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); System.out.println("----------------------------------------"); BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String inputLine; while ((inputLine = in.readLine()) != null) { crawlid = inputLine; } in.close(); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } catch (IOException ex) { Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); } finally { try { httpclient.close(); } catch (IOException ex) { Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex); } } return crawlid; }
From source file:org.wso2.developerstudio.appfactory.core.client.RssClient.java
public static String getDBinfo(String operation, String dsBaseUrl) { String url = dsBaseUrl + "NDataSourceAdmin"; DefaultHttpClient client = new DefaultHttpClient(); client = (DefaultHttpClient) HttpsJaggeryClient.wrapClient(client, url); client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(Authenticator.getInstance().getCredentials().getUser(), Authenticator.getInstance().getCredentials().getPassword())); // Generate BASIC scheme object and stick it to the execution context BasicScheme basicAuth = new BasicScheme(); BasicHttpContext context = new BasicHttpContext(); context.setAttribute("preemptive-auth", basicAuth); client.addRequestInterceptor(new PreemptiveAuth(), 0); HttpPost post = new HttpPost(url); String sopactionValue = "urn:" + operation; post.addHeader("SOAPAction", sopactionValue); String body = createPayLoad(operation); try {/*w ww . ja va2 s .c o m*/ StringEntity entity = new StringEntity(body.toString(), "text/xml", HTTP.DEFAULT_CONTENT_CHARSET); post.setEntity(entity); HttpResponse response = client.execute(post); if (200 == response.getStatusLine().getStatusCode()) { HttpEntity entityGetAppsOfUser = response.getEntity(); BufferedReader rd = new BufferedReader(new InputStreamReader(entityGetAppsOfUser.getContent())); StringBuilder sb = new StringBuilder(); String line = ""; while ((line = rd.readLine()) != null) { sb.append(line); } String respond = sb.toString(); EntityUtils.consume(entityGetAppsOfUser); return respond; } } catch (Exception e) { // log.error("Jenkins Client err", e); } return null; }
From source file:org.energyos.espi.thirdparty.web.ClientRestTemplate.java
public ClientRestTemplate(String username, String password) { DefaultHttpClient httpClient = new DefaultHttpClient(); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); httpClient.setCredentialsProvider(credentialsProvider); httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient); this.setRequestFactory(rf); }
From source file:com.github.restdriver.clientdriver.integration.BasicAuthTest.java
@Test public void basicAuthWorks() throws Exception { clientDriver.addExpectation(onRequestTo("/").withBasicAuth("Aladdin", "open sesame"), giveEmptyResponse().withStatus(418)).anyTimes(); DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", AuthScope.ANY_PORT), new UsernamePasswordCredentials("Aladdin", "open sesame")); HttpHost host = new HttpHost("localhost", 12345); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth);//from ww w . ja va 2 s. co m BasicHttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, authCache); List<String> authPrefs = new ArrayList<String>(); authPrefs.add(AuthPolicy.BASIC); client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authPrefs); HttpGet get = new HttpGet(clientDriver.getBaseUrl() + "/"); HttpResponse response = client.execute(host, get, context); assertThat(response.getStatusLine().getStatusCode(), is(418)); }
From source file:net.networksaremadeofstring.rhybudd.ZenossAPICore.java
@Override public boolean Login(ZenossCredentials credentials) throws Exception { if (credentials.URL.contains("https://")) { this.PrepareSSLHTTPClient(); } else {/*ww w . j a va2 s. c o m*/ this.PrepareHTTPClient(); //httpclient = new DefaultHttpClient(); } if (!credentials.BAUser.equals("") || !credentials.BAPassword.equals("")) { //Log.i("Auth","We have some auth credentials"); CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(credentials.BAUser, credentials.BAPassword)); httpclient.setCredentialsProvider(credProvider); } HttpPost httpost = new HttpPost(credentials.URL + "/zport/acl_users/cookieAuthHelper/login"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("__ac_name", credentials.UserName)); nvps.add(new BasicNameValuePair("__ac_password", credentials.Password)); nvps.add(new BasicNameValuePair("submitted", "true")); nvps.add(new BasicNameValuePair("came_from", credentials.URL + "/zport/dmd")); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); // Response from POST not needed, just the cookie HttpResponse response = httpclient.execute(httpost); // Consume so we can reuse httpclient response.getEntity().consumeContent(); //Set the variables for later this.ZENOSS_INSTANCE = credentials.URL; this.ZENOSS_USERNAME = credentials.UserName; this.ZENOSS_PASSWORD = credentials.Password; Log.e("CheckLoggedIn", Integer.toString(response.getStatusLine().getStatusCode())); reqCount++; return this.CheckLoggedIn(); }
From source file:com.restfiddle.handler.http.auth.BasicAuthHandler.java
/** * TODO : Not used anywhere right now.// www .ja va2 s .co m */ public CredentialsProvider prepareBasicAuth(String userName, String password) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, userName); provider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), credentials); return provider; }