use of org.apache.http.auth.NTCredentials in project hale by halestudio.
the class ClientProxyUtil method createCredentials.
/**
* Create a credentials object.
*
* @param user the user name
* @param password the password
* @return the created credentials
*/
public static Credentials createCredentials(String user, String password) {
Credentials credentials;
int sepIndex = user.indexOf('\\');
if (sepIndex > 0 && sepIndex + 1 < user.length()) {
// assume this is DOMAIN \ user for NTLM authentication
String userName = user.substring(sepIndex + 1);
String domain = user.substring(0, sepIndex);
String workstation = null;
credentials = new NTCredentials(userName, password, workstation, domain);
} else {
credentials = new UsernamePasswordCredentials(user, password);
}
return credentials;
}
use of org.apache.http.auth.NTCredentials in project coprhd-controller by CoprHD.
the class WinRMTarget method createHttpClientContext.
protected HttpClientContext createHttpClientContext() {
HttpClientContext httpClientContext = HttpClientContext.create();
// Build the credential provider. Note that the credentials are using NTCredentials class which is a derived class of UserPasswordCredentials
// This is specifically needed for NTLM authentication.
// NTCredentials requires user name in the format "user" and NOT "domain\\user"
String[] tokens = StringUtils.split(getUsername(), "\\", 2);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(tokens.length > 1 ? tokens[1] : getUsername(), getPassword(), System.getProperty("hostname"), tokens.length > 1 ? tokens[0] : null));
httpClientContext.setCredentialsProvider(credsProvider);
httpClientContext.setTargetHost(new HttpHost(getHost()));
return httpClientContext;
}
use of org.apache.http.auth.NTCredentials in project crawler4j by yasserg.
the class PageFetcher method addNtCredentials.
/**
* Do NT auth for Microsoft AD sites.
*/
private void addNtCredentials(NtAuthInfo authInfo, Map<AuthScope, Credentials> credentialsMap) {
logger.info("NT authentication for: {}", authInfo.getLoginTarget());
try {
Credentials credentials = new NTCredentials(authInfo.getUsername(), authInfo.getPassword(), InetAddress.getLocalHost().getHostName(), authInfo.getDomain());
credentialsMap.put(new AuthScope(authInfo.getHost(), authInfo.getPort()), credentials);
} catch (UnknownHostException e) {
logger.error("Error creating NT credentials", e);
}
}
use of org.apache.http.auth.NTCredentials in project robovm by robovm.
the class NTLMScheme method authenticate.
public Header authenticate(final Credentials credentials, final HttpRequest request) throws AuthenticationException {
NTCredentials ntcredentials = null;
try {
ntcredentials = (NTCredentials) credentials;
} catch (ClassCastException e) {
throw new InvalidCredentialsException("Credentials cannot be used for NTLM authentication: " + credentials.getClass().getName());
}
String response = null;
if (this.state == State.CHALLENGE_RECEIVED || this.state == State.FAILED) {
response = this.engine.generateType1Msg(ntcredentials.getDomain(), ntcredentials.getWorkstation());
this.state = State.MSG_TYPE1_GENERATED;
} else if (this.state == State.MSG_TYPE2_RECEVIED) {
response = this.engine.generateType3Msg(ntcredentials.getUserName(), ntcredentials.getPassword(), ntcredentials.getDomain(), ntcredentials.getWorkstation(), this.challenge);
this.state = State.MSG_TYPE3_GENERATED;
} else {
throw new AuthenticationException("Unexpected state: " + this.state);
}
CharArrayBuffer buffer = new CharArrayBuffer(32);
if (isProxy()) {
buffer.append(AUTH.PROXY_AUTH_RESP);
} else {
buffer.append(AUTH.WWW_AUTH_RESP);
}
buffer.append(": NTLM ");
buffer.append(response);
return new BufferedHeader(buffer);
}
use of org.apache.http.auth.NTCredentials in project jmeter by apache.
the class AuthManager method setupCredentials.
/**
* Configure credentials and auth scheme on client if an authorization is
* available for url
* @param client {@link HttpClient}
* @param url URL to test
* @param credentialsProvider {@link CredentialsProvider}
* @param localHost host running JMeter
*/
public void setupCredentials(HttpClient client, URL url, CredentialsProvider credentialsProvider, String localHost) {
Authorization auth = getAuthForURL(url);
if (auth != null) {
String username = auth.getUser();
String realm = auth.getRealm();
String domain = auth.getDomain();
if (log.isDebugEnabled()) {
log.debug(username + " > D=" + domain + " R=" + realm + " M=" + auth.getMechanism());
}
if (Mechanism.KERBEROS.equals(auth.getMechanism())) {
((AbstractHttpClient) client).getAuthSchemes().register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(isStripPort(url)));
credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
} else {
credentialsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort(), realm.length() == 0 ? null : realm), new NTCredentials(username, auth.getPass(), localHost, domain));
}
}
}
Aggregations