use of org.apache.commons.httpclient.auth.AuthScope in project zaproxy by zaproxy.
the class HttpSender method setProxyAuth.
private void setProxyAuth(HttpState state) {
if (param.isUseProxyChain() && param.isUseProxyChainAuth()) {
String realm = param.getProxyChainRealm();
state.setProxyCredentials(new AuthScope(param.getProxyChainName(), param.getProxyChainPort(), realm.isEmpty() ? AuthScope.ANY_REALM : realm), new NTCredentials(param.getProxyChainUserName(), param.getProxyChainPassword(), "", realm));
}
}
use of org.apache.commons.httpclient.auth.AuthScope in project cloudstack by apache.
the class UriUtils method getInputStreamFromUrl.
public static InputStream getInputStreamFromUrl(String url, String user, String password) {
try {
Pair<String, Integer> hostAndPort = validateUrl(url);
HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
if ((user != null) && (password != null)) {
httpclient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
}
// Execute the method.
GetMethod method = new GetMethod(url);
int statusCode = httpclient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
return method.getResponseBodyAsStream();
} catch (Exception ex) {
s_logger.error("Failed to read from URL: " + url);
return null;
}
}
use of org.apache.commons.httpclient.auth.AuthScope in project cloudstack by apache.
the class HttpTemplateDownloader method checkCredentials.
private void checkCredentials(String user, String password) {
try {
Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl);
if ((user != null) && (password != null)) {
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
} else {
s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second());
}
} catch (IllegalArgumentException iae) {
errorString = iae.getMessage();
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
inited = false;
}
}
use of org.apache.commons.httpclient.auth.AuthScope in project java-apns by notnoop.
the class TlsTunnelBuilder method AuthenticateProxy.
private Socket AuthenticateProxy(ConnectMethod method, ProxyClient client, String proxyHost, int proxyPort, String proxyUsername, String proxyPassword) throws IOException {
if ("ntlm".equalsIgnoreCase(method.getProxyAuthState().getAuthScheme().getSchemeName())) {
// If Auth scheme is NTLM, set NT credentials with blank host and domain name
client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUsername, proxyPassword, "", ""));
} else {
// If Auth scheme is Basic/Digest, set regular Credentials
client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUsername, proxyPassword));
}
ProxyClient.ConnectResponse response = client.connect();
Socket socket = response.getSocket();
if (socket == null) {
method = response.getConnectMethod();
throw new ProtocolException("Proxy Authentication failed. Socket not created: " + method.getStatusLine());
}
return socket;
}
use of org.apache.commons.httpclient.auth.AuthScope in project intellij-community by JetBrains.
the class BaseRepositoryImpl method configureHttpClient.
protected void configureHttpClient(HttpClient client) {
client.getParams().setConnectionManagerTimeout(3000);
client.getParams().setSoTimeout(TaskSettings.getInstance().CONNECTION_TIMEOUT);
if (isUseProxy()) {
HttpConfigurable proxy = HttpConfigurable.getInstance();
client.getHostConfiguration().setProxy(proxy.PROXY_HOST, proxy.PROXY_PORT);
if (proxy.PROXY_AUTHENTICATION && proxy.getProxyLogin() != null) {
AuthScope authScope = new AuthScope(proxy.PROXY_HOST, proxy.PROXY_PORT);
Credentials credentials = getCredentials(proxy.getProxyLogin(), proxy.getPlainProxyPassword(), proxy.PROXY_HOST);
client.getState().setProxyCredentials(authScope, credentials);
}
}
if (isUseHttpAuthentication()) {
client.getParams().setCredentialCharset("UTF-8");
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword()));
} else {
client.getState().clearCredentials();
client.getParams().setAuthenticationPreemptive(false);
}
}
Aggregations