类org.apache.http.impl.auth.DigestScheme源码实例Demo

下面列出了怎么用org.apache.http.impl.auth.DigestScheme的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: fess   文件: WebAuthentication.java
private AuthScheme getAuthScheme() {
    final String scheme = getProtocolScheme();
    if (Constants.BASIC.equals(scheme)) {
        return new BasicScheme();
    } else if (Constants.DIGEST.equals(scheme)) {
        return new DigestScheme();
    } else if (Constants.NTLM.equals(scheme)) {
        final Properties props = new Properties();
        getWebConfig().getConfigParameterMap(ConfigName.CONFIG).entrySet().stream()
                .filter(e -> e.getKey().startsWith(Config.JCIFS_PREFIX)).forEach(e -> {
                    props.setProperty(e.getKey(), e.getValue());
                });
        return new NTLMScheme(new JcifsEngine(props));
    } else if (Constants.FORM.equals(scheme)) {
        final Map<String, String> parameterMap = ParameterUtil.parse(getParameters());
        return new FormScheme(parameterMap);
    }
    return null;
}
 
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;
}
 
源代码3 项目: gocd-build-status-notifier   文件: HTTPClient.java
private AuthCache getAuthCache(AuthenticationType authenticationType, HttpHost target) {
    AuthCache authCache = new BasicAuthCache();
    if (authenticationType == AuthenticationType.BASIC) {
        authCache.put(target, new BasicScheme());
    } else {
        authCache.put(target, new DigestScheme());
    }
    return authCache;
}
 
源代码4 项目: restfiddle   文件: DigestAuthHandler.java
public HttpClientContext preemptive() {
AuthCache authCache = new BasicAuthCache();

DigestScheme digestAuth = new DigestScheme();

digestAuth.overrideParamter("realm", "");
digestAuth.overrideParamter("nonce", "");

// TODO : Add target
// authCache.put(target, digestAuth);
HttpClientContext localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);

return localContext;
   }
 
源代码5 项目: datacollector   文件: TestWebServicesFetcher.java
@Test
public void testInitializationCustomNoSslDigestAuth() throws Exception {
  Properties props = new Properties();
  props.setProperty(WebServicesFetcher.URL_KEY, "http://foo");
  props.setProperty(WebServicesFetcher.APP_ID_KEY, "appId");
  props.setProperty(WebServicesFetcher.KEYSTORE_FILE_KEY, "");
  props.setProperty(WebServicesFetcher.KEYSTORE_PASSWORD_KEY, "");
  props.setProperty(WebServicesFetcher.KEY_PASSWORD_KEY, "");
  props.setProperty(WebServicesFetcher.TRUSTSTORE_FILE_KEY, "");
  props.setProperty(WebServicesFetcher.TRUSTSTORE_PASSWORD_KEY, "");
  props.setProperty(WebServicesFetcher.SUPPORTED_PROTOCOLS_KEY, "");
  props.setProperty(WebServicesFetcher.HOSTNAME_VERIFIER_SKIP_KEY, "");
  props.setProperty(WebServicesFetcher.MAX_CONCURRENT_CONNECTIONS_KEY, "1");
  props.setProperty(WebServicesFetcher.VALIDATE_AFTER_INACTIVITY_KEY, "2");
  props.setProperty(WebServicesFetcher.CONNECTION_TIMEOUT_KEY, "5000");
  props.setProperty(WebServicesFetcher.NAME_SEPARATOR_KEY, "+");
  props.setProperty(WebServicesFetcher.HTTP_AUTH_TYPE_KEY, "digest");
  props.setProperty(WebServicesFetcher.HTTP_AUTH_USER_KEY, "user");
  props.setProperty(WebServicesFetcher.HTTP_AUTH_PASSWORD_KEY, "password");
  Configuration conf = createConfig(props);

  WebServicesFetcher fetcher = new WebServicesFetcher();
  try {
    fetcher.init(conf);
    Assert.assertNotNull(fetcher.getConfig());

    Assert.assertEquals("http://foo", fetcher.getUrl());
    Assert.assertEquals("appId", fetcher.getAppId());
    Assert.assertEquals(5000, fetcher.getConnectionTimeout());
    Assert.assertEquals("+", fetcher.getSeparator());
    Assert.assertEquals("digest", fetcher.getHttpAuth());
    Assert.assertEquals("user", fetcher.getHttpAuthUser());
    Assert.assertEquals("password", fetcher.getHttpAuthPassword());
    Assert.assertNotNull(fetcher.getCredentialsProvider());
    Assert.assertEquals("user",
        fetcher.getCredentialsProvider().getCredentials(AuthScope.ANY).getUserPrincipal().getName()
    );
    Assert.assertEquals("password", fetcher.getCredentialsProvider().getCredentials(AuthScope.ANY).getPassword());
    Assert.assertTrue(fetcher.getAuthCache().get(new HttpHost(fetcher.getUrl())) instanceof DigestScheme);

    PoolingHttpClientConnectionManager connectionManager = fetcher.getConnectionManager();
    Assert.assertEquals(1, connectionManager.getMaxTotal());
    Assert.assertEquals(1, connectionManager.getDefaultMaxPerRoute());
    Assert.assertEquals(2, connectionManager.getValidateAfterInactivity());

    Assert.assertNull(fetcher.getSslConnectionSocketFactory());
  } finally {
    fetcher.destroy();
  }
}
 
 类所在包
 同包方法