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:de.bytefish.fcmjava.client.tests.FakeFcmClientSettings.java
@Test public void testFcmClientWithProxySettings() throws Exception { // Create Settings: IFcmClientSettings settings = new FakeFcmClientSettings(); // Define the Credentials to be used: BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider(); // Set the Credentials (any auth scope used): basicCredentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("your_username", "your_password")); // Create the Apache HttpClientBuilder: HttpClientBuilder httpClientBuilder = HttpClientBuilder.create() // Set the Proxy Address: .setProxy(new HttpHost("your_hostname", 1234)) // Set the Authentication Strategy: .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()) // Set the Credentials Provider we built above: .setDefaultCredentialsProvider(basicCredentialsProvider); // Create the DefaultHttpClient: DefaultHttpClient httpClient = new DefaultHttpClient(settings, httpClientBuilder); // Finally build the FcmClient: try (IFcmClient client = new FcmClient(settings, httpClient)) { // TODO Work with the Proxy ... }// ww w. j a v a 2 s . co m }
From source file:org.apache.jena.jdbc.remote.connections.TestRemoteEndpointConnectionWithAuth.java
/** * Setup for the tests by allocating a Fuseki instance to work with * @throws IOException /*from w ww . ja va 2 s .c o m*/ */ @BeforeClass public static void setup() throws IOException { SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD); FusekiTestAuth.setupServer(true, sh); BasicCredentialsProvider credsProv = new BasicCredentialsProvider(); credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, PASSWORD)); client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build(); }
From source file:it.cloudicaro.disit.kb.rdf.HttpUtil.java
public static String get(URL url, String accept, String user, String passwd) throws Exception { //System.out.println("GET "+url); HttpClient client = HttpClients.createDefault(); HttpGet request = new HttpGet(url.toURI()); if (accept != null) request.addHeader("Accept", accept); HttpClientContext context = HttpClientContext.create(); if (user != null && passwd != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, passwd)); /*// Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth);*/ // Add AuthCache to the execution context context.setCredentialsProvider(credsProvider); }// w w w. j av a 2s. c o m HttpResponse response = client.execute(request, context); StatusLine s = response.getStatusLine(); int code = s.getStatusCode(); //System.out.println(code); if (code != 200) throw new Exception( "failed access to " + url.toString() + " code: " + code + " " + s.getReasonPhrase()); Reader reader = null; try { reader = new InputStreamReader(response.getEntity().getContent()); StringBuilder sb = new StringBuilder(); { int read; char[] cbuf = new char[1024]; while ((read = reader.read(cbuf)) != -1) { sb.append(cbuf, 0, read); } } return sb.toString(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:net.adamcin.httpsig.http.apache4.Http4Util.java
public static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId) { if (client == null) { throw new NullPointerException("client"); }//from w w w. j av a 2 s . co m if (keychain == null) { throw new NullPointerException("keychain"); } client.getAuthSchemes().register(Constants.SCHEME, new AuthSchemeFactory() { public AuthScheme newInstance(HttpParams params) { return new Http4SignatureAuthScheme(); } }); Signer signer = new Signer(keychain, keyId); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new SignerCredentials(signer)); client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(Constants.SCHEME)); HttpClientParams.setAuthenticating(client.getParams(), true); }
From source file:org.lorislab.armonitor.util.RestClient.java
/** * Gets the rest-service client./*from w w w . j a va 2s .c om*/ * * @param <T> the rest-service client implementation. * @param clazz the rest-service class. * @param url the server URL. * @param username the username. * @param password the password. * @param auth the authentication flag. * @exception Exception if the method fails. * * @return the the rest-service client instance. */ public static <T> T getClient(final Class<T> clazz, String url, boolean auth, String username, char[] password) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); if (url.startsWith(HTTPS)) { SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme(HTTPS, 443, sslSocketFactory)); } if (auth) { BasicCredentialsProvider provider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(username, new String(password)); provider.setCredentials(AuthScope.ANY, credentials); httpClient.setCredentialsProvider(provider); } return ProxyFactory.create(clazz, url, new ApacheHttpClient4Executor(httpClient)); }
From source file:org.mule.modules.constantcontact.RequestExecutor.java
public RequestExecutor(String apiKey, String username, String password) { String loginUsername = apiKey + "%" + username; httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(loginUsername, password)); httpclient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, Arrays.asList(AuthPolicy.BASIC)); }
From source file:org.lorislab.armonitor.client.MonitorClient.java
/** * Creates the monitor service.//from w w w .j a v a 2 s .c om * * @param url the URL. * @param username the user name. * @param password the password. * @return the monitor service. */ private static MonitorService createService(URL url, String username, String password, boolean auth) { ResteasyProviderFactory rpf = ResteasyProviderFactory.getInstance(); RegisterBuiltin.register(rpf); String tmp = url.toString(); if (!tmp.endsWith("/")) { tmp = tmp + "/"; } tmp = tmp + APP_URL; if (auth) { Credentials credentials = new UsernamePasswordCredentials(username, password); DefaultHttpClient httpClient = new DefaultHttpClient(); BasicCredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(AuthScope.ANY, credentials); httpClient.setCredentialsProvider(provider); return ProxyFactory.create(MonitorService.class, tmp, new ApacheHttpClient4Executor(httpClient)); } return ProxyFactory.create(MonitorService.class, tmp); }
From source file:com.liferay.portal.search.solr.http.BasicAuthPoolingHttpClientFactory.java
@Override protected void configure(DefaultHttpClient defaultHttpClient) { if (Validator.isBlank(_username)) { return;//www. j av a 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:de.yaio.commons.http.HttpUtils.java
/** * execute the prepared Request//from www .j ava 2 s .co m * @param request request to call * @param username username for auth * @param password password for auth * @return HttpResponse * @throws ClientProtocolException possible Exception if Request-state <200 > 299 * @throws IOException possible Exception if Request-state <200 > 299 */ public static HttpResponse executeRequest(final HttpUriRequest request, final String username, final String password) throws ClientProtocolException, IOException { CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password); provider.setCredentials(AuthScope.ANY, credentials); HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build(); HttpResponse response = client.execute(request); return response; }
From source file:org.deegree.maven.utils.HttpUtils.java
public static HttpClient getAuthenticatedHttpClient(ServiceIntegrationTestHelper helper) { DefaultHttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 30000); HttpConnectionParams.setSoTimeout(client.getParams(), 1200000); client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("deegree", "deegree")); // preemptive authentication used to be easier in pre-4.x httpclient AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); HttpHost host = new HttpHost("localhost", Integer.parseInt(helper.getPort())); authCache.put(host, basicAuth);/*from w w w . ja v a 2s. c o m*/ BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(AUTH_CACHE, authCache); return client; }