org.apache.http.impl.auth.DigestScheme Java Examples

The following examples show how to use org.apache.http.impl.auth.DigestScheme. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebAuthentication.java    From fess with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: HttpComponentsClientHttpRequestFactoryDigestAuth.java    From tutorials with MIT License 6 votes vote down vote up
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;
}
 
Example #3
Source File: HTTPClient.java    From gocd-build-status-notifier with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: DigestAuthHandler.java    From restfiddle with Apache License 2.0 5 votes vote down vote up
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;
   }
 
Example #5
Source File: TestWebServicesFetcher.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@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();
  }
}