Search in sources :

Example 1 with DigestScheme

use of org.apache.http.impl.auth.DigestScheme in project android_frameworks_base by ParanoidAndroid.

the class DefaultHttpClientTest method authenticateDigestAlgorithm.

private void authenticateDigestAlgorithm(String algorithm) throws Exception {
    String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
    HttpGet get = new HttpGet();
    digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with DigestScheme

use of org.apache.http.impl.auth.DigestScheme in project android_frameworks_base by ResurrectionRemix.

the class DefaultHttpClientTest method authenticateDigestAlgorithm.

private void authenticateDigestAlgorithm(String algorithm) throws Exception {
    String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
    HttpGet get = new HttpGet();
    digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 3 with DigestScheme

use of org.apache.http.impl.auth.DigestScheme in project android_frameworks_base by crdroidandroid.

the class DefaultHttpClientTest method authenticateDigestAlgorithm.

private void authenticateDigestAlgorithm(String algorithm) throws Exception {
    String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
    HttpGet get = new HttpGet();
    digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 4 with DigestScheme

use of org.apache.http.impl.auth.DigestScheme in project syncope by apache.

the class HttpUtils method postWithStringEntity.

public int postWithStringEntity(final String url, final String stringEntity) {
    int status = 0;
    try {
        final HttpPost httPost = httpPost(url, new StringEntity(stringEntity));
        httPost.addHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType());
        try (CloseableHttpResponse response = httpClient.execute(targetHost, httPost, setAuth(targetHost, new DigestScheme()))) {
            status = response.getStatusLine().getStatusCode();
            handler.logOutput("Http status: " + status, true);
            InstallLog.getInstance().info("Http status: " + status);
        }
    } catch (final IOException ioe) {
        final String messageError = "Error calling " + url + ": " + ioe.getMessage();
        handler.emitError(messageError, messageError);
        InstallLog.getInstance().error(messageError);
    }
    return status;
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Example 5 with DigestScheme

use of org.apache.http.impl.auth.DigestScheme in project tutorials by eugenp.

the class HttpComponentsClientHttpRequestFactoryDigestAuth method createHttpContext.

private HttpContext createHttpContext() {
    // Create AuthCache instance
    final AuthCache authCache = new BasicAuthCache();
    // Generate DIGEST scheme object, initialize it and add it to the local auth cache
    final DigestScheme digestAuth = new DigestScheme();
    // If we already know the realm name
    digestAuth.overrideParamter("realm", "Custom Realm Name");
    // digestAuth.overrideParamter("nonce", "MTM3NTU2OTU4MDAwNzoyYWI5YTQ5MTlhNzc5N2UxMGM5M2Y5M2ViOTc4ZmVhNg==");
    authCache.put(host, digestAuth);
    // Add AuthCache to the execution context
    final BasicHttpContext localcontext = new BasicHttpContext();
    localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
    return localcontext;
}
Also used : DigestScheme(org.apache.http.impl.auth.DigestScheme) BasicHttpContext(org.apache.http.protocol.BasicHttpContext) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache)

Aggregations

DigestScheme (org.apache.http.impl.auth.DigestScheme)16 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)13 HttpGet (org.apache.http.client.methods.HttpGet)7 IOException (java.io.IOException)6 BasicHeader (org.apache.http.message.BasicHeader)6 AuthScope (org.apache.http.auth.AuthScope)4 Map (java.util.Map)3 AuthScheme (org.apache.http.auth.AuthScheme)3 Credentials (org.apache.http.auth.Credentials)3 NTCredentials (org.apache.http.auth.NTCredentials)3 BasicScheme (org.apache.http.impl.auth.BasicScheme)3 NTLMScheme (org.apache.http.impl.auth.NTLMScheme)3 Authentication (org.codelibs.fess.crawler.client.http.Authentication)3 AuthenticationImpl (org.codelibs.fess.crawler.client.http.impl.AuthenticationImpl)3 JcifsEngine (org.codelibs.fess.crawler.client.http.ntlm.JcifsEngine)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)2