List of usage examples for org.apache.http.auth UsernamePasswordCredentials UsernamePasswordCredentials
public UsernamePasswordCredentials(final String userName, final String password)
From source file:de.yaio.commons.http.HttpUtils.java
/** * execute the prepared Request//from w w w . ja va 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:com.ibm.watson.retrieveandrank.app.rest.UtilityFunctions.java
public static HttpClientBuilder createHTTPBuilder(URI uri, String username, String password) { final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); final HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnTotal(128).setMaxConnPerRoute(32) .setDefaultRequestConfig(// w w w . j a v a 2 s . co m RequestConfig.copy(RequestConfig.DEFAULT).setRedirectsEnabled(true).build()); builder.setDefaultCredentialsProvider(credentialsProvider); builder.addInterceptorFirst(new PreemptiveAuthInterceptor()); return builder; }
From source file:com.udps.hive.jdbc.HttpBasicAuthInterceptor.java
public HttpBasicAuthInterceptor(String username, String password) { if (username != null) { credentials = new UsernamePasswordCredentials(username, password); }/*w w w . j a v a2 s . c o m*/ authScheme = new BasicScheme(); }
From source file:com.threatconnect.app.playbooks.db.tcapi.ConnectionUtil.java
/** * Adds proxy information to an http client builder * //from ww w . j a v a 2 s .c om * @param builder * the HttpClientBuilder builder to add the proxy information to * @param proxyHost * the host of the proxy server * @param proxyPort * the port of the proxy server * @param proxyUserName * the username to authenticate with the proxy server (optional) * @param proxyPassword * the password to authenticate with the proxy server (optional) */ public static void addProxy(final HttpClientBuilder builder, final String proxyHost, final Integer proxyPort, final String proxyUserName, final String proxyPassword) { // check to see if the the host or port are null if (proxyHost == null || proxyPort == null) { logger.warn("proxyHost and proxyPort are required to connect to a proxy"); } else { // add the proxy information to the builder builder.setProxy(new HttpHost(proxyHost, proxyPort)); // authentication required if (proxyUserName != null && proxyPassword != null) { // add the credentials to the proxy information Credentials credentials = new UsernamePasswordCredentials(proxyUserName, proxyPassword); AuthScope authScope = new AuthScope(proxyHost, proxyPort); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(authScope, credentials); builder.setDefaultCredentialsProvider(credsProvider); } } }
From source file:com.webbfontaine.valuewebb.startup.ProxyConfiguration.java
public void addProxy(AbstractHttpClient httpClient) { if (ApplicationProperties.isAllowProxy()) { LOGGER.debug("Adding PROXY for HTTP Client"); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials(userName, password)); httpClient.setCredentialsProvider(credsProvider); HttpHost proxy = new HttpHost(host, port, protocol); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else {/*from ww w . ja v a2s . c om*/ LOGGER.warn("HTTP Client has requested for PROXY but it is disabled."); } }
From source file:org.gbif.registry.utils.Installations.java
/** * Populate credentials used in Installation update ws request. * * @param installation Installation/*from w ww.j a v a 2s.co m*/ * * @return credentials */ public static UsernamePasswordCredentials credentials(Installation installation) { return new UsernamePasswordCredentials(installation.getKey().toString(), installation.getPassword()); }
From source file:org.mobicents.xcap.client.impl.auth.CredentialsImpl.java
/** * * @param user * @param password */ public CredentialsImpl(String user, String password) { wrappedCredentials = new UsernamePasswordCredentials(user, password); }
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:net.rcarz.jiraclient.BasicCredentials.java
/** * Sets the Authorization header for the given request. * * @param req HTTP request to authenticate *//*from w ww .ja va 2 s .co m*/ public void authenticate(HttpRequest req) { Credentials creds = new UsernamePasswordCredentials(username, password); req.addHeader(BasicScheme.authenticate(creds, "utf-8", false)); }
From source file:com.moarub.kipptapi.KipptAPIToken.java
@Override protected StringBuilder doInBackground(String... u) { String username = u[0];/*from w ww .j a v a 2 s.c o m*/ String password = u[1]; DefaultHttpClient client = new DefaultHttpClient(); Credentials creds = new UsernamePasswordCredentials(username, password); client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds); try { HttpGet request = new HttpGet(reqTokenUrl); HttpResponse response = client.execute(request); return ShareMoreUtils.getResponseString(response); } catch (ClientProtocolException e) { Log.d("ApiTokenFailure", "Can't fetch API Token " + e.getMessage()); return null; } catch (IOException e) { Log.d("ApiTokenFailure", "Can't fetch API Token " + e.getMessage()); return null; } }