List of usage examples for org.apache.http.auth UsernamePasswordCredentials UsernamePasswordCredentials
public UsernamePasswordCredentials(final String userName, final String password)
From source file:edu.harvard.iq.dataverse.DataCiteRESTfullClient.java
public DataCiteRESTfullClient(String url, String username, String password) throws IOException { this.url = url; try {/*from w ww . j a v a 2s . co m*/ context = HttpClientContext.create(); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(username, password)); context.setCredentialsProvider(credsProvider); httpClient = HttpClients.createDefault(); } catch (Exception ioe) { close(); logger.log(Level.SEVERE, "Fail to init Client", ioe); throw new RuntimeException("Fail to init Client", ioe); } }
From source file:co.aurasphere.botmill.skype.util.network.NetworkUtils.java
/** * Send.//w w w .j a va 2s . c o m * * @param request the request * @return the string */ private static String send(HttpRequestBase request) { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(null, null); provider.setCredentials(AuthScope.ANY, credentials); CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build(); logger.debug(request.getRequestLine().toString()); HttpResponse httpResponse = null; String response = null; try { httpResponse = httpClient.execute(request); response = logResponse(httpResponse); } catch (Exception e) { logger.error("Error during HTTP connection to Kik: ", e); } finally { try { httpClient.close(); } catch (IOException e) { logger.error("Error while closing HTTP connection: ", e); } } return response; }
From source file:org.torquebox.integration.arquillian.rack.AuthTest.java
@Test public void testBasicAuth() { String creds = "bmcwhirt@redhat.com:swordfish"; String encodedCreds = Base64.encodeBytes(creds.getBytes()); AuthScope authScope = new AuthScope("localhost", 8080); Credentials credentials = new UsernamePasswordCredentials("bmcwhirt@redhat.com", "swordfish"); driver.setCredentials(authScope, credentials); driver.get("http://localhost:8080/basic-auth"); WebElement element = driver.findElementById("auth_header"); assertNotNull(element);//ww w .j av a2 s . c om assertEquals("Basic " + encodedCreds, element.getText().trim()); }
From source file:com.natixis.appdynamics.traitements.GetInfoLicense.java
public Map<String, Object> RetrieveInfoLicense() throws ClientProtocolException, IOException { Map<String, Object> myMapInfoLicense = new HashMap<String, Object>(); HttpClient client = new DefaultHttpClient(); String[] chaineUrl = GetParamApplication.urlApm.split("/" + "/"); String hostApm = chaineUrl[1]; URI uri = null;//from w ww . j a v a 2s . co m try { uri = new URIBuilder().setScheme("http").setHost(hostApm).setPath(GetParamApplication.uriInfoLicense) .setParameter("startdate", GetDateInfoLicence()).setParameter("enddate", GetDateInfoLicence()) .build(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(new AuthScope(hostApm, 80), new UsernamePasswordCredentials(GetParamApplication.userApm, GetParamApplication.passwordApm)); HttpGet request = new HttpGet(uri); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); String jsonContent = EntityUtils.toString(entity); Reader stringReader = new StringReader(jsonContent); JsonReader rdr = Json.createReader(stringReader); JsonObject obj = rdr.readObject(); JsonArray results = obj.getJsonArray("usages"); for (JsonObject result : results.getValuesAs(JsonObject.class)) { BeanInfoLicense myBeanInfoLicense = new BeanInfoLicense(result.getString("agentType"), result.getInt("avgUnitsAllowed"), result.getInt("avgUnitsUsed")); myMapInfoLicense.put(result.getString("agentType"), myBeanInfoLicense); //System.out.println(result.getString("agentType")+","+result.getInt("avgUnitsAllowed")+","+result.getInt("avgUnitsUsed")); } return myMapInfoLicense; }
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:de.fraunhofer.iosb.ilt.tests.Constants.java
public static SensorThingsService createService(URL serviceUrl) throws MalformedURLException, URISyntaxException { SensorThingsService service = new SensorThingsService(serviceUrl); if (USE_OPENID_CONNECT) { service.setTokenManager(new TokenManagerOpenIDConnect().setTokenServerUrl(TOKEN_SERVER_URL) .setClientId(CLIENT_ID).setUserName(USERNAME).setPassword(PASSWORD)); }// ww w . jav a2 s .com if (USE_BASIC_AUTH) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); URL url = new URL(BASE_URL); credsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()), new UsernamePasswordCredentials(USERNAME, PASSWORD)); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider) .build(); service.setClient(httpclient); } return service; }
From source file:no.norrs.projects.andronary.tasks.DictListTask.java
@Override protected String[] doInBackground(String... lookup) { try {// w ww . j a va2 s . c o m System.out.println(String.format("%s : %s : %s", lookup[0], lookup[1], lookup[2])); if (lookup[0] == null) { dl.showError(new Exception("Press menu and configure up webservice.."), null); return null; } UsernamePasswordCredentials creds = null; if (lookup[1] != null && lookup[2] != null && !lookup[1].equalsIgnoreCase("") && !lookup[2].equalsIgnoreCase("")) { creds = new UsernamePasswordCredentials(lookup[1], lookup[2]); } DictonaryParser dp = new DictonaryParser(); Collection<String> results = dp.dictonaries(Uri.parse(String.format("%s/languages/", lookup[0])), creds); return results.toArray(new String[results.size()]); } catch (IOException ex) { Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(DictLookupTask.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:org.commonjava.indy.client.core.auth.BasicAuthenticator.java
@Override public HttpClientContext decoratePrototypeContext(AuthScope scope, SiteConfig location, PasswordType type, HttpClientContext ctx) {/*from w w w.j a v a2s .c o m*/ if (user != null) { final CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(scope, new UsernamePasswordCredentials(user, pass)); ctx.setCredentialsProvider(credProvider); } return ctx; }
From source file:com.liferay.portal.search.solr.http.BasicAuthPoolingHttpClientFactory.java
@Override protected void configure(DefaultHttpClient defaultHttpClient) { if (Validator.isBlank(_username)) { return;/* ww w . java 2 s . co m*/ } if (_authScope == null) { _authScope = AuthScope.ANY; } if (Validator.isNull(_password)) { _password = StringPool.BLANK; } CredentialsProvider credentialsProvider = defaultHttpClient.getCredentialsProvider(); credentialsProvider.setCredentials(_authScope, new UsernamePasswordCredentials(_username, _password)); }
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 {//w ww . j a va 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; }