当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientContext.setAuthCache方法代码示例

本文整理汇总了Java中org.apache.http.client.protocol.HttpClientContext.setAuthCache方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientContext.setAuthCache方法的具体用法?Java HttpClientContext.setAuthCache怎么用?Java HttpClientContext.setAuthCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.protocol.HttpClientContext的用法示例。


在下文中一共展示了HttpClientContext.setAuthCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authSucceeded

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
public void authSucceeded(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    Args.notNull(authhost, "Host");
    Args.notNull(authScheme, "Auth scheme");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    if (isCachable(authScheme)) {
        AuthCache authCache = clientContext.getAuthCache();
        if (authCache == null) {
            authCache = new BasicAuthCache();
            clientContext.setAuthCache(authCache);
        }
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Caching '" + authScheme.getSchemeName() +
                    "' auth scheme for " + authhost);
        }
        authCache.put(authhost, authScheme);
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:22,代码来源:AuthenticationStrategyImpl.java

示例2: addPreemptiveAuthenticationProxy

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private static void addPreemptiveAuthenticationProxy(HttpClientContext clientContext,
                                                     ProxyConfiguration proxyConfiguration) {

    if (proxyConfiguration.preemptiveBasicAuthenticationEnabled()) {
        HttpHost targetHost = new HttpHost(proxyConfiguration.endpoint().getHost(), proxyConfiguration.endpoint().getPort());
        final CredentialsProvider credsProvider = newProxyCredentialsProvider(proxyConfiguration);
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate BASIC scheme object and add it to the local auth cache
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);

        clientContext.setCredentialsProvider(credsProvider);
        clientContext.setAuthCache(authCache);
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:17,代码来源:ApacheUtils.java

示例3: addPreemptiveAuthenticationProxy

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private static void addPreemptiveAuthenticationProxy(HttpClientContext clientContext,
                                                     HttpClientSettings settings) {

    if (settings.isPreemptiveBasicProxyAuth()) {
        HttpHost targetHost = new HttpHost(settings.getProxyHost(), settings
                .getProxyPort());
        final CredentialsProvider credsProvider = newProxyCredentialsProvider(settings);
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate BASIC scheme object and add it to the local auth cache
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);

        clientContext.setCredentialsProvider(credsProvider);
        clientContext.setAuthCache(authCache);
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:ApacheUtils.java

示例4: createHttpClientContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
/**
 * Creates client context.
 * @param url url
 * @param cred credentials
 * @return client context
 */
public static HttpClientContext createHttpClientContext(URL url, SimpleCredentials cred) {
  HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
  CredentialsProvider credsProvider = new BasicCredentialsProvider();
  credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
          new UsernamePasswordCredentials(cred.getUserName(),cred.getPassword()));    
  
  // Create AuthCache instance
  AuthCache authCache = new BasicAuthCache();
  // Generate BASIC scheme object and add it to the local auth cache
  BasicScheme basicAuth = new BasicScheme();
  authCache.put(targetHost, basicAuth);

  // Add AuthCache to the execution context
  HttpClientContext context = HttpClientContext.create();
  context.setCredentialsProvider(credsProvider);
  context.setAuthCache(authCache);
  
  return context;
}
 
开发者ID:Esri,项目名称:geoportal-server-harvester,代码行数:26,代码来源:HttpClientContextBuilder.java

示例5: configureContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private HttpClientContext configureContext(CredentialsProvider credentialsProvider, String url) {
  if (credentialsProvider != null) {
    try {
      URL targetUrl = new URL(url);

      HttpHost targetHost =
          new HttpHost(targetUrl.getHost(), targetUrl.getPort(), targetUrl.getProtocol());
      AuthCache authCache = new BasicAuthCache();
      authCache.put(targetHost, new BasicScheme());

      final HttpClientContext context = HttpClientContext.create();
      context.setCredentialsProvider(credentialsProvider);
      context.setAuthCache(authCache);

      return context;
    } catch (MalformedURLException e) {
      LOG.error("Cannot parse URL '{}'", url, e);
    }
  }
  return null;
}
 
开发者ID:reflectoring,项目名称:infiniboard,代码行数:22,代码来源:UrlSourceJob.java

示例6: buildHttpContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
/**
 * Builds a configured HTTP context object that is pre-configured for
 * using HTTP Signature authentication.
 *
 * @param configurator HTTP Signatures configuration helper to pull properties from
 * @return configured HTTP context object
 */
protected HttpContext buildHttpContext(final HttpSignatureConfigurator configurator) {
    final HttpClientContext context = HttpClientContext.create();

    if (configurator != null) {
        AuthCache authCache = new BasicAuthCache();
        context.setAuthCache(authCache);

        AuthState authState = new AuthState();
        authState.update(configurator.getAuthScheme(), configurator.getCredentials());

        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE,
                authState);
        context.getTargetAuthState().setState(AuthProtocolState.UNCHALLENGED);

    }

    return context;
}
 
开发者ID:joyent,项目名称:java-triton,代码行数:26,代码来源:CloudApiApacheHttpClientContext.java

示例7: getRequestContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Override
protected HttpContext getRequestContext(URI imageUrl, String imageIdentifier,
        ConfluenceConfiguration config) {
    HttpHost targetHost = new HttpHost(imageUrl.getHost(), imageUrl.getPort());
    CredentialsProvider credentialsProviderProvider = new BasicCredentialsProvider();
    credentialsProviderProvider.setCredentials(new AuthScope(targetHost.getHostName(),
            targetHost.getPort()), new UsernamePasswordCredentials(config.getAdminLogin(),
            config.getAdminPassword()));

    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();
    // preemptive authentication (send credentials with request) by adding host to auth cache
    // TODO maybe use real basic auth challenge?
    authCache.put(targetHost, basicAuth);
    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credentialsProviderProvider);
    context.setAuthCache(authCache);
    return context;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:20,代码来源:ConfluenceUserImageProvider.java

示例8: authSucceeded

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Override
public void authSucceeded(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    Args.notNull(authhost, "Host");
    Args.notNull(authScheme, "Auth scheme");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    if (isCachable(authScheme)) {
        AuthCache authCache = clientContext.getAuthCache();
        if (authCache == null) {
            authCache = new BasicAuthCache();
            clientContext.setAuthCache(authCache);
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Caching '" + authScheme.getSchemeName() +
                    "' auth scheme for " + authhost);
        }
        authCache.put(authhost, authScheme);
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:AuthenticationStrategyImpl.java

示例9: testPreemptiveAuthentication

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testPreemptiveAuthentication() throws Exception {
    final CountingAuthHandler requestHandler = new CountingAuthHandler();
    this.serverBootstrap.registerHandler("*", requestHandler);

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();
    final AuthCache authCache = new BasicAuthCache();
    authCache.put(target, new BasicScheme());
    context.setAuthCache(authCache);
    final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("test", "test"));
    context.setCredentialsProvider(credsProvider);

    final HttpGet httpget = new HttpGet("/");
    final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
    final HttpEntity entity1 = response1.getEntity();
    Assert.assertEquals(HttpStatus.SC_OK, response1.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity1);
    EntityUtils.consume(entity1);

    Assert.assertEquals(1, requestHandler.getCount());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestClientAuthentication.java

示例10: testPreemptiveAuthenticationFailure

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
@Test
public void testPreemptiveAuthenticationFailure() throws Exception {
    final CountingAuthHandler requestHandler = new CountingAuthHandler();
    this.serverBootstrap.registerHandler("*", requestHandler);

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();
    final AuthCache authCache = new BasicAuthCache();
    authCache.put(target, new BasicScheme());
    context.setAuthCache(authCache);
    final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("test", "stuff"));
    context.setCredentialsProvider(credsProvider);

    final HttpGet httpget = new HttpGet("/");
    final HttpResponse response1 = this.httpclient.execute(target, httpget, context);
    final HttpEntity entity1 = response1.getEntity();
    Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response1.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity1);
    EntityUtils.consume(entity1);

    Assert.assertEquals(1, requestHandler.getCount());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestClientAuthentication.java

示例11: createContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private HttpClientContext createContext(Authentication auth, HttpHost target) {
	HttpClientContext httpClientContext = HttpClientContext.create();
	CookieStore cookieStore = new BasicCookieStore();
	httpClientContext.setCookieStore(cookieStore);
	if (auth.usePreemptiveAuthentication()) {
		httpClientContext.setAuthCache(new Auth().getAuthCache(auth, target));
	}
	return httpClientContext;
}
 
开发者ID:Hi-Fi,项目名称:httpclient,代码行数:10,代码来源:RestClient.java

示例12: prepareContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private HttpClientContext prepareContext()
{
    HttpHost targetHost = new HttpHost(serverConfig.getServerName(), serverConfig.getPort(), serverConfig.isUseHTTPS() ? "https" : "http");
    AuthCache authCache = new BasicAuthCache();
    authCache.put(targetHost, new BasicScheme());

    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials
     = new UsernamePasswordCredentials(serverConfig.getUserName(), serverConfig.getPassword());
    credsProvider.setCredentials(AuthScope.ANY, credentials);

    // Add AuthCache to the execution context
    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);
    context.setAuthCache(authCache);
    return context;
}
 
开发者ID:a-schild,项目名称:nextcloud-java-api,代码行数:18,代码来源:ConnectorCommon.java

示例13: httpContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private HttpContext httpContext() {
    BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
    if (isNotBlank(this.username) && this.password != null) {
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(this.username, this.password);
        HttpHost httpHost = HttpHost.create(this.rootConfluenceUrl);
        AuthScope authScope = new AuthScope(httpHost);
        basicCredentialsProvider.setCredentials(authScope, credentials);

        BasicAuthCache basicAuthCache = new BasicAuthCache();
        basicAuthCache.put(httpHost, new BasicScheme());

        HttpClientContext httpClientContext = HttpClientContext.create();
        httpClientContext.setCredentialsProvider(basicCredentialsProvider);
        httpClientContext.setAuthCache(basicAuthCache);

        return httpClientContext;
    } else {
        return null;
    }
}
 
开发者ID:jboz,项目名称:living-documentation,代码行数:21,代码来源:ConfluenceRestClient.java

示例14: createHttpClientContextFromConfig

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
private HttpClientContext createHttpClientContextFromConfig() {
    // create context from config
    HttpClientContext context = HttpClientContext.create();

    if (config.getCookieStore() != null) {
        context.setCookieStore(config.getCookieStore());
    }

    if (config.getCredsProvider() != null) {
        context.setCredentialsProvider(config.getCredsProvider());
    }

    if (config.getAuthCache() != null) {
        context.setAuthCache(config.getAuthCache());
    }

    return context;
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-testing-clients,代码行数:19,代码来源:AbstractSlingClient.java

示例15: createContext

import org.apache.http.client.protocol.HttpClientContext; //导入方法依赖的package包/类
public final HttpContext createContext(URI uri,
        UsernamePasswordCredentials creds) throws Exception {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(
            new AuthScope(uri.getHost(), uri.getPort()),
            creds);
    org.apache.http.HttpHost host = new org.apache.http.HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(host, basicAuth);
    HttpClientContext context1 = HttpClientContext.create();
    context1.setCredentialsProvider(credsProvider);
    context1.setAuthCache(authCache);
    return context1;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:16,代码来源:AbstractHttpClient.java


注:本文中的org.apache.http.client.protocol.HttpClientContext.setAuthCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。