List of usage examples for org.apache.http.auth NTCredentials NTCredentials
public NTCredentials(final String userName, final String password, final String workstation, final String domain)
From source file:forcalibre.ClientProxyAuthentication.java
public static void main(String[] args) throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(PROXY_HOST, PROXY_PORT), ///new UsernamePasswordCredentials("vimpelcom_main\\vyualeksandrov", "s1teRlin9g19") new NTCredentials("vyualeksandrov", "s1teRlin9g19", PROXY_HOST, "vimpelcom_main")); Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.NTLM, new NTLMSchemeFactory()) .register(AuthSchemes.BASIC, new BasicSchemeFactory()) .register(AuthSchemes.DIGEST, new DigestSchemeFactory()) .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()) .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry) .setDefaultCredentialsProvider(credsProvider).build(); try {/* w w w. ja v a 2 s .c om*/ // HttpHost target = new HttpHost("www.verisign.com", 443, "https"); // HttpHost proxy = new HttpHost("localhost", 8080); HttpHost target = new HttpHost(TARGET_HOST, 80, "http"); HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); HttpGet httpget = new HttpGet("/"); httpget.setConfig(config); System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy); CloseableHttpResponse response = httpclient.execute(target, httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } }
From source file:simauthenticator.SimAuthenticator.java
/** * @param args the command line arguments */// w w w. j a v a 2 s . c o m public static void main(String[] args) throws Exception { cliOpts = new Options(); cliOpts.addOption("U", "url", true, "Connection URL"); cliOpts.addOption("u", "user", true, "User name"); cliOpts.addOption("p", "password", true, "User password"); cliOpts.addOption("d", "domain", true, "Domain name"); cliOpts.addOption("v", "verbose", false, "Verbose output"); cliOpts.addOption("k", "keystore", true, "KeyStore path"); cliOpts.addOption("K", "keystorepass", true, "KeyStore password"); cliOpts.addOption("h", "help", false, "Print help info"); CommandLineParser clip = new GnuParser(); cmd = clip.parse(cliOpts, args); if (cmd.hasOption("help")) { help(); return; } else { boolean valid = init(args); if (!valid) { return; } } HttpClientContext clientContext = HttpClientContext.create(); KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); char[] keystorePassword = passwk.toCharArray(); FileInputStream kfis = null; try { kfis = new FileInputStream(keyStorePath); ks.load(kfis, keystorePassword); } finally { if (kfis != null) { kfis.close(); } } SSLContext sslContext = SSLContexts.custom().useSSL().loadTrustMaterial(ks).build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setSslcontext(sslContext) .setSSLSocketFactory(sslsf).setUserAgent(userAgent); ; cookieStore = new BasicCookieStore(); /* BasicClientCookie cookie = new BasicClientCookie("SIM authenticator", "Utility for getting event details"); cookie.setVersion(0); cookie.setDomain(".astelit.ukr"); cookie.setPath("/"); cookieStore.addCookie(cookie);*/ CloseableHttpClient client = httpClientBuilder.build(); try { NTCredentials creds = new NTCredentials(usern, passwu, InetAddress.getLocalHost().getHostName(), domain); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, creds); HttpClientContext context = HttpClientContext.create(); context.setCredentialsProvider(credsProvider); context.setCookieStore(cookieStore); HttpGet httpget = new HttpGet(eventUrl); if (verbose) { System.out.println("executing request " + httpget.getRequestLine()); } HttpResponse response = client.execute(httpget, context); HttpEntity entity = response.getEntity(); HttpPost httppost = new HttpPost(eventUrl); List<Cookie> cookies = cookieStore.getCookies(); if (verbose) { System.out.println("----------------------------------------------"); System.out.println(response.getStatusLine()); System.out.print("Initial set of cookies: "); if (cookies.isEmpty()) { System.out.println("none"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("usernameInput", usern)); nvps.add(new BasicNameValuePair("passwordInput", passwu)); nvps.add(new BasicNameValuePair("domainInput", domain)); //nvps.add(new BasicNameValuePair("j_username", domain + "\\" + usern)); //nvps.add(new BasicNameValuePair("j_password", ipAddr + ";" + passwu)); if (entity != null && verbose) { System.out.println("Responce content length: " + entity.getContentLength()); } //System.out.println(EntityUtils.toString(entity)); httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse afterPostResponse = client.execute(httppost, context); HttpEntity afterPostEntity = afterPostResponse.getEntity(); cookies = cookieStore.getCookies(); if (entity != null && verbose) { System.out.println("----------------------------------------------"); System.out.println(afterPostResponse.getStatusLine()); System.out.println("Responce content length: " + afterPostEntity.getContentLength()); System.out.print("After POST set of cookies: "); if (cookies.isEmpty()) { System.out.println("none"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } System.out.println(EntityUtils.toString(afterPostEntity)); EntityUtils.consume(entity); EntityUtils.consume(afterPostEntity); } finally { client.getConnectionManager().shutdown(); } }
From source file:org.pentaho.reporting.designer.core.auth.AuthenticationHelper.java
public static Credentials getCredentials(final String user, final String password) { if (StringUtils.isEmpty(user)) { return null; }// w w w . j ava2 s .c om final Configuration config = ReportDesignerBoot.getInstance().getGlobalConfig(); if ("true".equals(config.getConfigProperty(NT_AUTH_CONFIGKEY, "false")) == false) { return new UsernamePasswordCredentials(user, password); } 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:org.apache.camel.component.http4.BasicAuthenticationHttpClientConfigurer.java
public void configureHttpClient(HttpClient client) { Credentials defaultcreds;/*from w w w . j a va2s . c o m*/ if (domain != null) { defaultcreds = new NTCredentials(username, password, host, domain); } else { defaultcreds = new UsernamePasswordCredentials(username, password); } ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds); }
From source file:com.microsoft.exchange.integration.NtlmCredentialsIntegrationTest.java
@Override public void initializeCredentials() { Credentials credentials = new NTCredentials(userName, password, "", domain); ThreadLocalCredentialsProviderFactory.set(credentials); }
From source file:com.eviware.soapui.support.httpclient.JCIFSTest.java
@Test public void test() throws ParseException, IOException { try {/*w w w . ja va 2 s . c o m*/ DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getAuthSchemes().register(AuthPolicy.NTLM, new NTLMSchemeFactory()); httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new NTLMSchemeFactory()); NTCredentials creds = new NTCredentials("testuser", "kebabsalladT357", "", ""); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); HttpHost target = new HttpHost("dev-appsrv01.eviware.local", 81, "http"); HttpContext localContext = new BasicHttpContext(); HttpGet httpget = new HttpGet("/"); HttpResponse response1 = httpClient.execute(target, httpget, localContext); HttpEntity entity1 = response1.getEntity(); // System.out.println( "----------------------------------------" ); //System.out.println( response1.getStatusLine() ); // System.out.println( "----------------------------------------" ); if (entity1 != null) { //System.out.println( EntityUtils.toString( entity1 ) ); } // System.out.println( "----------------------------------------" ); // This ensures the connection gets released back to the manager EntityUtils.consume(entity1); Assert.assertEquals(response1.getStatusLine().getStatusCode(), 200); } catch (UnknownHostException e) { /* ignore */ } catch (HttpHostConnectException e) { /* ignore */ } catch (SocketException e) { /* ignore */ } Assert.assertTrue(true); }
From source file:org.opentravel.schemacompiler.repository.impl.NTLMSystemCredentialsProvider.java
private NTCredentials traslateToNTLMCredentials(Credentials credentials) { String fullUserName = credentials.getUserPrincipal().getName(); String[] tokens = fullUserName.split("\\\\", 2); String userName = ""; String domain = null;//from ww w . j a va2 s. c o m if (tokens.length == 2) { if (tokens[0] != null && !tokens[0].isEmpty()) { domain = tokens[0]; } userName = tokens[1]; } else { userName = tokens[0]; } String workstation = null; // how to support workstation ??? return new NTCredentials(userName, credentials.getPassword(), workstation, domain); }
From source file:org.nuxeo.connect.connector.http.ProxyHelper.java
public static void configureProxyIfNeeded(RequestConfig.Builder requestConfigBuilder, CredentialsProvider credentialsProvider, String url) { if (ConnectUrlConfig.useProxy()) { // configure proxy host HttpHost proxyHost = null;/*w w w. j a va 2 s . co m*/ if (ConnectUrlConfig.useProxyPac()) { String[] proxy = pacResolver.findProxy(url); if (proxy != null) { proxyHost = new HttpHost(proxy[0], Integer.parseInt(proxy[1])); } } else { proxyHost = new HttpHost(ConnectUrlConfig.getProxyHost(), ConnectUrlConfig.getProxyPort()); } if (proxyHost != null) { requestConfigBuilder.setProxy(proxyHost); // configure proxy auth in BA if (ConnectUrlConfig.isProxyAuthenticated()) { AuthScope authScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort(), AuthScope.ANY_REALM); if (ConnectUrlConfig.isProxyNTLM()) { NTCredentials ntlmCredential = new NTCredentials(ConnectUrlConfig.getProxyLogin(), ConnectUrlConfig.getProxyPassword(), ConnectUrlConfig.getProxyNTLMHost(), ConnectUrlConfig.getProxyNTLMDomain()); credentialsProvider.setCredentials(authScope, ntlmCredential); } else { Credentials ba = new UsernamePasswordCredentials(ConnectUrlConfig.getProxyLogin(), ConnectUrlConfig.getProxyPassword()); credentialsProvider.setCredentials(authScope, ba); } } } } }
From source file:com.kms.core.io.HttpUtil_In.java
public static CloseableHttpClient getHttpClient(final String SoeID, final String Password, final int type) { CloseableHttpClient httpclient;/* www.jav a 2s. c om*/ // Auth Scheme final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.NTLM, new NTLMSchemeFactory()) .register(AuthSchemes.BASIC, new BasicSchemeFactory()) .register(AuthSchemes.DIGEST, new DigestSchemeFactory()) .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory()) .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory()).build(); // NTLM final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), //AuthScope("localhost", 8080), new NTCredentials(SoeID, Password, "dummy", "APAC")); //new NTCredentials( SoeID, Password,"APACKR081WV058", "APAC" )); // ------------- cookie start ------------------------ // Auction // Create a local instance of cookie store final CookieStore cookieStore = new BasicCookieStore(); // Cookie . final BasicClientCookie cookie = new BasicClientCookie("songdal_view", "YES"); cookie.setVersion(0); cookie.setDomain(".scourt.go.kr"); cookie.setPath("/"); cookieStore.addCookie(cookie); // ------------- cookie end ------------------------ if (type == 0) // TYPE.AuctionInput { // HTTP Client httpclient = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry) .setDefaultCredentialsProvider(credsProvider).build(); } else // SagunInput { // HTTP Client httpclient = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry) .setDefaultCredentialsProvider(credsProvider).setDefaultCookieStore(cookieStore).build(); } return httpclient; }
From source file:com.msopentech.odatajclient.engine.client.http.AbstractNTLMAuthHttpClientFactory.java
@Override public HttpClient createHttpClient(final HttpMethod method, final URI uri) { final DefaultHttpClient httpclient = (DefaultHttpClient) super.createHttpClient(method, uri); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(getUsername(), getPassword(), getWorkstation(), getDomain())); httpclient.setCredentialsProvider(credsProvider); return httpclient; }