use of org.apache.http.auth.NTCredentials in project htmlunit by HtmlUnit.
the class DefaultCredentialsProvider method addNTLMCredentials.
/**
* Adds NTLM credentials for the specified username/password on the specified host/port.
* @param username the username for the new credentials; should not include the domain to authenticate with;
* for example: <tt>"user"</tt> is correct whereas <tt>"DOMAIN\\user"</tt> is not
* @param password the password for the new credentials
* @param host the host to which to the new credentials apply ({@code null} if applicable to any host)
* @param port the port to which to the new credentials apply (negative if applicable to any port)
* @param workstation The workstation the authentication request is originating from.
* Essentially, the computer name for this machine.
* @param domain the domain to authenticate within
*/
public void addNTLMCredentials(final String username, final String password, final String host, final int port, final String workstation, final String domain) {
final AuthScope authscope = new AuthScope(host, port, ANY_REALM, ANY_SCHEME);
final Credentials credentials = new NTCredentials(username, password, workstation, domain);
setCredentials(authscope, credentials);
}
use of org.apache.http.auth.NTCredentials in project selenium_java by sergueik.
the class ProxyTest method testProxyCredentials.
@Test
public void testProxyCredentials() throws Exception {
WebDriverManager.config().setProxy("myproxy:8081").setProxyUser("domain\\me").setProxyPass("pass");
HttpClient wdmClient = new HttpClient();
Field field = HttpClient.class.getDeclaredField("closeableHttpClient");
field.setAccessible(true);
CloseableHttpClient client = (CloseableHttpClient) field.get(wdmClient);
field = client.getClass().getDeclaredField("credentialsProvider");
field.setAccessible(true);
BasicCredentialsProvider provider = (BasicCredentialsProvider) field.get(client);
NTCredentials ntcreds = (NTCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, NTLM));
assertThat(ntcreds.getDomain(), equalTo("DOMAIN"));
assertThat(ntcreds.getUserName(), equalTo("me"));
assertThat(ntcreds.getPassword(), equalTo("pass"));
UsernamePasswordCredentials creds = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT));
assertThat(creds.getUserName(), equalTo("domain\\me"));
assertThat(creds.getPassword(), equalTo("pass"));
}
use of org.apache.http.auth.NTCredentials in project ecf by eclipse.
the class HttpClientProxyCredentialProvider method fixNTCredentials.
public static Credentials fixNTCredentials(Credentials credentials) {
if (credentials == null) {
return null;
}
if (credentials instanceof NTCredentials) {
NTCredentials ntCreds = (NTCredentials) credentials;
String userName = ntCreds.getUserName();
String domainUser = getNTLMUserName(userName);
if (ntCreds.getDomain() == null || domainUser != userName) {
String domain = getNTLMDomainName(userName);
String workstation = getNTLMWorkstation();
return new NTCredentials(domainUser, ntCreds.getPassword(), workstation, domain);
}
} else if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials basicCredentials = (UsernamePasswordCredentials) credentials;
return createNTLMCredentials(basicCredentials.getUserName(), basicCredentials.getPassword());
}
return credentials;
}
use of org.apache.http.auth.NTCredentials in project cs-actions by CloudSlang.
the class CredentialsProviderBuilder method buildCredentialsProvider.
public CredentialsProvider buildCredentialsProvider() {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (!StringUtils.isEmpty(username)) {
Credentials credentials;
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;
}
use of org.apache.http.auth.NTCredentials in project cs-actions by CloudSlang.
the class CredentialsProviderBuilderTest method createNtlmCredentialsProvider.
@Test
public void createNtlmCredentialsProvider() {
CredentialsProvider credentialsProvider = getCredentialsProvider(AuthSchemes.NTLM);
Credentials credentials = credentialsProvider.getCredentials(new AuthScope("host", 80));
assertThat(credentials, instanceOf(NTCredentials.class));
NTCredentials ntCredentials = (NTCredentials) credentials;
assertEquals("DOMAIN", ntCredentials.getDomain());
assertEquals("HOST", ntCredentials.getWorkstation());
assertEquals("pass", ntCredentials.getPassword());
Credentials proxyCredentials = credentialsProvider.getCredentials(new AuthScope("proxy", 8080));
assertThat(proxyCredentials, instanceOf(UsernamePasswordCredentials.class));
UsernamePasswordCredentials userCredentials = (UsernamePasswordCredentials) proxyCredentials;
assertEquals("proxyUsername", userCredentials.getUserName());
}
Aggregations