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:net.seedboxer.seedroid.utils.RestClient.java
public void AddBasicAuthentication(String username, String password) { credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); }
From source file:com.ibm.connectors.splunklog.SplunkHttpConnection.java
public Properties sendLogEvent(SplunkConnectionData connData, byte[] thePayload, Properties properties) throws ConnectorException { HttpClient myhClient = HttpClients.custom().setConnectionManager(this.cm).build(); HttpClientContext myhContext = HttpClientContext.create(); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(connData.getUser(), connData.getPass())); AuthCache authCache = new BasicAuthCache(); authCache.put(new HttpHost(connData.getHost(), Integer.parseInt(connData.getPort()), connData.getScheme()), new BasicScheme()); myhContext.setCredentialsProvider(credsProvider); myhContext.setAuthCache(authCache);//from w w w .j a va 2 s.com HttpPost myhPost = new HttpPost(connData.getSplunkURI()); ByteArrayEntity payload = new ByteArrayEntity(thePayload); try { myhPost.setEntity(payload); HttpResponse response = myhClient.execute(myhPost, myhContext); Integer statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200 && !connData.getIgnoreSplunkErrors()) { throw new ConnectorException( "Error posting log event to Splunk: " + response.getStatusLine().toString()); } System.out.println(response.getStatusLine().toString()); properties.setProperty("status", String.valueOf(statusCode)); Integer leasedConns = Integer .valueOf(((PoolingHttpClientConnectionManager) this.cm).getTotalStats().getLeased()); properties.setProperty("conns_leased", leasedConns.toString()); Integer availConns = Integer .valueOf(((PoolingHttpClientConnectionManager) this.cm).getTotalStats().getAvailable()); properties.setProperty("conns_available", availConns.toString()); } catch (IOException e) { e.fillInStackTrace(); throw new ConnectorException(e.toString()); } return properties; }
From source file:de.escidoc.core.test.common.fedora.TripleStoreTestBase.java
protected DefaultHttpClient getHttpClient() throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); URL url = new URL(getFedoraUrl()); AuthScope m_authScope = new AuthScope(url.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_REALM); UsernamePasswordCredentials m_creds = new UsernamePasswordCredentials("fedoraAdmin", "fedoraAdmin"); httpClient.getCredentialsProvider().setCredentials(m_authScope, m_creds); return httpClient; }
From source file:org.duracloud.common.web.RestHttpHelper.java
public RestHttpHelper(Credential credential, int socketTimeoutMs) { if (credential != null) { credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(credential.getUsername(), credential.getPassword())); }/*from w w w . j a va 2 s . c o m*/ this.socketTimeoutMs = socketTimeoutMs; }
From source file:me.willowcheng.makerthings.util.MjpegStreamer.java
public InputStream httpRequest(String url, String usr, String pwd) { HttpResponse res = null;/*from ww w. j a v a 2 s .c o m*/ DefaultHttpClient httpclient = new DefaultHttpClient(); CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(usr, pwd)); httpclient.setCredentialsProvider(credProvider); Log.d(TAG, "1. Sending http request"); try { res = httpclient.execute(new HttpGet(URI.create(url))); Log.d(TAG, "2. Request finished, status = " + res.getStatusLine().getStatusCode()); if (res.getStatusLine().getStatusCode() == 401) { //You must turn off camera User Access Control before this will work return null; } Log.d(TAG, "content-type = " + res.getEntity().getContentType()); Log.d(TAG, "content-encoding = " + res.getEntity().getContentEncoding()); return res.getEntity().getContent(); } catch (ClientProtocolException e) { e.printStackTrace(); Log.d(TAG, "Request failed-ClientProtocolException", e); //Error connecting to camera } catch (IOException e) { e.printStackTrace(); Log.d(TAG, "Request failed-IOException", e); //Error connecting to camera } return null; }
From source file:org.dataconservancy.dcs.integration.main.IngestTest.java
@Test public void sipIngest_db_authentication() throws Exception { client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials("seadva@gmail.com", hashPassword("password"))); String agentId = "agent:" + UUID.randomUUID().toString(); Agent agent = new Agent(); agent.setFirstName("Kavitha"); agent.setLastName("Chandrasekar"); agent.setId(agentId);//from w w w . jav a 2s. com agent.setEntityName(agent.getLastName()); agent.setEntityCreatedTime(new Date()); agent.setEntityLastUpdatedTime(new Date()); new RegistryClient(registryUrl).postAgent(agent, "Curator"); File sipFile = new File(IngestTest.class.getResource("/" + "sampleSip_2.xml").getPath()); ResearchObject sip = new SeadXstreamStaxModelBuilder() .buildSip(new FileInputStream(sipFile.getAbsolutePath())); Collection<DcsDeliverableUnit> dus = sip.getDeliverableUnits(); for (DcsDeliverableUnit du : dus) { if (du.getParents() == null || du.getParents().size() == 0) { SeadPerson submitter = new SeadPerson(); submitter.setName(agent.getFirstName() + " " + agent.getLastName()); submitter.setId(agentId); submitter.setIdType("registryId"); ((SeadDeliverableUnit) du).setSubmitter(submitter); } } sip.setDeliverableUnits(dus); new SeadXstreamStaxModelBuilder().buildSip(sip, new FileOutputStream(sipFile.getAbsolutePath())); int code = doDeposit(sipFile); assertEquals(code, 202); }
From source file:de.escidoc.core.http.HttpClientBuilderImpl.java
@Override public HttpClientBuilder withUsernamePasswordCredentials(final String urlString, final String username, final String password) { final URL url; try {/*w w w . ja v a 2 s . c o m*/ url = new URL(urlString); } catch (final MalformedURLException e) { throw new IllegalArgumentException("Invalid url '" + urlString + "'.", e); } final AuthScope authScope = new AuthScope(url.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_REALM); final Credentials usernamePasswordCredentials = new UsernamePasswordCredentials(username, password); this.httpClient.getCredentialsProvider().setCredentials(authScope, usernamePasswordCredentials); return this; }
From source file:org.codelibs.fess.es.config.exentity.WebAuthentication.java
private AuthScope getAuthScope() { if (StringUtil.isBlank(getHostname())) { return AuthScope.ANY; }/* w ww.j a v a 2 s . c o m*/ int p; if (getPort() == null) { p = AuthScope.ANY_PORT; } else { p = getPort().intValue(); } String r = getAuthRealm(); if (StringUtil.isBlank(r)) { r = AuthScope.ANY_REALM; } String s = getProtocolScheme(); if (StringUtil.isBlank(s) || Constants.NTLM.equals(s)) { s = AuthScope.ANY_SCHEME; } return new AuthScope(getHostname(), p, r, s); }
From source file:org.apache.maven.wagon.providers.http.BasicAuthScopeTest.java
/** * Test AuthScope where original port is -1, which should result in ANY *//*w w w. j a v a2s . c o m*/ @Test public void testGetScopeOriginalPortIsNegativeOne() { BasicAuthScope scope = new BasicAuthScope(); AuthScope authScope = scope.getScope("original.host.com", -1); Assert.assertEquals(AuthScope.ANY_PORT, authScope.getPort()); }
From source file:net.bioclipse.dbxp.business.DbxpManager.java
public static HttpResponse postValues(HashMap<String, String> postvars, String url) throws NoSuchAlgorithmException, ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(userName, password)); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); Iterator<Entry<String, String>> it = postvars.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> next = (Map.Entry<String, String>) it.next(); Map.Entry<String, String> pairs = next; formparams.add(new BasicNameValuePair(pairs.getKey(), pairs.getValue())); }/*from w ww . j a va 2 s. c om*/ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); HttpPost httppost = new HttpPost(url); httppost.setEntity(entity); HttpContext localContext = new BasicHttpContext(); return httpclient.execute(httppost, localContext); }