Search in sources :

Example 16 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project lobcder by skoulouzis.

the class WebDAVSecurityTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    String propBasePath = "etc" + File.separator + "test.properties";
    Properties prop = TestSettings.getTestProperties(propBasePath);
    String testURL = prop.getProperty("webdav.test.url");
    // Some problem with the pom.xml. The properties are set but System.getProperty gets null
    if (testURL == null) {
        testURL = "http://localhost:8080/lobcder-1.0-SNAPSHOT/";
    }
    assertTrue(testURL != null);
    if (!testURL.endsWith("/")) {
        testURL = testURL + "/";
    }
    uri = URI.create(testURL);
    root = uri.toASCIIString();
    if (!root.endsWith("/")) {
        root += "/";
    }
    username1 = prop.getProperty(("webdav.test.username1"), "");
    if (username1 == null) {
        username1 = "user1";
    }
    assertTrue(username1 != null);
    password1 = prop.getProperty(("webdav.test.password1"), "");
    if (password1 == null) {
        password1 = "passwd1";
    }
    assertTrue(password1 != null);
    username2 = prop.getProperty(("webdav.test.username2"), "");
    if (username2 == null) {
        username2 = "user2";
    }
    assertTrue(username2 != null);
    password2 = prop.getProperty(("webdav.test.password2"), "");
    if (password2 == null) {
        password2 = "passwd2";
    }
    assertTrue(password2 != null);
    client1 = new HttpClient();
    assertNotNull(uri.getHost());
    assertNotNull(uri.getPort());
    assertNotNull(client1);
    int port = uri.getPort();
    if (port == -1) {
        port = 443;
    }
    ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
    Protocol https = new Protocol("https", socketFactory, port);
    Protocol.registerProtocol("https", https);
    client1.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username1, password1));
    client2 = new HttpClient();
    assertNotNull(uri.getHost());
    assertNotNull(uri.getPort());
    assertNotNull(client2);
    client2.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username2, password2));
// acMgr = getAccessControlManager(superuser);
}
Also used : EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) HttpClient(org.apache.commons.httpclient.HttpClient) AuthScope(org.apache.commons.httpclient.auth.AuthScope) Properties(java.util.Properties) Protocol(org.apache.commons.httpclient.protocol.Protocol) EasySSLProtocolSocketFactory(org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) BeforeClass(org.junit.BeforeClass)

Example 17 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope 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 18 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope 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)

Example 19 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project zaproxy by zaproxy.

the class HttpMethodDirector method authenticateProxy.

private void authenticateProxy(final HttpMethod method) throws AuthenticationException {
    // Clean up existing authentication headers
    boolean userDefinedAuthenticationHeaders = !cleanAuthHeaders(method, PROXY_AUTH_RESP);
    if (userDefinedAuthenticationHeaders) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("User defined '" + PROXY_AUTH_RESP + "' headers present in the request.");
        }
    }
    AuthState authstate = method.getProxyAuthState();
    AuthScheme authscheme = authstate.getAuthScheme();
    if (authscheme == null) {
        return;
    }
    if (authstate.isAuthRequested() || !authscheme.isConnectionBased()) {
        AuthScope authscope = new AuthScope(conn.getProxyHost(), conn.getProxyPort(), authscheme.getRealm(), authscheme.getSchemeName());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Authenticating with " + authscope);
        }
        Credentials credentials = this.state.getProxyCredentials(authscope);
        if (credentials != null) {
            if (userDefinedAuthenticationHeaders) {
                if (!method.getParams().getBooleanParameter(PARAM_REMOVE_USER_DEFINED_AUTH_HEADERS, false)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Ignoring proxy authentication, user defined '" + PROXY_AUTH_RESP + "' headers present in the request.");
                    }
                    return;
                }
                method.removeRequestHeader(PROXY_AUTH_RESP);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Removed user defined '" + PROXY_AUTH_RESP + "' headers.");
                }
            }
            String authstring = authscheme.authenticate(credentials, method);
            if (authstring != null) {
                method.addRequestHeader(new Header(PROXY_AUTH_RESP, authstring, true));
            }
        } else {
            if (LOG.isWarnEnabled()) {
                LOG.warn("Required proxy credentials not available for " + authscope);
                if (method.getProxyAuthState().isPreemptive()) {
                    LOG.warn("Preemptive authentication requested but no default " + "proxy credentials available");
                }
            }
        }
    }
}
Also used : AuthState(org.apache.commons.httpclient.auth.AuthState) AuthScope(org.apache.commons.httpclient.auth.AuthScope) AuthScheme(org.apache.commons.httpclient.auth.AuthScheme)

Example 20 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project zaproxy by zaproxy.

the class HttpMethodDirector method processProxyAuthChallenge.

private boolean processProxyAuthChallenge(final HttpMethod method) throws MalformedChallengeException, AuthenticationException {
    AuthState authstate = method.getProxyAuthState();
    Map<?, ?> proxyChallenges = AuthChallengeParser.parseChallenges(method.getResponseHeaders(PROXY_AUTH_CHALLENGE));
    if (proxyChallenges.isEmpty()) {
        LOG.debug("Proxy authentication challenge(s) not found");
        return false;
    }
    AuthScheme authscheme = null;
    try {
        authscheme = this.authProcessor.processChallenge(authstate, proxyChallenges);
    } catch (AuthChallengeException e) {
        if (LOG.isWarnEnabled()) {
            LOG.warn(e.getMessage());
        }
    }
    if (authscheme == null) {
        return false;
    }
    AuthScope authscope = new AuthScope(conn.getProxyHost(), conn.getProxyPort(), authscheme.getRealm(), authscheme.getSchemeName());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Proxy authentication scope: " + authscope);
    }
    if (authstate.isAuthAttempted() && authscheme.isComplete()) {
        // Already tried and failed
        Credentials credentials = promptForProxyCredentials(authscheme, method.getParams(), authscope);
        if (credentials == null) {
            if (LOG.isInfoEnabled()) {
                LOG.info("Failure authenticating with " + authscope);
            }
            return false;
        } else {
            return true;
        }
    } else {
        authstate.setAuthAttempted(true);
        Credentials credentials = this.state.getProxyCredentials(authscope);
        if (credentials == null) {
            credentials = promptForProxyCredentials(authscheme, method.getParams(), authscope);
        }
        if (credentials == null) {
            if (LOG.isInfoEnabled()) {
                LOG.info("No credentials available for " + authscope);
            }
            return false;
        } else {
            return true;
        }
    }
}
Also used : AuthChallengeException(org.apache.commons.httpclient.auth.AuthChallengeException) AuthState(org.apache.commons.httpclient.auth.AuthState) AuthScope(org.apache.commons.httpclient.auth.AuthScope) AuthScheme(org.apache.commons.httpclient.auth.AuthScheme)

Aggregations

AuthScope (org.apache.commons.httpclient.auth.AuthScope)52 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)34 Credentials (org.apache.commons.httpclient.Credentials)19 GetMethod (org.apache.commons.httpclient.methods.GetMethod)12 HttpClient (org.apache.commons.httpclient.HttpClient)11 URL (java.net.URL)10 IOException (java.io.IOException)5 NTCredentials (org.apache.commons.httpclient.NTCredentials)5 Protocol (org.apache.commons.httpclient.protocol.Protocol)5 ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)5 Header (org.apache.commons.httpclient.Header)4 AuthScheme (org.apache.commons.httpclient.auth.AuthScheme)4 AuthState (org.apache.commons.httpclient.auth.AuthState)4 EasySSLProtocolSocketFactory (org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory)4 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)3 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3