Search in sources :

Example 1 with DigestSchemeFactory

use of org.apache.http.impl.auth.DigestSchemeFactory in project robovm by robovm.

the class DefaultHttpClient method createAuthSchemeRegistry.

@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    return registry;
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Example 2 with DigestSchemeFactory

use of org.apache.http.impl.auth.DigestSchemeFactory in project apex-core by apache.

the class WebServicesClient method initAuth.

public static void initAuth(ConfigProvider configuration) {
    // Setting up BASIC and DIGEST auth
    setupUserPassAuthScheme(AuthScheme.BASIC, AuthSchemes.BASIC, new BasicSchemeFactory(), configuration);
    setupUserPassAuthScheme(AuthScheme.DIGEST, AuthSchemes.DIGEST, new DigestSchemeFactory(), configuration);
    // Adding kerberos standard auth
    setupHttpAuthScheme(AuthSchemes.KERBEROS, new KerberosSchemeFactory(), AuthScope.ANY, DEFAULT_TOKEN_CREDENTIALS);
    authRegistry = registryBuilder.build();
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) KerberosSchemeFactory(org.apache.http.impl.auth.KerberosSchemeFactory) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Example 3 with DigestSchemeFactory

use of org.apache.http.impl.auth.DigestSchemeFactory in project platform_external_apache-http by android.

the class DefaultHttpClient method createAuthSchemeRegistry.

@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    return registry;
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Example 4 with DigestSchemeFactory

use of org.apache.http.impl.auth.DigestSchemeFactory in project XobotOS by xamarin.

the class DefaultHttpClient method createAuthSchemeRegistry.

@Override
protected AuthSchemeRegistry createAuthSchemeRegistry() {
    AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
    registry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
    return registry;
}
Also used : BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Example 5 with DigestSchemeFactory

use of org.apache.http.impl.auth.DigestSchemeFactory in project wildfly by wildfly.

the class Utils method makeCallWithBasicAuthn.

/**
 * Returns response body for the given URL request as a String. It also checks if the returned HTTP status code is the
 * expected one. If the server returns {@link HttpServletResponse#SC_UNAUTHORIZED} and username is provided, then a new
 * request is created with the provided credentials (basic authentication).
 *
 * @param url URL to which the request should be made
 * @param user Username (may be null)
 * @param pass Password (may be null)
 * @param expectedStatusCode expected status code returned from the requested server
 * @param checkFollowupAuthState whether to check auth state for followup request - if set to true, followup
 *                               request is sent to server and 200 OK is expected directly (no re-authentication
 *                               challenge - 401 Unauthorized - is expected)
 * @return HTTP response body
 * @throws IOException
 * @throws URISyntaxException
 */
public static String makeCallWithBasicAuthn(URL url, String user, String pass, int expectedStatusCode, boolean checkFollowupAuthState) throws IOException, URISyntaxException {
    LOGGER.trace("Requesting URL " + url);
    // use UTF-8 charset for credentials
    Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.BASIC, new BasicSchemeFactory(StandardCharsets.UTF_8)).register(AuthSchemes.DIGEST, new DigestSchemeFactory(StandardCharsets.UTF_8)).build();
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultAuthSchemeRegistry(authSchemeRegistry).build()) {
        final HttpGet httpGet = new HttpGet(url.toURI());
        HttpResponse response = httpClient.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        if (HttpServletResponse.SC_UNAUTHORIZED != statusCode || StringUtils.isEmpty(user)) {
            assertEquals("Unexpected HTTP response status code.", expectedStatusCode, statusCode);
            return EntityUtils.toString(response.getEntity());
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("HTTP response was SC_UNAUTHORIZED, let's authenticate the user " + user);
        }
        HttpEntity entity = response.getEntity();
        if (entity != null)
            EntityUtils.consume(entity);
        final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, pass);
        HttpClientContext hc = new HttpClientContext();
        hc.setCredentialsProvider(new BasicCredentialsProvider());
        hc.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), url.getPort()), credentials);
        // enable auth
        response = httpClient.execute(httpGet, hc);
        statusCode = response.getStatusLine().getStatusCode();
        assertEquals("Unexpected status code returned after the authentication.", expectedStatusCode, statusCode);
        if (checkFollowupAuthState) {
            // Let's disable authentication for this client as we already have all the context necessary to be
            // authorized (we expect that gained 'nonce' value can be re-used in our case here).
            // By disabling authentication we simply get first server response and thus we can check whether we've
            // got 200 OK or different response code.
            RequestConfig reqConf = RequestConfig.custom().setAuthenticationEnabled(false).build();
            httpGet.setConfig(reqConf);
            response = httpClient.execute(httpGet, hc);
            statusCode = response.getStatusLine().getStatusCode();
            assertEquals("Unexpected status code returned after the authentication.", HttpURLConnection.HTTP_OK, statusCode);
        }
        return EntityUtils.toString(response.getEntity());
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpEntity(org.apache.http.HttpEntity) BasicSchemeFactory(org.apache.http.impl.auth.BasicSchemeFactory) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) AuthScope(org.apache.http.auth.AuthScope) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) DigestSchemeFactory(org.apache.http.impl.auth.DigestSchemeFactory)

Aggregations

BasicSchemeFactory (org.apache.http.impl.auth.BasicSchemeFactory)8 DigestSchemeFactory (org.apache.http.impl.auth.DigestSchemeFactory)8 AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)4 AuthSchemeRegistry (org.apache.http.auth.AuthSchemeRegistry)3 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)3 AuthScope (org.apache.http.auth.AuthScope)2 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)2 RequestConfig (org.apache.http.client.config.RequestConfig)2 KerberosSchemeFactory (org.apache.http.impl.auth.KerberosSchemeFactory)2 NTLMSchemeFactory (org.apache.http.impl.auth.NTLMSchemeFactory)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)2 EncryptedHttpRequestExecutor (com.iwave.ext.windows.winrm.encryption.EncryptedHttpRequestExecutor)1 MalformedURLException (java.net.MalformedURLException)1 MutableTriple (org.apache.commons.lang3.tuple.MutableTriple)1 HttpEntity (org.apache.http.HttpEntity)1 HttpException (org.apache.http.HttpException)1 HttpHost (org.apache.http.HttpHost)1 HttpResponse (org.apache.http.HttpResponse)1 AuthState (org.apache.http.auth.AuthState)1