List of usage examples for org.apache.http.auth UsernamePasswordCredentials UsernamePasswordCredentials
public UsernamePasswordCredentials(final String userName, final String password)
From source file:org.eclipse.ecf.internal.provider.filetransfer.httpclient4.HttpClientProxyCredentialProvider.java
public Credentials getCredentials(AuthScope authscope) { Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, HttpClientProxyCredentialProvider.class, "getCredentials " + authscope); //$NON-NLS-1$ // First check to see whether given authscope matches any authscope // already cached. Credentials result = matchCredentials(this.cachedCredentials, authscope); // If we have a match, return credentials if (result != null) return result; // If we don't have a match, first get ECF proxy, if any Proxy proxy = getECFProxy();/*from ww w .j av a 2 s.c o m*/ if (proxy == null) return null; // Make sure that authscope and proxy host and port match if (!matchAuthScopeAndProxy(authscope, proxy)) return null; // Then match scheme, and get credentials from proxy (if it's scheme we know about) Credentials credentials = null; if ("ntlm".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$ credentials = getNTLMCredentials(proxy); } else if ("basic".equalsIgnoreCase(authscope.getScheme()) || //$NON-NLS-1$ "digest".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$ final String proxyUsername = proxy.getUsername(); final String proxyPassword = proxy.getPassword(); // If credentials present for proxy then we're done if (proxyUsername != null) { credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword); } } else if ("negotiate".equalsIgnoreCase(authscope.getScheme())) { //$NON-NLS-1$ Trace.trace(Activator.PLUGIN_ID, "SPNEGO is not supported, if you can contribute support, please do so."); //$NON-NLS-1$ } else { Trace.trace(Activator.PLUGIN_ID, "Unrecognized authentication scheme."); //$NON-NLS-1$ } // Put found credentials in cache for next time if (credentials != null) cachedCredentials.put(authscope, credentials); return credentials; }
From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceProviderCatalogTests.java
@Before public void setupTest() throws IOException, ParserConfigurationException, SAXException { Properties setupProps = SetupProperties.setup(null); if (setupProps.getProperty("testBackwardsCompatability") != null && Boolean.parseBoolean(setupProps.getProperty("testBackwardsCompatability"))) { setupProps = SetupProperties.setup(setupProps.getProperty("version1Properties")); }/*w ww .j av a 2 s .c om*/ baseUrl = setupProps.getProperty("baseUri"); String userId = setupProps.getProperty("userId"); String pw = setupProps.getProperty("pw"); basicCreds = new UsernamePasswordCredentials(userId, pw); response = OSLCUtils.getResponseFromUrl(baseUrl, currentUrl, basicCreds, OSLCConstants.CT_DISC_CAT_XML); responseBody = EntityUtils.toString(response.getEntity()); //Get XML Doc from response doc = OSLCUtils.createXMLDocFromResponseBody(responseBody); }
From source file:org.sonar.ide.eclipse.wsclient.WSClientFactory.java
/** * Workaround for http://jira.codehaus.org/browse/SONAR-1586 *///from w w w . ja v a 2 s . co m private static void configureProxy(DefaultHttpClient httpClient, Host server) { try { IProxyData proxyData = getEclipseProxyFor(server); if (proxyData != null && !IProxyData.SOCKS_PROXY_TYPE.equals(proxyData.getType())) { LOG.debug("Proxy for [{}] - [{}]", server.getHost(), proxyData); HttpHost proxy = new HttpHost(proxyData.getHost(), proxyData.getPort()); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (proxyData.isRequiresAuthentication()) { httpClient.getCredentialsProvider().setCredentials( new AuthScope(proxyData.getHost(), proxyData.getPort()), new UsernamePasswordCredentials(proxyData.getUserId(), proxyData.getPassword())); } } else { LOG.debug("No proxy for [{}]", server.getHost()); } } catch (Exception e) { LOG.error("Unable to configure proxy for sonar-ws-client", e); } }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.cda.HttpQueryBackend.java
public static Credentials getCredentials(final String user, final String password) { if (StringUtils.isEmpty(user)) { return null; }/*from ww w. j a v a 2s . co m*/ final int domainIdx = user.indexOf(DOMAIN_SEPARATOR); if (domainIdx == -1) { return new UsernamePasswordCredentials(user, password); } try { final String domain = user.substring(0, domainIdx); final String username = user.substring(domainIdx + 1); final String host = InetAddress.getLocalHost().getHostName(); return new NTCredentials(username, password, host, domain); } catch (UnknownHostException uhe) { return new UsernamePasswordCredentials(user, password); } }
From source file:com.ibm.watson.apis.conversation_enhanced.utils.HttpSolrClientUtils.java
/** * Creates the {@link HttpClient} to use with the Solrj * * @param url the Solr server url/*from ww w. j a v a2 s .co m*/ * @param username the {@link RetrieveAndRank} service username * @param password the {@link RetrieveAndRank} service password * @return the {@link HttpClient} */ private static HttpClient createHttpClient(String url, String username, String password) { final URI scopeUri = URI.create(url); logger.info(Messages.getString("HttpSolrClientUtils.CREATING_HTTP_CLIENT")); //$NON-NLS-1$ final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(scopeUri.getHost(), scopeUri.getPort()), new UsernamePasswordCredentials(username, password)); final HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnTotal(128).setMaxConnPerRoute(32) .setDefaultRequestConfig( RequestConfig.copy(RequestConfig.DEFAULT).setRedirectsEnabled(true).build()) .setDefaultCredentialsProvider(credentialsProvider) .addInterceptorFirst(new PreemptiveAuthInterceptor()); return builder.build(); }
From source file:com.seleniumtests.browserfactory.SauceLabsDriverFactory.java
/** * Upload application to saucelabs server * @param targetAppPath//from w w w . j av a2s . com * @param serverURL * @return * @throws IOException * @throws AuthenticationException */ protected static boolean uploadFile(String targetAppPath) throws IOException, AuthenticationException { // extract user name and password from getWebDriverGrid Matcher matcher = REG_USER_PASSWORD .matcher(SeleniumTestsContextManager.getThreadContext().getWebDriverGrid().get(0)); String user; String password; if (matcher.matches()) { user = matcher.group(1); password = matcher.group(2); } else { throw new ConfigurationException( "getWebDriverGrid variable does not have the right format for connecting to sauceLabs"); } FileEntity entity = new FileEntity(new File(targetAppPath)); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, password); HttpPost request = new HttpPost(String.format(SAUCE_UPLOAD_URL, user, new File(targetAppPath).getName())); request.setEntity(entity); request.addHeader(new BasicScheme().authenticate(creds, request, null)); request.addHeader("Content-Type", "application/octet-stream"); try (CloseableHttpClient client = HttpClients.createDefault();) { CloseableHttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() != 200) { client.close(); throw new ConfigurationException( "Application file upload failed: " + response.getStatusLine().getReasonPhrase()); } } return true; }
From source file:org.overlord.security.eval.webapp4.services.JaxrsService.java
/** * @return/*w w w.ja va2s. co m*/ */ private ClientExecutor getSamlAssertionExecutor() { try { String username = "SAML-BEARER-TOKEN"; String password = createSAMLAssertion(); Credentials credentials = new UsernamePasswordCredentials(username, password); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient); return clientExecutor; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceDescriptionTests.java
@Before public void setup() throws IOException, ParserConfigurationException, SAXException, XPathException { Properties setupProps = SetupProperties.setup(null); if (setupProps.getProperty("testBackwardsCompatability") != null && Boolean.parseBoolean(setupProps.getProperty("testBackwardsCompatability"))) { setupProps = SetupProperties.setup(setupProps.getProperty("version1Properties")); }/*from www . ja v a 2 s .c om*/ baseUrl = setupProps.getProperty("baseUri"); String userId = setupProps.getProperty("userId"); String pw = setupProps.getProperty("pw"); basicCreds = new UsernamePasswordCredentials(userId, pw); response = OSLCUtils.getResponseFromUrl(baseUrl, currentUrl, basicCreds, OSLCConstants.CT_DISC_DESC_XML); responseBody = EntityUtils.toString(response.getEntity()); //Get XML Doc from response doc = OSLCUtils.createXMLDocFromResponseBody(responseBody); }
From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItem.java
/** * @param config Http client configuration *///from w w w . j a va2 s.c om HttpClientItem(HttpClientConfig config) { this.config = config; // optional SSL client certificate support SSLContext sslContext; if (CertificateLoader.isSslKeyManagerEnabled(config) || CertificateLoader.isSslTrustStoreEnbaled(config)) { try { sslContext = CertificateLoader.buildSSLContext(config); } catch (IOException | GeneralSecurityException ex) { throw new IllegalArgumentException("Invalid SSL client certificate configuration.", ex); } } else { sslContext = CertificateLoader.createDefaultSSlContext(); } CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); // optional proxy authentication if (StringUtils.isNotEmpty(config.getProxyUser())) { credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUser(), config.getProxyPassword())); } // optional http basic authentication support if (StringUtils.isNotEmpty(config.getHttpUser())) { credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(config.getHttpUser(), config.getHttpPassword())); } // build http clients connectionManager = buildConnectionManager(config, sslContext); httpClient = buildHttpClient(config, connectionManager, credentialsProvider); }
From source file:it.larusba.neo4j.jdbc.http.driver.CypherExecutor.java
/** * Default constructor.// w ww . ja v a 2 s . co m * * @param host Hostname of the Neo4j instance. * @param port HTTP port of the Neo4j instance. * @param properties Properties of the url connection. * @throws SQLException */ public CypherExecutor(String host, Integer port, Properties properties) throws SQLException { // Create the http client builder HttpClientBuilder builder = HttpClients.custom(); // Adding authentication to the http client if needed if (properties.containsKey("user") && properties.containsKey("password")) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(host, port), new UsernamePasswordCredentials( properties.get("user").toString(), properties.get("password").toString())); builder.setDefaultCredentialsProvider(credsProvider); } // Setting user-agent StringBuilder sb = new StringBuilder(); sb.append("Neo4j JDBC Driver"); if (properties.containsKey("userAgent")) { sb.append(" via "); sb.append(properties.getProperty("userAgent")); } builder.setUserAgent(sb.toString()); // Create the http client this.http = builder.build(); // Create the url endpoint StringBuffer sbEndpoint = new StringBuffer(); sbEndpoint.append("http://").append(host).append(":").append(port).append("/db/data/transaction"); this.transactionUrl = sbEndpoint.toString(); // Setting autocommit this.setAutoCommit(Boolean.valueOf(properties.getProperty("autoCommit", "true"))); }