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


Java AuthCache类代码示例

本文整理汇总了Java中org.apache.http.client.AuthCache的典型用法代码示例。如果您正苦于以下问题:Java AuthCache类的具体用法?Java AuthCache怎么用?Java AuthCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: authSucceeded

import org.apache.http.client.AuthCache; //导入依赖的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: authSucceeded

import org.apache.http.client.AuthCache; //导入依赖的package包/类
public void authSucceeded(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    if (authhost == null) {
        throw new IllegalArgumentException("Host may not be null");
    }
    if (authScheme == null) {
        throw new IllegalArgumentException("Auth scheme may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    if (isCachable(authScheme)) {
        AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
        if (authCache == null) {
            authCache = new BasicAuthCache();
            context.setAttribute(ClientContext.AUTH_CACHE, authCache);
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Caching '" + authScheme.getSchemeName() +
                    "' auth scheme for " + authhost);
        }
        authCache.put(authhost, authScheme);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:AuthenticationStrategyImpl.java

示例3: authFailed

import org.apache.http.client.AuthCache; //导入依赖的package包/类
public void authFailed(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    if (authhost == null) {
        throw new IllegalArgumentException("Host may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    AuthCache authCache = (AuthCache) context.getAttribute(ClientContext.AUTH_CACHE);
    if (authCache != null) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("Clearing cached auth scheme for " + authhost);
        }
        authCache.remove(authhost);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AuthenticationStrategyImpl.java

示例4: addPreemptiveAuthenticationProxy

import org.apache.http.client.AuthCache; //导入依赖的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

示例5: addPreemptiveAuthenticationProxy

import org.apache.http.client.AuthCache; //导入依赖的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

示例6: createHttpClientContext

import org.apache.http.client.AuthCache; //导入依赖的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

示例7: BitcoindApiHandler

import org.apache.http.client.AuthCache; //导入依赖的package包/类
public BitcoindApiHandler(String host, int port, String protocol, String uri, String username, String password) {
	this.uri = uri;

	httpClient = HttpClients.createDefault();

	targetHost = new HttpHost(host, port, protocol);
	CredentialsProvider credsProvider = new BasicCredentialsProvider();
	credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
			new UsernamePasswordCredentials(username, password));

	AuthCache authCache = new BasicAuthCache();
	BasicScheme basicAuth = new BasicScheme();
	authCache.put(targetHost, basicAuth);

	context = HttpClientContext.create();
	context.setCredentialsProvider(credsProvider);
	context.setAuthCache(authCache);
}
 
开发者ID:SulacoSoft,项目名称:BitcoindConnector4J,代码行数:19,代码来源:BitcoindApiHandler.java

示例8: checkLocalContext

import org.apache.http.client.AuthCache; //导入依赖的package包/类
private synchronized void checkLocalContext()
{
    if (null != sdkProtocolAdatperCustProvider && null != target)
    {
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate DIGEST scheme object, initialize it and add it to the local auth cache
        String authType = (String) ThreadLocalHolder.get().getEntities().get("AuthType");
        if ("Basic".equals(authType))
        {
            LOGGER.debug("authentication type: basic");
        }
        else
        {
            DigestScheme digestAuth = new DigestScheme();
            digestAuth.overrideParamter("nc", String.valueOf(serverNounceCount++));
            digestAuth.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
            digestAuth.overrideParamter("qop", "auth");
            authCache.put(target, digestAuth);
        }
        
        // Add AuthCache to the execution context
        localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:27,代码来源:RestfulAdapterImplHttpClient.java

示例9: checkLocalContext

import org.apache.http.client.AuthCache; //导入依赖的package包/类
private synchronized void checkLocalContext()
{
    if (null != sdkProtocolAdatperCustProvider && null != target)
    {
        // Create AuthCache instance
        AuthCache authCache = new BasicAuthCache();
        // Generate DIGEST scheme object, initialize it and add it to the local auth cache
        String authType = (String)ThreadLocalHolder.get().getEntities().get("AuthType");
        if ("Basic".equals(authType))
        {
            LOGGER.debug("authentication type: basic");
        }
        else
        {
            DigestScheme digestAuth = new DigestScheme();
            digestAuth.overrideParamter("nc", String.valueOf(serverNounceCount++));
            digestAuth.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
            digestAuth.overrideParamter("qop", "auth");
            authCache.put(target, digestAuth);
        }
        
        // Add AuthCache to the execution context
        localContext = new BasicHttpContext();
        localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
    }
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:27,代码来源:RestfulAdapterImplHttpClientHTLS.java

示例10: configureContext

import org.apache.http.client.AuthCache; //导入依赖的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

示例11: authFailed

import org.apache.http.client.AuthCache; //导入依赖的package包/类
public void authFailed(
        final HttpHost authhost, final AuthScheme authScheme, final HttpContext context) {
    Args.notNull(authhost, "Host");
    Args.notNull(context, "HTTP context");

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    final AuthCache authCache = clientContext.getAuthCache();
    if (authCache != null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Clearing cached auth scheme for " + authhost);
        }
        authCache.remove(authhost);
    }
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:16,代码来源:AuthenticationStrategyImpl.java

示例12: buildHttpContext

import org.apache.http.client.AuthCache; //导入依赖的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

示例13: createClient

import org.apache.http.client.AuthCache; //导入依赖的package包/类
private CloseableHttpClient createClient(String user, String password) {
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
    cm.setMaxTotal(TOTAL_CONN);
    cm.setDefaultMaxPerRoute(ROUTE_CONN);

    logger.info("Pooling connection manager created.");

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
    logger.info("Default credentials provider created.");

    AuthCache authCache = new BasicAuthCache();
    BasicScheme basicAuth = new BasicScheme();

    authCache.put(new HttpHost(rootUri.getHost(), rootUri.getPort(), rootUri.getScheme()), basicAuth);
    logger.info("Auth cache created.");

    httpContext = HttpClientContext.create();
    httpContext.setCredentialsProvider(credentialsProvider);
    httpContext.setAuthCache(authCache);
    logger.info("HttpContext filled with Auth cache.");

    return HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(cm)
            .build();
}
 
开发者ID:egetman,项目名称:ibm-bpm-rest-client,代码行数:26,代码来源:SimpleBpmClient.java

示例14: withAuthentication

import org.apache.http.client.AuthCache; //导入依赖的package包/类
@Override
public RestConfiguration withAuthentication(String user, String password) {
  // Create AuthCache instance
  AuthCache authCache = new BasicAuthCache();
  // Generate BASIC scheme object and add it to the local auth cache
  BasicScheme basicAuth = new BasicScheme();
  CredentialsProvider provider = new BasicCredentialsProvider();

  URI uri = request.getURI();
  authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth);
  provider.setCredentials(new AuthScope(uri.getHost(), AuthScope.ANY_PORT),
      new UsernamePasswordCredentials(user, password));

  this.context.setCredentialsProvider(provider);
  this.context.setAuthCache(authCache);

  return this;
}
 
开发者ID:devnull-tools,项目名称:boteco,代码行数:19,代码来源:DefaultRestConfiguration.java

示例15: getRequestContext

import org.apache.http.client.AuthCache; //导入依赖的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


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