List of usage examples for org.apache.http.client.config AuthSchemes NTLM
String NTLM
To view the source code for org.apache.http.client.config AuthSchemes NTLM.
Click Source Link
From source file:org.opentravel.schemacompiler.repository.impl.NTLMSystemCredentialsProviderTest.java
@Test public void getCredentialsWithoutDomainShouldReturnNull() { String domain = ""; String username = "userName"; testAuthenticator.userName = domain + "\\" + username; NTCredentials credentials = (NTCredentials) ntlmCredentialsProvider .getCredentials(createAuthScope(AuthSchemes.NTLM)); assertEquals(null, credentials.getDomain()); assertEquals(username, credentials.getUserName()); }
From source file:org.openscore.content.httpclient.build.auth.AuthSchemeProviderLookupBuilder.java
public Lookup<AuthSchemeProvider> buildAuthSchemeProviderLookup() { RegistryBuilder<AuthSchemeProvider> registryBuilder = RegistryBuilder.create(); for (String type : authTypes) { switch (type.trim()) { case "NTLM": registryBuilder.register(AuthSchemes.NTLM, new AuthSchemeProvider() { @Override/*from ww w . j a v a 2 s . co m*/ public AuthScheme create(HttpContext httpContext) { return new NTLMScheme(new JCIFSEngine()); } }); break; case "BASIC": registryBuilder.register(AuthSchemes.BASIC, new BasicSchemeFactory(Charset.forName("UTF-8"))); String value = username + ":" + password; byte[] encodedValue = Base64.encodeBase64(value.getBytes(StandardCharsets.UTF_8)); headers.add(new BasicHeader("Authorization", "Basic " + new String(encodedValue))); break; case "DIGEST": registryBuilder.register(AuthSchemes.DIGEST, new DigestSchemeFactory()); break; case "KERBEROS": if (getSettingsKey().equals(System.getProperty("oohttpclient.krb.last.settings"))) { break; } if (kerberosConfigFile != null) { System.setProperty("java.security.krb5.conf", kerberosConfigFile); } else { File krb5Config; String domain = host.replaceAll(".*\\.(?=.*\\.)", ""); try { krb5Config = createKrb5Configuration(domain); } catch (IOException e) { throw new RuntimeException("could not create the krb5 config file" + e.getMessage(), e); } System.setProperty("java.security.krb5.conf", krb5Config.toURI().toString()); } if (kerberosLoginConfigFile != null) { System.setProperty("java.security.auth.login.config", kerberosLoginConfigFile); } else { File loginConfig; try { loginConfig = createLoginConfig(); } catch (IOException e) { throw new RuntimeException( "could not create the kerberos login config file" + e.getMessage(), e); } System.setProperty("java.security.auth.login.config", loginConfig.toURI().toString()); } //todo fix security issue if (password != null) { System.setProperty(KrbHttpLoginModule.PAS, password); } if (username != null) { System.setProperty(KrbHttpLoginModule.USR, username); } System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); boolean skipPort = Boolean.parseBoolean(skipPortAtKerberosDatabaseLookup); registryBuilder.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(skipPort)); registryBuilder.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(skipPort)); System.setProperty("oohttpclient.krb.last.settings", getSettingsKey()); break; default: throw new IllegalStateException( "Unsupported '" + HttpClientInputs.AUTH_TYPE + "'authentication scheme: " + type); } } return registryBuilder.build(); }
From source file:io.cloudslang.content.httpclient.build.auth.AuthSchemeProviderLookupBuilder.java
public Lookup<AuthSchemeProvider> buildAuthSchemeProviderLookup() { RegistryBuilder<AuthSchemeProvider> registryBuilder = RegistryBuilder.create(); for (String type : authTypes) { switch (type.trim()) { case "NTLM": registryBuilder.register(AuthSchemes.NTLM, new AuthSchemeProvider() { @Override/*from ww w . j a v a 2 s . c om*/ public AuthScheme create(HttpContext httpContext) { return new NTLMScheme(new JCIFSEngine()); } }); break; case "BASIC": registryBuilder.register(AuthSchemes.BASIC, new BasicSchemeFactory(Charset.forName(Utils.DEFAULT_CHARACTER_SET))); String value = username + ":" + password; byte[] encodedValue = Base64.encodeBase64(value.getBytes(StandardCharsets.UTF_8)); headers.add(new BasicHeader("Authorization", "Basic " + new String(encodedValue))); break; case "DIGEST": registryBuilder.register(AuthSchemes.DIGEST, new DigestSchemeFactory()); break; case "KERBEROS": if (kerberosConfigFile != null) { System.setProperty("java.security.krb5.conf", kerberosConfigFile); } else { File krb5Config; String domain = host.replaceAll(".*\\.(?=.*\\.)", ""); try { krb5Config = createKrb5Configuration(domain); } catch (IOException e) { throw new RuntimeException("could not create the krb5 config file" + e.getMessage(), e); } System.setProperty("java.security.krb5.conf", krb5Config.toURI().toString()); } if (kerberosLoginConfigFile != null) { System.setProperty("java.security.auth.login.config", kerberosLoginConfigFile); } else { File loginConfig; try { loginConfig = createLoginConfig(); } catch (IOException e) { throw new RuntimeException( "could not create the kerberos login config file" + e.getMessage(), e); } System.setProperty("java.security.auth.login.config", loginConfig.toURI().toString()); } if (password != null) { System.setProperty(KrbHttpLoginModule.PAS, password); } if (username != null) { System.setProperty(KrbHttpLoginModule.USR, username); } System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); boolean skipPort = Boolean.parseBoolean(skipPortAtKerberosDatabaseLookup); registryBuilder.register(AuthSchemes.KERBEROS, new KerberosSchemeFactory(skipPort)); registryBuilder.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(skipPort)); break; case AuthTypes.ANONYMOUS: break; default: throw new IllegalStateException( "Unsupported '" + HttpClientInputs.AUTH_TYPE + "'authentication scheme: " + type); } } return registryBuilder.build(); }
From source file:com.microsoft.teamfoundation.plugin.impl.TfsClient.java
private Client getClient(URI uri, TfsClientFactoryImpl.ServiceProvider provider, String username, TfsSecret password) {/*from w w w .ja v a 2 s . c o m*/ ClientConfig clientConfig = new ClientConfig(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); if (TfsClientFactoryImpl.ServiceProvider.TFS == provider) { /* NTLM auth for on premise installation */ credentialsProvider.setCredentials( new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM, AuthSchemes.NTLM), new NTCredentials(username, password.getSecret(), uri.getHost(), "")); logger.info("Using NTLM authentication for on premise TeamFoundationServer"); } else if (TfsClientFactoryImpl.ServiceProvider.VSO == provider) { // Basic Auth for VSO services credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password.getSecret())); logger.info("Using user/pass authentication for Visual Studio Online services"); // Preemptive send basic auth header, or we will be redirected for oauth login clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true); } clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED); if (System.getProperty(PROXY_URL_PROPERTY) != null) { clientConfig.property(ClientProperties.PROXY_URI, System.getProperty(PROXY_URL_PROPERTY)); clientConfig.property(ApacheClientProperties.SSL_CONFIG, getSslConfigurator()); } clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider); clientConfig.connectorProvider(new ApacheConnectorProvider()); return ClientBuilder.newClient(clientConfig); }
From source file:org.opentravel.schemacompiler.repository.impl.NTLMSystemCredentialsProviderTest.java
@Test public void getCredentialsWithMultipleDelimetersShouldConsiderFirstOne() { String domain = "DOMAIN"; String username = "user\\Nam\\e"; testAuthenticator.userName = domain + "\\" + username; NTCredentials credentials = (NTCredentials) ntlmCredentialsProvider .getCredentials(createAuthScope(AuthSchemes.NTLM)); assertEquals(domain, credentials.getDomain()); assertEquals(username, credentials.getUserName()); }
From source file:com.jaeksoft.searchlib.crawler.web.spider.HttpAbstract.java
public HttpAbstract(String userAgent, boolean bFollowRedirect, ProxyHandler proxyHandler) { HttpClientBuilder builder = HttpClients.custom(); redirectStrategy = new DefaultRedirectStrategy(); if (userAgent != null) { userAgent = userAgent.trim();// w w w . jav a2s .com if (userAgent.length() > 0) builder.setUserAgent(userAgent); else userAgent = null; } if (!bFollowRedirect) builder.disableRedirectHandling(); this.proxyHandler = proxyHandler; 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(); credentialsProvider = new BasicCredentialsProvider(); builder.setDefaultCredentialsProvider(credentialsProvider); cookieStore = new BasicCookieStore(); builder.setDefaultCookieStore(cookieStore); builder.setDefaultCredentialsProvider(credentialsProvider); builder.setDefaultAuthSchemeRegistry(authSchemeRegistry); httpClient = builder.build(); }
From source file:com.wudaosoft.net.httpclient.HostConfigBuilder.java
public HostConfig build() { requestConfig = RequestConfig.custom().setExpectContinueEnabled(false) // .setStaleConnectionCheckEnabled(true) .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST)) .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)) .setConnectionRequestTimeout(connectionRequestTimeout).setConnectTimeout(connectTimeout) .setSocketTimeout(socketTimeout).build(); SimpleHostConfig hostCofing = new SimpleHostConfig(requestConfig); hostCofing.setCA(ca);/*from w ww.j a va 2 s . c om*/ hostCofing.setCaPassword(caPassword); hostCofing.setCharset(charset); hostCofing.setHost(httpHost); hostCofing.setHostUrl(hostUrl); hostCofing.setHostCount(hostCount); hostCofing.setIsMulticlient(multiclient); hostCofing.setPoolSize(poolSize); hostCofing.setReferer(referer); hostCofing.setUserAgent(userAgent); return hostCofing; }