List of usage examples for org.apache.http.auth AuthScope AuthScope
public AuthScope(final String host, final int port, final String realm)
From source file:org.cvasilak.jboss.mobile.app.net.TalkToJBossServerTask.java
public TalkToJBossServerTask(Context context, Server server, Callback callback, boolean shouldProcessRequest) { this.context = context; this.server = server; this.callback = callback; this.shouldProcessRequest = shouldProcessRequest; this.client = CustomHTTPClient.getHttpClient(); this.jsonBuilder = ((JBossAdminApplication) context.getApplicationContext()).getJSONBuilder(); this.jsonParser = ((JBossAdminApplication) context.getApplicationContext()).getJSONParser(); Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword()); client.getCredentialsProvider().setCredentials( new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials); }
From source file:org.geomajas.layer.common.proxy.LayerHttpServiceTest.java
@Test public void testAuthentication() throws IOException { // TODO: there is something wrong with cache invalidation, using uuid for now !!! try {//from www . j av a 2 s.c o m cachingLayerHttpService.getStream("http://somehost/" + UUID.randomUUID().toString(), new MockProxyLayer("layer1")); } catch (Exception e) { // ok to fail } // check the authentication CredentialsProvider p = cachingLayerHttpService.getClient().getCredentialsProvider(); Credentials cc = p.getCredentials(new AuthScope("somehost", 80, "realm-layer1")); Assert.assertEquals("user-layer1", cc.getUserPrincipal().getName()); Assert.assertEquals("password-layer1", cc.getPassword()); // check for layer 2 try { cachingLayerHttpService.getStream("https://somehost/" + UUID.randomUUID().toString(), new MockProxyLayer("layer2")); } catch (Exception e) { // ok to fail } // check the authentication p = cachingLayerHttpService.getClient().getCredentialsProvider(); cc = p.getCredentials(new AuthScope("somehost", 443, "realm-layer2")); Assert.assertEquals("user-layer2", cc.getUserPrincipal().getName()); Assert.assertEquals("password-layer2", cc.getPassword()); // TODO: test functioning of interceptors (without setting up connection ?) !!! Assert.assertEquals(2, interceptors.getMap().size()); }
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 {/*w ww. j ava 2 s . c o m*/ return executor; } } return executor; }
From source file:org.cvasilak.jboss.mobile.admin.net.UploadToJBossServerTask.java
public UploadToJBossServerTask(Context context, Server server, Callback callback) { this.context = context; this.client = CustomHTTPClient.getHttpClient(); this.server = server; this.callback = callback; this.gjson = ((JBossAdminApplication) context.getApplicationContext()).getJSONParser(); this.parser = new JsonParser(); // enable digest authentication if (server.getUsername() != null && !server.getUsername().equals("")) { Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword()); client.getCredentialsProvider().setCredentials( new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials); }//from www . java2 s . c o m }
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: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.j av a 2s. 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:com.mondora.chargify.controller.ChargifyAdapter.java
protected void setup(String key, String domain) { this.domain = domain; this.key = key; host = new HttpHost(domain + ".chargify.com", 443, "https"); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(key, "x"); credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(domain + ".chargify.com", 443, "ChargifyAdapter API"), creds); // todo preemtive and cache autentication // client.getParams().setAuthenticationPreemptive(true); // org.apache.http.client.AuthCache authCache = new BasicAuthCache(); // // Generate BASIC scheme object and add it to the local auth cache // BasicScheme basicAuth = new BasicScheme(); // authCache.put("chargify.com", basicAuth); if (logger.isDebugEnabled()) logger.debug("ChargifyAdapter client created for domain " + domain); }
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 w w w . jav a 2s . c o m } return executor; }
From source file:org.janusgraph.diskstorage.es.rest.util.BasicAuthHttpClientConfigCallbackTest.java
@Test public void testSetDefaultCredentialsProviderWithRealm() throws Exception { final CredentialsProvider cp = basicAuthTestBase(HTTP_REALM); // expected: will match any host in that specific realm final Credentials credentialsForRealm1 = cp.getCredentials(new AuthScope("dummyhost1", 1234, HTTP_REALM)); assertEquals(HTTP_USER, credentialsForRealm1.getUserPrincipal().getName()); assertEquals(HTTP_PASSWORD, credentialsForRealm1.getPassword()); // ...but not in any other realms final Credentials credentialsForRealm3 = cp .getCredentials(new AuthScope("dummyhost1", 1234, "Not_" + HTTP_REALM)); assertNull(credentialsForRealm3);/*w ww .j a va2 s . c om*/ }
From source file:org.apache.maven.wagon.providers.http.BasicAuthScope.java
/** * Create an authScope given the /repository/host and /repository/password * and the /server/basicAuth or /server/proxyBasicAuth host, port and realm * settings. The basicAuth setting should override the repository settings * host and/or port if host, port or realm is set to "ANY". * <p/>/*from www.j ava 2 s.c o m*/ * Realm can also be set to a specific string and will be set if * /server/basicAuthentication/realm is non-null * * @param host The server setting's /server/host value * @param port The server setting's /server/port value * @return */ public AuthScope getScope(String host, int port) { if (getHost() != null // && "ANY".compareTo(getHost()) == 0 // && getPort() != null // && "ANY".compareTo(getPort()) == 0 // && getRealm() != null // && "ANY".compareTo(getRealm()) == 0) { return AuthScope.ANY; } String scopeHost = host; if (getHost() != null) { if ("ANY".compareTo(getHost()) == 0) { scopeHost = AuthScope.ANY_HOST; } else { scopeHost = getHost(); } } int scopePort = port > -1 ? port : AuthScope.ANY_PORT; // -1 for server/port settings does this, but providing an override here // in // the BasicAuthScope config if (getPort() != null) { if ("ANY".compareTo(getPort()) == 0) { scopePort = AuthScope.ANY_PORT; } else { scopePort = Integer.parseInt(getPort()); } } String scopeRealm = AuthScope.ANY_REALM; if (getRealm() != null) { if ("ANY".compareTo(getRealm()) != 0) { scopeRealm = getRealm(); } else { scopeRealm = getRealm(); } } return new AuthScope(scopeHost, scopePort, scopeRealm); }