use of org.apache.hc.client5.http.auth.AuthScope in project ecf by eclipse.
the class HttpClientRetrieveFileTransfer method setupAuthentication.
protected void setupAuthentication(String urlString) throws UnsupportedCallbackException, IOException {
Credentials credentials = null;
if (username == null) {
credentials = getFileRequestCredentials();
}
if (credentials != null && username != null) {
final AuthScope authScope = new AuthScope(getHostFromURL(urlString), getPortFromURL(urlString));
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "retrieve credentials=" + credentials);
credentialsProvider.setCredentials(authScope, credentials);
}
}
use of org.apache.hc.client5.http.auth.AuthScope in project ecf by eclipse.
the class HttpClientProxyCredentialProvider method getCredentials.
@Override
public Credentials getCredentials(AuthScope authscope, HttpContext httpContext) {
// $NON-NLS-1$
Trace.entering(Activator.PLUGIN_ID, DebugOptions.METHODS_ENTERING, HttpClientProxyCredentialProvider.class, "getCredentials " + authscope);
// First check to see whether given authscope matches any authscope
// already cached.
Credentials result = super.getCredentials(authscope, httpContext);
// If we have a match, return credentials
if (result != null) {
if ("ntlm".equalsIgnoreCase(authscope.getSchemeName())) {
// $NON-NLS-1$
// We might have gotten these from a password prompt, making them
// UsernamePasswordCredentials...
Credentials fixed = fixNTCredentials(result);
if (fixed != result) {
result = fixed;
setCredentials(authscope, fixed);
}
}
return result;
}
// If we don't have a match, first get ECF proxy, if any
Proxy proxy = getECFProxy();
if (proxy == null)
return null;
// Make sure that authscope and proxy host and port match
if (!matchAuthScopeAndProxy(authscope, proxy))
return null;
// Then match scheme, and get credentials from proxy (if it's scheme we know about)
Credentials credentials = null;
if ("ntlm".equalsIgnoreCase(authscope.getSchemeName())) {
// $NON-NLS-1$
credentials = getNTLMCredentials(proxy);
} else if (// $NON-NLS-1$
"basic".equalsIgnoreCase(authscope.getSchemeName()) || "digest".equalsIgnoreCase(authscope.getSchemeName())) {
// $NON-NLS-1$
final String proxyUsername = proxy.getUsername();
final String proxyPassword = proxy.getPassword();
// If credentials present for proxy then we're done
if (proxyUsername != null) {
credentials = new UsernamePasswordCredentials(proxyUsername, proxyPassword.toCharArray());
}
} else if ("negotiate".equalsIgnoreCase(authscope.getSchemeName())) {
// $NON-NLS-1$
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "SPNEGO is not supported, if you can contribute support, please do so.");
} else {
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "Unrecognized authentication scheme.");
}
// Put found credentials in cache for next time
if (credentials != null)
setCredentials(authscope, credentials);
return credentials;
}
use of org.apache.hc.client5.http.auth.AuthScope in project ecf by eclipse.
the class HttpClientFileSystemBrowser method setupAuthentication.
protected void setupAuthentication(String urlString) throws UnsupportedCallbackException, IOException {
Credentials credentials = null;
if (username == null) {
credentials = getFileRequestCredentials();
}
if (credentials != null && username != null) {
final AuthScope authScope = new AuthScope(HttpClientRetrieveFileTransfer.getHostFromURL(urlString), HttpClientRetrieveFileTransfer.getPortFromURL(urlString));
// $NON-NLS-1$
Trace.trace(Activator.PLUGIN_ID, "browse credentials=" + credentials);
credentialsProvider.setCredentials(authScope, credentials);
}
}
use of org.apache.hc.client5.http.auth.AuthScope in project wiremock by wiremock.
the class WireMockTestClient method httpClientWithPreemptiveAuth.
private static CloseableHttpClient httpClientWithPreemptiveAuth(HttpHost target, String username, String password) {
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(target), new UsernamePasswordCredentials(username, password.toCharArray()));
return HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
}
use of org.apache.hc.client5.http.auth.AuthScope in project jahia by Jahia.
the class HttpClientService method initHttpClient.
private CloseableHttpClient initHttpClient(HttpClientBuilder builder, String protocol) {
String host = System.getProperty(protocol + ".proxyHost");
int port = Integer.getInteger(protocol + ".proxyPort", -1);
HttpHost proxy = new HttpHost(protocol, host, port);
builder.setProxy(proxy);
String key = host + ':' + port;
BasicCredentialsProvider credsProvider = null;
String user = System.getProperty(protocol + ".proxyUser");
if (StringUtils.isNotEmpty(user)) {
credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(user, System.getProperty(protocol + ".proxyPassword").toCharArray()));
builder.setDefaultCredentialsProvider(credsProvider);
}
if (logger.isInfoEnabled()) {
logger.info("Initialized HttpClient for {} protocol using proxy {} {} credentials", protocol.toUpperCase(), key, credsProvider != null ? "with" : "without");
}
CloseableHttpClient client = builder.build();
httpClients.put(key, client);
return client;
}
Aggregations