當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpClientContext.getCredentialsProvider方法代碼示例

本文整理匯總了Java中org.apache.http.client.protocol.HttpClientContext.getCredentialsProvider方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpClientContext.getCredentialsProvider方法的具體用法?Java HttpClientContext.getCredentialsProvider怎麽用?Java HttpClientContext.getCredentialsProvider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.protocol.HttpClientContext的用法示例。


在下文中一共展示了HttpClientContext.getCredentialsProvider方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: select

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Auth scheme registry not set in the context");
        }
        return options;
    }
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Credentials provider not set in the context");
        }
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id: authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (Log.isLoggable(TAG, Log.WARN)) {
                    Log.w(TAG, "Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(
                    authhost.getHostName(),
                    authhost.getPort(),
                    authScheme.getRealm(),
                    authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
開發者ID:xxonehjh,項目名稱:remote-files-sync,代碼行數:69,代碼來源:AuthenticationStrategyImpl.java

示例2: select

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Override
public Queue<AuthOption> select(
        final Map<String, Header> challenges,
        final HttpHost authhost,
        final HttpResponse response,
        final HttpContext context) throws MalformedChallengeException {
    Args.notNull(challenges, "Map of auth challenges");
    Args.notNull(authhost, "Host");
    Args.notNull(response, "HTTP response");
    Args.notNull(context, "HTTP context");
    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final Queue<AuthOption> options = new LinkedList<AuthOption>();
    final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
    if (registry == null) {
        this.log.debug("Auth scheme registry not set in the context");
        return options;
    }
    final CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
    if (credsProvider == null) {
        this.log.debug("Credentials provider not set in the context");
        return options;
    }
    final RequestConfig config = clientContext.getRequestConfig();
    Collection<String> authPrefs = getPreferredAuthSchemes(config);
    if (authPrefs == null) {
        authPrefs = DEFAULT_SCHEME_PRIORITY;
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
    }

    for (final String id: authPrefs) {
        final Header challenge = challenges.get(id.toLowerCase(Locale.ROOT));
        if (challenge != null) {
            final AuthSchemeProvider authSchemeProvider = registry.lookup(id);
            if (authSchemeProvider == null) {
                if (this.log.isWarnEnabled()) {
                    this.log.warn("Authentication scheme " + id + " not supported");
                    // Try again
                }
                continue;
            }
            final AuthScheme authScheme = authSchemeProvider.create(context);
            authScheme.processChallenge(challenge);

            final AuthScope authScope = new AuthScope(
                    authhost.getHostName(),
                    authhost.getPort(),
                    authScheme.getRealm(),
                    authScheme.getSchemeName());

            final Credentials credentials = credsProvider.getCredentials(authScope);
            if (credentials != null) {
                options.add(new AuthOption(authScheme, credentials));
            }
        } else {
            if (this.log.isDebugEnabled()) {
                this.log.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }
    return options;
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:66,代碼來源:AuthenticationStrategyImpl.java

示例3: testUserInfoInRequestURI

import org.apache.http.client.protocol.HttpClientContext; //導入方法依賴的package包/類
@Test
public void testUserInfoInRequestURI() throws Exception {
    final HttpRoute route = new HttpRoute(new HttpHost("somehost", 8080));
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(
            new HttpGet("http://somefella:[email protected]/test"));
    final HttpClientContext context = HttpClientContext.create();
    protocolExec.execute(route, request, context, execAware);
    Assert.assertEquals(new URI("/test"), request.getURI());
    Assert.assertEquals(new HttpHost("bar", -1), context.getTargetHost());
    final CredentialsProvider credentialsProvider = context.getCredentialsProvider();
    Assert.assertNotNull(credentialsProvider);
    final Credentials creds = credentialsProvider.getCredentials(new AuthScope("bar", -1, null));
    Assert.assertNotNull(creds);
    Assert.assertEquals("somefella", creds.getUserPrincipal().getName());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:16,代碼來源:TestProtocolExec.java


注:本文中的org.apache.http.client.protocol.HttpClientContext.getCredentialsProvider方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。