use of org.apache.commons.httpclient.UsernamePasswordCredentials in project zm-mailbox by Zimbra.
the class ExchangeFreeBusyProvider method basicAuth.
private boolean basicAuth(HttpClient client, ServerInfo info) {
HttpState state = new HttpState();
Credentials cred = new UsernamePasswordCredentials(info.authUsername, info.authPassword);
state.setCredentials(AuthScope.ANY, cred);
client.setState(state);
ArrayList<String> authPrefs = new ArrayList<String>();
authPrefs.add(AuthPolicy.BASIC);
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
return true;
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project zm-mailbox by Zimbra.
the class TestAccessKeyGrant method testCalendarGet_guest.
/*
* use zmmailbox to grant guest access:
* zmmailbox -z -m user1@phoebe.mac mfg Calendar guest g1@guest.com zzz r
*/
public void testCalendarGet_guest() throws Exception {
HttpState initialState = new HttpState();
/*
Cookie authCookie = new Cookie(restURL.getURL().getHost(), "ZM_AUTH_TOKEN", mAuthToken, "/", null, false);
Cookie sessionCookie = new Cookie(restURL.getURL().getHost(), "JSESSIONID", mSessionId, "/zimbra", null, false);
initialState.addCookie(authCookie);
initialState.addCookie(sessionCookie);
*/
String guestName = "g1@guest.com";
String guestPassword = "zzz";
Credentials loginCredentials = new UsernamePasswordCredentials(guestName, guestPassword);
initialState.setCredentials(AuthScope.ANY, loginCredentials);
HttpClient client = new HttpClient();
client.setState(initialState);
String url = getRestCalendarUrl(OWNER_NAME);
System.out.println("REST URL: " + url);
HttpMethod method = new GetMethod(url);
executeHttpMethod(client, method);
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials 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.UsernamePasswordCredentials in project maven-plugins by apache.
the class ClassicJiraDownloader method prepareBasicAuthentication.
/**
* Check and prepare for basic authentication.
*
* @param client The client to prepare
*/
private void prepareBasicAuthentication(HttpClient client) {
if ((webUser != null) && (webUser.length() > 0)) {
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials(webUser, webPassword);
getLog().debug("Using username: " + webUser + " for Basic Authentication.");
client.getState().setCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME), defaultcreds);
}
}
use of org.apache.commons.httpclient.UsernamePasswordCredentials in project maven-plugins by apache.
the class ClassicJiraDownloader method determineProxy.
/**
* Setup proxy access if we have to.
*
* @param client the HttpClient
*/
private void determineProxy(String jiraUrl, HttpClient client) {
// see whether there is any proxy defined in maven
getProxyInfo(jiraUrl);
if (proxyHost != null) {
client.getHostConfiguration().setProxy(proxyHost, proxyPort);
getLog().debug("Using proxy: " + proxyHost + " at port " + proxyPort);
if (proxyUser != null) {
getLog().debug("Using proxy user: " + proxyUser);
client.getState().setProxyCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME), new UsernamePasswordCredentials(proxyUser, proxyPass));
}
}
}
Aggregations