public static void main(String... args) throws IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.NTLM); httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); NTCredentials creds = new NTCredentials("abhisheks", "abhiProJul17", "", ""); httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpHost target = new HttpHost("apps.prorigo.com", 80, "http"); // Make sure the same context is used to execute logically related requests HttpContext localContext = new BasicHttpContext(); // Execute a cheap method first. This will trigger NTLM authentication HttpGet httpget = new HttpGet("/conference/Booking"); HttpResponse response = httpclient.execute(target, httpget, localContext); HttpEntity entity = response.getEntity(); System.out.println(EntityUtils.toString(entity)); }
@SuppressWarnings({ "resource"}) private TwilioRestClient _createTwilioRESTClient() { TwilioRestClient outClient = new TwilioRestClient(_apiData.getAccountSID().asString(), _apiData.getAccountToken().asString()); if (_proxySettings != null && _proxySettings.isEnabled()) { UrlComponents proxyUrlComps = _proxySettings.getProxyUrl().getComponents(); log.info("Connecting to twilio through {}:{}",proxyUrlComps.getHost(), proxyUrlComps.getPort()); // Get the twilio api underlying http client DefaultHttpClient httpClient = (DefaultHttpClient)outClient.getHttpClient(); // Set proxy details HttpHost proxy = new HttpHost(proxyUrlComps.getHost().asString(),proxyUrlComps.getPort(), "http"); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyUrlComps.getHost().asString(), proxyUrlComps.getPort()), new UsernamePasswordCredentials(_proxySettings.getUserCode().asString(), _proxySettings.getPassword().asString())); httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, Lists.newArrayList(AuthPolicy.BASIC)); } return outClient; }
public static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId) { if (client == null) { throw new NullPointerException("client"); } 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); }
@Override protected List<String> getAuthPreferences( final HttpResponse response, final HttpContext context) { @SuppressWarnings("unchecked") List<String> authpref = (List<String>) response.getParams().getParameter( AuthPNames.TARGET_AUTH_PREF); if (authpref != null) { return authpref; } else { return super.getAuthPreferences(response, context); } }
@Override protected List<String> getAuthPreferences( final HttpResponse response, final HttpContext context) { @SuppressWarnings("unchecked") List<String> authpref = (List<String>) response.getParams().getParameter( AuthPNames.PROXY_AUTH_PREF); if (authpref != null) { return authpref; } else { return super.getAuthPreferences(response, context); } }
String getCredentialsCharset(final HttpRequest request) { String charset = (String) request.getParams().getParameter(AuthPNames.CREDENTIAL_CHARSET); if (charset == null) { charset = getCredentialsCharset().name(); } return charset; }
@Override protected List<String> getAuthPreferences( final HttpResponse response, final HttpContext context) { @SuppressWarnings("unchecked") final List<String> authpref = (List<String>) response.getParams().getParameter( AuthPNames.TARGET_AUTH_PREF); if (authpref != null) { return authpref; } else { return super.getAuthPreferences(response, context); } }
@Override protected List<String> getAuthPreferences( final HttpResponse response, final HttpContext context) { @SuppressWarnings("unchecked") final List<String> authpref = (List<String>) response.getParams().getParameter( AuthPNames.PROXY_AUTH_PREF); if (authpref != null) { return authpref; } else { return super.getAuthPreferences(response, context); } }
@SuppressWarnings("unchecked") public static RequestConfig getRequestConfig(final HttpParams params) { return RequestConfig.custom() .setSocketTimeout(params.getIntParameter( CoreConnectionPNames.SO_TIMEOUT, 0)) .setStaleConnectionCheckEnabled(params.getBooleanParameter( CoreConnectionPNames.STALE_CONNECTION_CHECK, true)) .setConnectTimeout(params.getIntParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, 0)) .setExpectContinueEnabled(params.getBooleanParameter( CoreProtocolPNames.USE_EXPECT_CONTINUE, false)) .setProxy((HttpHost) params.getParameter( ConnRoutePNames.DEFAULT_PROXY)) .setLocalAddress((InetAddress) params.getParameter( ConnRoutePNames.LOCAL_ADDRESS)) .setProxyPreferredAuthSchemes((Collection<String>) params.getParameter( AuthPNames.PROXY_AUTH_PREF)) .setTargetPreferredAuthSchemes((Collection<String>) params.getParameter( AuthPNames.TARGET_AUTH_PREF)) .setAuthenticationEnabled(params.getBooleanParameter( ClientPNames.HANDLE_AUTHENTICATION, true)) .setCircularRedirectsAllowed(params.getBooleanParameter( ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false)) .setConnectionRequestTimeout((int) params.getLongParameter( ClientPNames.CONN_MANAGER_TIMEOUT, 0)) .setCookieSpec((String) params.getParameter( ClientPNames.COOKIE_POLICY)) .setMaxRedirects(params.getIntParameter( ClientPNames.MAX_REDIRECTS, 50)) .setRedirectsEnabled(params.getBooleanParameter( ClientPNames.HANDLE_REDIRECTS, true)) .setRelativeRedirectsAllowed(!params.getBooleanParameter( ClientPNames.REJECT_RELATIVE_REDIRECT, false)) .build(); }
/** * 認証プロキシを通過するためのHttpClient。 */ public HttpClientForProxy() { super(); String proxyUser = System.getProperty("http.proxyUser"); if (proxyUser != null) { String proxyHost = System.getProperty("http.proxyHost"); String proxyPortStr = System.getProperty("http.proxyPort"); int proxyPort = 0; if (proxyPortStr != null) { proxyPort = Integer.parseInt(proxyPortStr); } String proxyPassword = System.getProperty("http.proxyPassword"); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.BASIC); this.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); CredentialsProvider credsProvider = this.getCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials( proxyUser, proxyPassword)); this.setCredentialsProvider(credsProvider); String protocol = ""; if (proxyHost.indexOf("https") != 0) { protocol = "http"; } else { protocol = "https"; } HttpHost proxy = new HttpHost(proxyHost, proxyPort, protocol); this.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } }
private void appendAuthentication(Credentials credentials, String authPolicy, SolrClient solrClient) { if (isHttpSolrClient(solrClient)) { HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient; if (credentials != null && StringUtils.isNotBlank(authPolicy) && assertHttpClientInstance(httpSolrClient.getHttpClient())) { AbstractHttpClient httpClient = (AbstractHttpClient) httpSolrClient.getHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), credentials); httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(authPolicy)); } } }
/** * 認証プロキシを通過するためのHttpClient。 */ public HttpClientForProxy() { super(); String proxyHost = System.getProperty("http.proxyHost"); if (proxyHost != null) { String proxyPortStr = System.getProperty("http.proxyPort"); int proxyPort = 0; if (proxyPortStr != null) { proxyPort = Integer.parseInt(proxyPortStr); } String proxyUser = System.getProperty("http.proxyUser"); if (proxyUser != null) { String proxyPassword = System.getProperty("http.proxyPassword"); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.BASIC); this.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); CredentialsProvider credsProvider = this.getCredentialsProvider(); credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials( proxyUser, proxyPassword)); this.setCredentialsProvider(credsProvider); } String protocol = ""; if (proxyHost.indexOf("https") != 0) { protocol = "http"; } else { protocol = "https"; } HttpHost proxy = new HttpHost(proxyHost, proxyPort, protocol); this.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } }
private void appendAuthentication(Credentials credentials, String authPolicy, SolrServer solrServer) { if (isHttpSolrServer(solrServer)) { HttpSolrServer httpSolrServer = (HttpSolrServer) solrServer; if (credentials != null && StringUtils.isNotBlank(authPolicy) && assertHttpClientInstance(httpSolrServer.getHttpClient())) { AbstractHttpClient httpClient = (AbstractHttpClient) httpSolrServer.getHttpClient(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), credentials); httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(authPolicy)); } } }
@Test public void testInitFactoryWithAuthentication() { HttpSolrServerFactory factory = new HttpSolrServerFactory(solrServer, "core", new UsernamePasswordCredentials( "username", "password"), "BASIC"); AbstractHttpClient solrHttpClient = (AbstractHttpClient) ((HttpSolrServer) factory.getSolrServer()).getHttpClient(); Assert.assertNotNull(solrHttpClient.getCredentialsProvider().getCredentials(AuthScope.ANY)); Assert.assertNotNull(solrHttpClient.getParams().getParameter(AuthPNames.TARGET_AUTH_PREF)); Assert.assertEquals("username", ((UsernamePasswordCredentials) solrHttpClient.getCredentialsProvider() .getCredentials(AuthScope.ANY)).getUserName()); Assert.assertEquals("password", ((UsernamePasswordCredentials) solrHttpClient.getCredentialsProvider() .getCredentials(AuthScope.ANY)).getPassword()); }
public ProxyAuthenticationStrategy() { super(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, AUTH.PROXY_AUTH, AuthPNames.PROXY_AUTH_PREF); }
public TargetAuthenticationStrategy() { super(HttpStatus.SC_UNAUTHORIZED, AUTH.WWW_AUTH, AuthPNames.TARGET_AUTH_PREF); }
public String getServerTime() { String soapAction = "http://tempuri.org/SoapService/GetServerTime"; String soapEnv = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"> <soapenv:Header/> <soapenv:Body> <tem:GetServerTime/> </soapenv:Body></soapenv:Envelope>"; log.info(String.format("sendSoap - action %s [%s]", soapAction, soapEnv)); String mesEndpoint = properties.getProperty("mes.endpoint"); String mesUser = properties.getProperty("mes.user"); String mesDomain = properties.getProperty("mes.domain"); String mesPassword = properties.getProperty("mes.password"); log.info(String.format("mesEndpoint %s", mesEndpoint)); log.info(String.format("mesUser %s", mesUser)); log.info(String.format("mesDomain %s", mesDomain)); log.info(String.format("mesPassword %s", mesPassword)); String ret = ""; try { DefaultHttpClient httpclient = new DefaultHttpClient(); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.NTLM); httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); NTCredentials creds = new NTCredentials(mesUser, mesPassword, "", mesDomain); httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpContext localContext = new BasicHttpContext(); HttpPost post = new HttpPost(mesEndpoint); // ,"utf-8" StringEntity stringentity = new StringEntity(soapEnv); stringentity.setChunked(true); post.setEntity(stringentity); post.addHeader("Accept", "text/xml"); post.addHeader("SOAPAction", soapAction); post.addHeader("Content-Type", "text/xml; charset=utf-8"); HttpResponse response = httpclient.execute(post, localContext); HttpEntity entity = response.getEntity(); ret = EntityUtils.toString(entity); // parse the response - check } catch (Exception e) { error("endpoint %s user %s domain %s password %s", mesEndpoint, mesUser, mesDomain, mesPassword); Logging.logError(e); ret = e.getMessage(); } log.info(String.format("soap response [%s]", ret)); return ret; }
public String sendSoap(String soapAction, String soapEnv) { log.info(String.format("sendSoap - action %s [%s]", soapAction, soapEnv)); String mesEndpoint = properties.getProperty("mes.endpoint"); String mesUser = properties.getProperty("mes.user"); String mesDomain = properties.getProperty("mes.domain"); String mesPassword = properties.getProperty("mes.password"); log.info(String.format("mesEndpoint %s", mesEndpoint)); log.info(String.format("mesUser %s", mesUser)); log.info(String.format("mesDomain %s", mesDomain)); log.info(String.format("mesPassword %s", mesPassword)); String ret = ""; try { DefaultHttpClient httpclient = new DefaultHttpClient(); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.NTLM); httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); NTCredentials creds = new NTCredentials(mesUser, mesPassword, "", mesDomain); httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpContext localContext = new BasicHttpContext(); HttpPost post = new HttpPost(mesEndpoint); // ,"utf-8" StringEntity stringentity = new StringEntity(soapEnv); stringentity.setChunked(true); post.setEntity(stringentity); post.addHeader("Accept", "text/xml"); post.addHeader("SOAPAction", soapAction); post.addHeader("Content-Type", "text/xml; charset=utf-8"); HttpResponse response = httpclient.execute(post, localContext); HttpEntity entity = response.getEntity(); ret = EntityUtils.toString(entity); // parse the response - check } catch (Exception e) { error("endpoint %s user %s domain %s password %s", mesEndpoint, mesUser, mesDomain, mesPassword); Logging.logError(e); ret = e.getMessage(); } log.info(String.format("soap response [%s]", ret)); return ret; }
public String sendSoap(String soapAction, String soapEnv) { log.info(String.format("sendSoap - action %s [%s]", soapAction, soapEnv)); String mesEndpoint = properties.getProperty("mes.endpoint"); String mesUser = properties.getProperty("mes.user"); String mesDomain = properties.getProperty("mes.domain"); String mesPassword = properties.getProperty("mes.password"); log.info(String.format("mesEndpoint %s", mesEndpoint)); log.info(String.format("mesUser %s", mesUser)); log.info(String.format("mesDomain %s", mesDomain)); log.info(String.format("mesPassword %s", mesPassword)); String ret = ""; try { DefaultHttpClient client = new DefaultHttpClient(); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.NTLM); client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); NTCredentials creds = new NTCredentials(mesUser, mesPassword, "", mesDomain); client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpContext localContext = new BasicHttpContext(); HttpPost post = new HttpPost(mesEndpoint); // ,"utf-8" StringEntity stringentity = new StringEntity(soapEnv); stringentity.setChunked(true); post.setEntity(stringentity); post.addHeader("Accept", "text/xml"); post.addHeader("SOAPAction", soapAction); post.addHeader("Content-Type", "text/xml; charset=utf-8"); HttpResponse response = client.execute(post, localContext); HttpEntity entity = response.getEntity(); ret = EntityUtils.toString(entity); // parse the response - check } catch (Exception e) { error("endpoint %s user %s domain %s password %s", mesEndpoint, mesUser, mesDomain, mesPassword); Logging.logError(e); ret = e.getMessage(); } log.info(String.format("soap response [%s]", ret)); return ret; }
public static void main(String[] args) throws Throwable { // create a HTTP BASIC enabled HTTP client final DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager()); final CredentialsProvider credentialsProvider = httpClient.getCredentialsProvider(); final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin"); final List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.BASIC); authpref.add(AuthPolicy.DIGEST); httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); credentialsProvider.setCredentials(new AuthScope("localhost", 8080), credentials); credentialsProvider.setCredentials(new AuthScope("localhost", 9090), credentials); // register endpoints final List<String> slaveEndpoints = new ArrayList<String>(); slaveEndpoints.add("http://localhost:8080/DataCleaner-monitor/repository/DC/cluster_slave_endpoint"); slaveEndpoints.add("http://localhost:9090/DataCleaner-monitor/repository/DC/cluster_slave_endpoint"); final HttpClusterManager clusterManager = new HttpClusterManager(httpClient, slaveEndpoints); final AnalyzerBeansConfiguration configuration = ClusterTestHelper.createConfiguration("manual_test", false); // build a job that concats names and inserts the concatenated names // into a file final AnalysisJobBuilder jobBuilder = new AnalysisJobBuilder(configuration); jobBuilder.setDatastore("orderdb"); jobBuilder.addSourceColumns("CUSTOMERS.CUSTOMERNUMBER", "CUSTOMERS.CUSTOMERNAME", "CUSTOMERS.CONTACTFIRSTNAME", "CUSTOMERS.CONTACTLASTNAME"); AnalyzerJobBuilder<CompletenessAnalyzer> completeness = jobBuilder.addAnalyzer(CompletenessAnalyzer.class); completeness.addInputColumns(jobBuilder.getSourceColumns()); completeness.setConfiguredProperty("Conditions", new CompletenessAnalyzer.Condition[] { CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL, CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL, CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL, CompletenessAnalyzer.Condition.NOT_BLANK_OR_NULL }); AnalysisJob job = jobBuilder.toAnalysisJob(); jobBuilder.close(); AnalysisResultFuture result = new DistributedAnalysisRunner(configuration, clusterManager).run(job); if (result.isErrornous()) { throw result.getErrors().get(0); } final List<AnalyzerResult> results = result.getResults(); for (AnalyzerResult analyzerResult : results) { System.out.println("result:" + analyzerResult); if (analyzerResult instanceof CompletenessAnalyzerResult) { int invalidRowCount = ((CompletenessAnalyzerResult) analyzerResult).getInvalidRowCount(); System.out.println("invalid records found: " + invalidRowCount); } else { System.out.println("class: " + analyzerResult.getClass().getName()); } } }