Search in sources :

Example 71 with UsernamePasswordCredentials

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);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) AuthScope(org.apache.commons.httpclient.auth.AuthScope) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 72 with UsernamePasswordCredentials

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

Example 73 with UsernamePasswordCredentials

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);
            }
        }
    }
}
Also used : Proxy(org.apache.maven.settings.Proxy) 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 74 with UsernamePasswordCredentials

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

Example 75 with UsernamePasswordCredentials

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();
    }
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) Part(org.apache.commons.httpclient.methods.multipart.Part) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) StringPart(org.apache.commons.httpclient.methods.multipart.StringPart) RepositoryException(org.apache.sling.ide.transport.RepositoryException) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) RepositoryException(org.apache.sling.ide.transport.RepositoryException) 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