use of org.apache.commons.httpclient.UsernamePasswordCredentials in project zm-mailbox by Zimbra.
the class HttpProxyUtil method configureProxy.
public static synchronized void configureProxy(HttpClient client) {
try {
String url = Provisioning.getInstance().getLocalServer().getAttr(Provisioning.A_zimbraHttpProxyURL, null);
if (url == null)
return;
// need to initializae all the statics
if (sProxyUrl == null || !sProxyUrl.equals(url)) {
sProxyUrl = url;
sProxyUri = new URI(url);
sProxyAuthScope = null;
sProxyCreds = null;
String userInfo = sProxyUri.getUserInfo();
if (userInfo != null) {
int i = userInfo.indexOf(':');
if (i != -1) {
sProxyAuthScope = new AuthScope(sProxyUri.getHost(), sProxyUri.getPort(), null);
sProxyCreds = new UsernamePasswordCredentials(userInfo.substring(0, i), userInfo.substring(i + 1));
}
}
}
if (ZimbraLog.misc.isDebugEnabled()) {
ZimbraLog.misc.debug("setting proxy: " + url);
}
client.getHostConfiguration().setProxy(sProxyUri.getHost(), sProxyUri.getPort());
if (sProxyAuthScope != null && sProxyCreds != null)
client.getState().setProxyCredentials(sProxyAuthScope, sProxyCreds);
} catch (ServiceException e) {
ZimbraLog.misc.warn("Unable to configureProxy: " + e.getMessage(), e);
} catch (URISyntaxException e) {
ZimbraLog.misc.warn("Unable to configureProxy: " + e.getMessage(), e);
}
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project cloudstack by apache.
the class HTTPUtils method setCredentials.
/**
* @param username
* @param password
* @param httpClient
*/
public static void setCredentials(String username, String password, HttpClient httpClient) {
if (username != null && password != null && httpClient != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Setting credentials with username " + username + " for host " + httpClient.getHostConfiguration().getHost() + ":" + httpClient.getHostConfiguration().getPort());
}
httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getState().setCredentials(new AuthScope(httpClient.getHostConfiguration().getHost(), httpClient.getHostConfiguration().getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
}
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project maven-plugins by apache.
the class AbstractCheckDocumentationMojo method setupProxy.
/**
* Setup proxy access if needed.
*/
private void setupProxy() {
Proxy settingsProxy = settings.getActiveProxy();
if (settingsProxy != null) {
String proxyUsername = settingsProxy.getUsername();
String proxyPassword = settingsProxy.getPassword();
String proxyHost = settingsProxy.getHost();
int proxyPort = settingsProxy.getPort();
if (StringUtils.isNotEmpty(proxyHost)) {
httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
getLog().info("Using proxy [" + proxyHost + "] at port [" + proxyPort + "].");
if (StringUtils.isNotEmpty(proxyUsername)) {
getLog().info("Using proxy user [" + proxyUsername + "].");
Credentials creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
httpClient.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), creds);
httpClient.getParams().setAuthenticationPreemptive(true);
}
}
}
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class AuthenticatedTestUtil method assertAuthenticatedAdminPostStatus.
/** Execute a POST request and check status */
public void assertAuthenticatedAdminPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage) throws IOException {
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
assertAuthenticatedPostStatus(defaultcreds, url, expectedStatusCode, postParams, assertMessage);
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project sling by apache.
the class DeleteNodeCommand method execute.
@Override
public Result<Void> execute() {
PostMethod post = new PostMethod(getPath());
try {
Part[] parts = { new StringPart(":operation", "delete") };
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()));
httpClient.getParams().setAuthenticationPreemptive(true);
int responseStatus = httpClient.executeMethod(post);
return resultForResponseStatus(responseStatus);
} catch (Exception e) {
return AbstractResult.failure(new RepositoryException(e));
} finally {
post.releaseConnection();
}
}
Aggregations