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:aajavafx.CustomerMedicineController.java
public ObservableList<Medicines> getMedicines() throws IOException, JSONException { ObservableList<Medicines> medicines = FXCollections.observableArrayList(); //Managers manager = new Managers(); Gson gson = new Gson(); JSONObject jo = new JSONObject(); //........SSL Update CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("EMPLOYEE", "password"); provider.setCredentials(AuthScope.ANY, credentials); HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build(); HttpGet get = new HttpGet("http://localhost:8080/MainServerREST/api/medicines"); HttpResponse response = client.execute(get); System.out.println("RESPONSE IS: " + response); //................... // JSONArray jsonArray = new JSONArray(IOUtils.toString(new URL(MedicineRootURL), Charset.forName("UTF-8"))); JSONArray jsonArray = new JSONArray( IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8"))); System.out.println(jsonArray); for (int i = 0; i < jsonArray.length(); i++) { jo = (JSONObject) jsonArray.getJSONObject(i); Medicines medicine = gson.fromJson(jo.toString(), Medicines.class); System.out.println("JSON OBJECT #" + i + " " + jo); medicines.add(medicine);/*from ww w . ja v a 2 s. c om*/ } return medicines; }
From source file:com.sun.jersey.client.apache4.impl.AuthTest.java
public void testAuthInteractiveGet() { ResourceConfig rc = new DefaultResourceConfig(AuthResource.class); rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, LoggingFilter.class.getName()); startServer(rc);/*from w w w . j a v a 2s . co m*/ CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password")); DefaultApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider); ApacheHttpClient4 c = ApacheHttpClient4.create(config); WebResource r = c.resource(getUri().path("test").build()); assertEquals("GET", r.get(String.class)); }
From source file:org.fcrepo.integration.FedoraHtmlResponsesIT.java
License:asdf
private CredentialsProvider getFedoraAdminCredentials() { final CredentialsProvider credentials = new DefaultCredentialsProvider(); credentials.setCredentials(AuthScope.ANY, FEDORA_ADMIN_CREDENTIALS); return credentials; }
From source file:groovyx.net.http.ApacheHttpBuilder.java
private void basicAuth(final HttpClientContext c, final HttpConfig.Auth auth, final URI uri) { CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(AuthScope.ANY, //new AuthScope(uri.getHost(), port(uri)), new UsernamePasswordCredentials(auth.getUser(), auth.getPassword())); c.setCredentialsProvider(provider);// w w w. j ava 2 s . c om }
From source file:de.mendelson.comm.as2.send.MessageHttpUploader.java
/**Sets necessary HTTP authentication for this partner, depending on if it is an asny MDN that will be sent or an AS2 message. *If the partner is not configured to use HTTP authentication in any kind nothing will happen in here *///from w w w . j ava 2 s. co m private void setHTTPAuthentication(DefaultHttpClient client, Partner receiver, boolean isMDN) { HTTPAuthentication authentication = null; if (isMDN) { authentication = receiver.getAuthenticationAsyncMDN(); } else { authentication = receiver.getAuthentication(); } if (authentication.isEnabled()) { Credentials userPassCredentials = new UsernamePasswordCredentials(authentication.getUser(), authentication.getPassword()); client.getCredentialsProvider().setCredentials(AuthScope.ANY, userPassCredentials); BasicHttpContext localcontext = new BasicHttpContext(); // Generate BASIC scheme object and stick it to the local // execution context BasicScheme basicAuth = new BasicScheme(); localcontext.setAttribute("preemptive-auth", basicAuth); // Add as the first request interceptor client.addRequestInterceptor(new PreemptiveAuth(), 0); } }
From source file:com.ibm.watson.developer_cloud.professor_languo.pipeline.RnrMergerAndRanker.java
/** * Gets the rankers associated with the given credentials * //from w w w . j a v a2s.c o m * @return a list of ranker_ids of the active rankers * @throws ClientProtocolException * @throws IOException */ public List<String> getRankers() throws ClientProtocolException, IOException { List<String> rankerIds = new ArrayList<String>(); JSONArray rankers; // Create authorized HttpClient client = RankerCreationUtil.createHttpClient(AuthScope.ANY, creds); try { HttpGet httpget = new HttpGet(ranker_url); CloseableHttpResponse response = client.execute(httpget); try { String result = EntityUtils.toString(response.getEntity()); JSONObject jobject = (JSONObject) JSON.parse(result); rankers = jobject.getJSONArray("rankers"); for (int i = 0; i < rankers.size(); i++) { rankerIds.add((String) ((JSONObject) rankers.get(i)).get("ranker_id")); } } catch (NullPointerException | JSONException e) { logger.error(e.getMessage()); } finally { response.close(); } } finally { client.close(); } return rankerIds; }
From source file:org.codelibs.fess.es.config.exentity.DataConfig.java
private AuthScope getAuthScope(final String webAuthName, final String scheme, final Map<String, String> paramMap) { final String hostname = paramMap.get(CRAWLER_WEB_AUTH + "." + webAuthName + ".host"); final String port = paramMap.get(CRAWLER_WEB_AUTH + "." + webAuthName + ".port"); final String realm = paramMap.get(CRAWLER_WEB_AUTH + "." + webAuthName + ".realm"); AuthScope authScope;//from w w w . j a v a 2 s. co m if (StringUtil.isBlank(hostname)) { authScope = AuthScope.ANY; } else { int p = AuthScope.ANY_PORT; if (StringUtil.isNotBlank(port)) { try { p = Integer.parseInt(port); } catch (final NumberFormatException e) { logger.warn("Failed to parse " + port, e); } } String r = realm; if (StringUtil.isBlank(realm)) { r = AuthScope.ANY_REALM; } String s = scheme; if (StringUtil.isBlank(scheme) || Constants.NTLM.equals(scheme)) { s = AuthScope.ANY_SCHEME; } authScope = new AuthScope(hostname, p, r, s); } return authScope; }
From source file:com.sun.jersey.client.apache4.impl.AuthTest.java
@Ignore public void _testAuthInteractivePost() { ResourceConfig rc = new DefaultResourceConfig(AuthResource.class); rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, LoggingFilter.class.getName()); startServer(rc);//from ww w .j ava 2s. c o m CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password")); DefaultApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider); ApacheHttpClient4 c = ApacheHttpClient4.create(config); WebResource r = c.resource(getUri().path("test").build()); assertEquals("POST", r.post(String.class, "POST")); }
From source file:org.artifactory.util.HttpClientConfigurator.java
private boolean hasCredentials() { return credsProvider.getCredentials(AuthScope.ANY) != null; }