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:io.cloudslang.content.httpclient.build.auth.CredentialsProviderBuilder.java
public CredentialsProvider buildCredentialsProvider() { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); if (!StringUtils.isEmpty(username)) { Credentials credentials;/*from www. j a v a 2 s .c o m*/ if (authTypes.contains(AuthTypes.NTLM)) { String[] domainAndUsername = getDomainUsername(username); credentials = new NTCredentials(domainAndUsername[1], password, host, domainAndUsername[0]); } else { credentials = new UsernamePasswordCredentials(username, password); } credentialsProvider.setCredentials(new AuthScope(host, Integer.parseInt(port)), credentials); } else if (authTypes.contains(AuthTypes.KERBEROS)) { credentialsProvider.setCredentials(new AuthScope(host, Integer.parseInt(port)), new Credentials() { @Override public Principal getUserPrincipal() { return null; } @Override public String getPassword() { return null; } }); } if (!StringUtils.isEmpty(proxyUsername)) { int intProxyPort = 8080; if (!StringUtils.isEmpty(proxyPort)) { intProxyPort = Utils.validatePortNumber(proxyPort); } credentialsProvider.setCredentials(new AuthScope(proxyHost, intProxyPort), new UsernamePasswordCredentials(proxyUsername, proxyPassword)); } return credentialsProvider; }
From source file:com.ksc.http.apache.utils.ApacheUtils.java
/** * Returns a new instance of NTCredentials used for proxy authentication. *//*from w w w. j a va2 s.c o m*/ private static Credentials newNTCredentials(HttpClientSettings settings) { return new NTCredentials(settings.getProxyUsername(), settings.getProxyPassword(), settings.getProxyWorkstation(), settings.getProxyDomain()); }
From source file:com.microsoft.exchange.ExchangeWebService.java
public ExchangeServicePortType getNtlmServicePort(String endpointUrl, String userName, String password, String domain) {//from www . j a va 2 s.co m ExchangeServicePortType port = getServicePort(); Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl); // setup NTLM authentication requestContext.put(Credentials.class.getName(), new NTCredentials(userName, password, "", domain)); // force async conduit requestContext.put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE); // turn off chunking Client client = ClientProxy.getClient(port); initLogging(client); HTTPConduit conduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy clientPolicy = conduit.getClient(); clientPolicy.setAllowChunking(false); clientPolicy.setAutoRedirect(true); clientPolicy.setConnectionTimeout(DEFAULT_TIMEOUT); clientPolicy.setReceiveTimeout(DEFAULT_TIMEOUT); clientPolicy.setAsyncExecuteTimeout(DEFAULT_TIMEOUT); return port; }
From source file:org.cleverbus.core.common.ws.transport.http.ntlm.NtlmCloseableHttpComponentsMessageSender.java
/** * Create a new instance of the {@code HttpClientMessageSender} with a default {@link HttpClient} * with added support for NTLM.//www.j a v a2 s . c o m * * @param ntlmUsername the NTLM username (without domain name) * @param ntlmPassword the NTLM password * @param ntlmDomain the NTLM domain */ public NtlmCloseableHttpComponentsMessageSender(String ntlmUsername, String ntlmPassword, String ntlmDomain) { super(); Assert.hasText(ntlmUsername, "the ntlmUsername must not be empty"); Assert.hasText(ntlmPassword, "the ntlmPassword must not be empty"); Assert.hasText(ntlmDomain, "the ntlmDomain must not be empty"); this.ntlmUsername = ntlmUsername; this.ntlmPassword = ntlmPassword; this.ntlmDomain = ntlmDomain; // Register NTLMSchemeFactory with the HttpClient instance you want to NTLM enable. Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.NTLM, new NTLMSchemeFactory()).build(); getClientBuilder().setDefaultAuthSchemeRegistry(authSchemeRegistry); NTCredentials credentials = new NTCredentials(ntlmUsername, ntlmPassword, MACHINE_NAME, ntlmDomain); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); setCredentials(credentials); credentialsProvider.setCredentials(AuthScope.ANY, credentials); // register NTLM to HttpClient setCredentialsProvider(credentialsProvider); }
From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.Proxies.java
public static Executor proxyAuthentication(Executor executor, URI target) throws IOException { IProxyData proxy = getProxyData(target).orNull(); if (proxy != null) { HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); if (proxy.getUserId() != null) { String userId = getUserName(proxy.getUserId()).orNull(); String pass = proxy.getPassword(); String workstation = getWorkstation().orNull(); String domain = getUserDomain(proxy.getUserId()).orNull(); return executor .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, "ntlm"), new NTCredentials(userId, pass, workstation, domain)) .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(userId, pass)); } else {/* w w w.j a v a 2 s . co m*/ return executor; } } return executor; }
From source file:org.opensextant.xtext.collectors.sharepoint.SharepointClient.java
/** * Sharepoint requires NTLM. This client requires a non-null user/passwd/domain. * //from ww w . j a va2 s . c o m */ @Override public HttpClient getClient() { if (currentConn != null) { return currentConn; } HttpClientBuilder clientHelper = HttpClientBuilder.create(); if (proxyHost != null) { clientHelper.setProxy(proxyHost); } RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY) .build(); CredentialsProvider creds = new BasicCredentialsProvider(); creds.setCredentials(AuthScope.ANY, new NTCredentials(user, passwd, server, domain)); clientHelper.setDefaultCredentialsProvider(creds); HttpClient httpClient = clientHelper.setDefaultRequestConfig(globalConfig).build(); return httpClient; }
From source file:com.aliyun.oss.common.comm.HttpClientFactory.java
public HttpClient createHttpClient(ClientConfiguration config) { HttpParams httpClientParams = new BasicHttpParams(); HttpProtocolParams.setUserAgent(httpClientParams, config.getUserAgent()); HttpConnectionParams.setConnectionTimeout(httpClientParams, config.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(httpClientParams, config.getSocketTimeout()); HttpConnectionParams.setStaleCheckingEnabled(httpClientParams, true); HttpConnectionParams.setTcpNoDelay(httpClientParams, true); PoolingClientConnectionManager connManager = createConnectionManager(config, httpClientParams); DefaultHttpClient httpClient = new DefaultHttpClient(connManager, httpClientParams); if (System.getProperty("com.aliyun.oss.disableCertChecking") != null) { Scheme sch = new Scheme("https", 443, getSSLSocketFactory()); httpClient.getConnectionManager().getSchemeRegistry().register(sch); }/*from w ww . j a v a2s . c o m*/ String proxyHost = config.getProxyHost(); int proxyPort = config.getProxyPort(); if (proxyHost != null && proxyPort > 0) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); String proxyUsername = config.getProxyUsername(); String proxyPassword = config.getProxyPassword(); if (proxyUsername != null && proxyPassword != null) { String proxyDomain = config.getProxyDomain(); String proxyWorkstation = config.getProxyWorkstation(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUsername, proxyPassword, proxyWorkstation, proxyDomain)); } } return httpClient; }
From source file:org.eclipse.oomph.setup.internal.sync.SyncUtil.java
public static Executor proxyAuthentication(Executor executor, URI uri) throws IOException { IProxyData proxy = getProxyData(uri); if (proxy != null) { HttpHost proxyHost = new HttpHost(proxy.getHost(), proxy.getPort()); String proxyUserID = proxy.getUserId(); if (proxyUserID != null) { String userID = getUserName(proxyUserID); String password = proxy.getPassword(); String workstation = getWorkstation(); String domain = getUserDomain(proxyUserID); return executor .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, "ntlm"), new NTCredentials(userID, password, workstation, domain)) .auth(new AuthScope(proxyHost, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(userID, password)); }/* w w w . ja va2s.c o m*/ } return executor; }
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; }//w ww .j a v a 2 s . c om 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); } }