List of usage examples for org.apache.http.auth AuthScope ANY_SCHEME
String ANY_SCHEME
To view the source code for org.apache.http.auth AuthScope ANY_SCHEME.
Click Source Link
From source file:com.datatorrent.stram.util.WebServicesClientTest.java
public static void checkUserCredentials(String username, String password, AuthScheme authScheme) throws NoSuchFieldException, IllegalAccessException { CredentialsProvider provider = getCredentialsProvider(); String httpScheme = AuthScope.ANY_SCHEME; if (authScheme == AuthScheme.BASIC) { httpScheme = AuthSchemes.BASIC;//w w w.ja v a2 s . c om } else if (authScheme == AuthScheme.DIGEST) { httpScheme = AuthSchemes.DIGEST; } AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, httpScheme); Credentials credentials = provider.getCredentials(authScope); Assert.assertNotNull("Credentials", credentials); Assert.assertTrue("Credentials type is user", UsernamePasswordCredentials.class.isAssignableFrom(credentials.getClass())); UsernamePasswordCredentials pwdCredentials = (UsernamePasswordCredentials) credentials; Assert.assertEquals("Username", username, pwdCredentials.getUserName()); Assert.assertEquals("Password", password, pwdCredentials.getPassword()); }
From source file:org.ow2.bonita.facade.rest.apachehttpclient.ApacheHttpClientUtil.java
public static HttpClient getHttpClient(String serverAddress, String username, String password) throws URISyntaxException { URI serverURI = new URI(serverAddress); DefaultHttpClient client = new DefaultHttpClient(); AuthScope authScope = new AuthScope(serverURI.getHost(), serverURI.getPort(), AuthScope.ANY_REALM, AuthScope.ANY_SCHEME); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); client.getCredentialsProvider().setCredentials(authScope, credentials); return client; }
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 2s . c om authScope = AuthScope.ANY; } credentialsProvider.setCredentials(authScope, new UsernamePasswordCredentials(username, password)); }
From source file:be.fedict.trust.Credential.java
/** * Any scheme is allowed./*from w w w . j a va 2 s . c o m*/ * * @param host * @param port * @param realm * @param username * @param password */ public Credential(String host, int port, String realm, String username, String password) { this(host, port, realm, AuthScope.ANY_SCHEME, username, password); }
From source file:org.apache.cloudstack.storage.datastore.util.NexentaNmsClient.java
protected DefaultHttpClient getClient() { if (httpClient == null) { if (nmsUrl.getSchema().equalsIgnoreCase("http")) { httpClient = getHttpClient(); } else {//w w w .j av a2 s.com httpClient = getHttpsClient(); } AuthScope authScope = new AuthScope(nmsUrl.getHost(), nmsUrl.getPort(), AuthScope.ANY_SCHEME, "basic"); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(nmsUrl.getUsername(), nmsUrl.getPassword()); httpClient.getCredentialsProvider().setCredentials(authScope, credentials); } return httpClient; }
From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.Proxies.java
public static Executor proxyAuthentication(Executor executor, URI target) throws IOException { IProxyData proxy = getProxyData(target).orNull(); if (proxy != null) { HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); if (proxy.getUserId() != null) { String userId = getUserName(proxy.getUserId()).orNull(); String pass = proxy.getPassword(); String workstation = getWorkstation().orNull(); String domain = getUserDomain(proxy.getUserId()).orNull(); return executor .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, "ntlm"), new NTCredentials(userId, pass, workstation, domain)) .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(userId, pass)); } else {//from w w w .j ava2s. c o m return executor; } } return executor; }
From source file:org.gradle.internal.resource.transport.http.HttpConnectorFactory.java
private Set<String> getAuthSchemes(Collection<Authentication> authenticationTypes) { Set<String> authSchemes = Sets.newHashSet(); for (Authentication authenticationType : authenticationTypes) { if (BasicAuthentication.class.isAssignableFrom(authenticationType.getClass())) { authSchemes.add(AuthPolicy.BASIC); } else if (DigestAuthentication.class.isAssignableFrom(authenticationType.getClass())) { authSchemes.add(AuthPolicy.DIGEST); } else {/*w w w .ja v a2s . c om*/ throw new IllegalArgumentException(String.format("Authentication type of '%s' is not supported.", authenticationType.getClass().getSimpleName())); } } if (authSchemes.size() == 0) { authSchemes.add(AuthScope.ANY_SCHEME); } return authSchemes; }
From source file:org.eclipse.oomph.setup.internal.sync.SyncUtil.java
public static Executor proxyAuthentication(Executor executor, URI uri) throws IOException { IProxyData proxy = getProxyData(uri); if (proxy != null) { HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); String proxyUserID = proxy.getUserId(); if (proxyUserID != null) { String userID = getUserName(proxyUserID); String password = proxy.getPassword(); String workstation = getWorkstation(); String domain = getUserDomain(proxyUserID); return executor .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, "ntlm"), new NTCredentials(userID, password, workstation, domain)) .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(userID, password)); }//from ww w . j ava 2 s . c o m } return executor; }
From source file:org.codelibs.fess.es.config.exentity.WebAuthentication.java
private AuthScope getAuthScope() { if (StringUtil.isBlank(getHostname())) { return AuthScope.ANY; }/*from w ww. ja v a2 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:de.fuberlin.agcsw.heraclitus.svont.client.core.ChangeLog.java
public static void updateChangeLog(OntologyStore os, SVoNtProject sp, String user, String pwd) { //load the change log from server try {/*from ww w . jav a2 s .c o m*/ //1. fetch Changelog URI URI u = sp.getChangelogURI(); //2. search for change log owl files DefaultHttpClient client = new DefaultHttpClient(); client.getCredentialsProvider().setCredentials( new AuthScope(u.getHost(), AuthScope.ANY_PORT, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(user, pwd)); HttpGet httpget = new HttpGet(u); System.out.println("executing request" + httpget.getRequestLine()); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = client.execute(httpget, responseHandler); System.out.println(response); List<String> files = ChangeLog.extractChangeLogFiles(response); ArrayList<ChangeLogElement> changelog = sp.getChangelog(); changelog.clear(); //4. sort the revisions for (int i = 0; i < files.size(); i++) { String fileName = files.get(i); System.out.println("rev sort: " + fileName); int rev = Integer.parseInt(fileName.split("\\.")[0]); changelog.add(new ChangeLogElement(URI.create(u + fileName), rev)); } Collections.sort(changelog, new SortChangeLogsElementsByRev()); //show sorted changelog System.out.print("["); for (ChangeLogElement cle : changelog) { System.out.print(cle.getRev() + ","); } System.out.println("]"); //5. map revision with SVN revisionInformations mapRevisionInformation(os, sp, changelog); //6. load change log files System.out.println("Load Changelog Files"); for (String s : files) { System.out.println(s); String req = u + s; httpget = new HttpGet(req); response = client.execute(httpget, responseHandler); // System.out.println(response); // save the changelog File persistent IFolder chlFold = sp.getChangeLogFolder(); IFile chlFile = chlFold.getFile(s); if (!chlFile.exists()) { chlFile.create(new ByteArrayInputStream(response.getBytes()), true, null); } os.getOntologyManager().loadOntology(new ReaderInputSource(new StringReader(response))); } System.out.println("Changelog Ontology successfully loaded"); //Show loaded onts Set<OWLOntology> onts = os.getOntologyManager().getOntologies(); for (OWLOntology o : onts) { System.out.println("loaded ont: " + o.getURI()); } //7 refresh possibly modified Mainontology os.getOntologyManager().reloadOntology(os.getMainOntologyLocalURI()); //8. recalculate Revision Information of the concept of this ontology sp.setRevisionMap(createConceptRevisionMap(os, sp)); sp.saveRevisionMap(); sp.saveRevisionInformationMap(); //9. show MetaInfos on ConceptTree ConceptTree.refreshConceptTree(os, os.getMainOntologyURI()); OntologyInformation.refreshOntologyInformation(os, os.getMainOntologyURI()); //shutdown http connection client.getConnectionManager().shutdown(); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (OWLOntologyCreationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (OWLReasonerException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SVNException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SVNClientException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } }