Search in sources :

Example 11 with UsernamePasswordCredentials

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;
}
Also used : HttpState(org.apache.commons.httpclient.HttpState) ArrayList(java.util.ArrayList) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 12 with UsernamePasswordCredentials

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);
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) HttpState(org.apache.commons.httpclient.HttpState) GetMethod(org.apache.commons.httpclient.methods.GetMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) HttpMethod(org.apache.commons.httpclient.HttpMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 13 with UsernamePasswordCredentials

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;
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) AuthScope(org.apache.commons.httpclient.auth.AuthScope) GetMethod(org.apache.commons.httpclient.methods.GetMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 14 with UsernamePasswordCredentials

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);
    }
}
Also used : AuthScope(org.apache.commons.httpclient.auth.AuthScope) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 15 with UsernamePasswordCredentials

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));
        }
    }
}
Also used : AuthScope(org.apache.commons.httpclient.auth.AuthScope) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)113 Credentials (org.apache.commons.httpclient.Credentials)97 ArrayList (java.util.ArrayList)65 NameValuePair (org.apache.commons.httpclient.NameValuePair)61 JsonObject (javax.json.JsonObject)52 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)51 Test (org.junit.Test)51 JsonArray (javax.json.JsonArray)19 HttpClient (org.apache.commons.httpclient.HttpClient)19 AuthScope (org.apache.commons.httpclient.auth.AuthScope)17 HashSet (java.util.HashSet)14 GetMethod (org.apache.commons.httpclient.methods.GetMethod)14 HttpException (org.apache.commons.httpclient.HttpException)9 IOException (java.io.IOException)8 HttpMethod (org.apache.commons.httpclient.HttpMethod)8 HttpState (org.apache.commons.httpclient.HttpState)6 PostMethod (org.apache.commons.httpclient.methods.PostMethod)6 URL (java.net.URL)5 RepositoryException (org.apache.sling.ide.transport.RepositoryException)5 Header (org.apache.commons.httpclient.Header)4