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.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.j av a2s.c o m*/ //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 {// ww w .j av a 2s. co m 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 ww . j a v a 2s . co 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: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 w w w . ja v a 2 s. c o 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 {//from ww w. j a va 2s . c om 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:net.networksaremadeofstring.rhybudd.ZenossAPICore.java
@Override public boolean Login(ZenossCredentials credentials) throws Exception { if (credentials.URL.contains("https://")) { this.PrepareSSLHTTPClient(); } else {/*from ww w . ja va2 s . c om*/ 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.//from w ww . j av a 2 s . com */ 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; }
From source file:com.kms.core.io.HttpUtil_In.java
public static CloseableHttpClient getHttpClient(final String SoeID, final String Password, final int type) { CloseableHttpClient httpclient;/*from w w w . ja va 2 s . c o m*/ // Auth Scheme final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.NTLM, new NTLMSchemeFactory()) .register(AuthSchemes.BASIC, new BasicSchemeFactory()) .register(AuthSchemes.DIGEST, new DigestSchemeFactory()) .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()) .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build(); // NTLM final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), //AuthScope("localhost", 8080), new NTCredentials(SoeID, Password, "dummy", "APAC")); //new NTCredentials( SoeID, Password,"APACKR081WV058", "APAC" )); // ------------- cookie start ------------------------ // Auction // Create a local instance of cookie store final CookieStore cookieStore = new BasicCookieStore(); // Cookie . final BasicClientCookie cookie = new BasicClientCookie("songdal_view", "YES"); cookie.setVersion(0); cookie.setDomain(".scourt.go.kr"); cookie.setPath("/"); cookieStore.addCookie(cookie); // ------------- cookie end ------------------------ if (type == 0) // TYPE.AuctionInput { // HTTP Client httpclient = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry) .setDefaultCredentialsProvider(credsProvider).build(); } else // SagunInput { // HTTP Client httpclient = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry) .setDefaultCredentialsProvider(credsProvider).setDefaultCookieStore(cookieStore).build(); } return httpclient; }
From source file:info.ajaxplorer.client.http.AjxpHttpClient.java
public void refreshCredentials(String user, String pass) { this.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(user, pass)); }