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


Java DigestScheme类代码示例

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


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

示例1: checkLocalContext

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

示例2: checkLocalContext

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

示例3: init

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
public void init() throws ClientProtocolException, IOException, JAXBException {
    if (user != null && pwd != null) {
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(user, pwd));
        AuthCache authCache = new BasicAuthCache();
        DigestScheme digestScheme = new DigestScheme();
        digestScheme.overrideParamter("realm", "F!Box SOAP-Auth");
        digestScheme.overrideParamter("nonce", Long.toString(new Random().nextLong(), 36));
        digestScheme.overrideParamter("qop", "auth");
        digestScheme.overrideParamter("nc", "0");
        digestScheme.overrideParamter("cnonce", DigestScheme.createCnonce());
        authCache.put(targetHost, digestScheme);
        context.setCredentialsProvider(credsProvider);
        context.setAuthCache(authCache);
        readTR64();
    } else {
        readIGDDESC();
    }

}
 
开发者ID:mirthas,项目名称:FritzTR064,代码行数:22,代码来源:FritzConnection.java

示例4: postWithDigestAuth

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
public String postWithDigestAuth(final String url, final String file) {
    String responseBodyAsString = "";
    try (CloseableHttpResponse response =
            httpClient.execute(targetHost, httpPost(url, MultipartEntityBuilder.create().
                    addPart("bin", new FileBody(new File(file))).build()),
                    setAuth(targetHost, new DigestScheme()))) {
        responseBodyAsString = IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8"));
        handler.logOutput("Http status: " + response.getStatusLine().getStatusCode(), true);
        InstallLog.getInstance().info("Http status: " + response.getStatusLine().getStatusCode());
    } catch (IOException e) {
        final String messageError = "Error calling " + url + ": " + e.getMessage();
        handler.emitError(messageError, messageError);
        InstallLog.getInstance().error(messageError);
    }

    return responseBodyAsString;
}
 
开发者ID:apache,项目名称:syncope,代码行数:18,代码来源:HttpUtils.java

示例5: postWithStringEntity

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
public int postWithStringEntity(final String url, final String stringEntity) {
    int status = 0;
    try {
        final HttpPost httPost = httpPost(url, new StringEntity(stringEntity));
        httPost.addHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType());
        try (CloseableHttpResponse response =
                httpClient.execute(targetHost, httPost, setAuth(targetHost, new DigestScheme()))) {
            status = response.getStatusLine().getStatusCode();
            handler.logOutput("Http status: " + status, true);
            InstallLog.getInstance().info("Http status: " + status);
        }
    } catch (final IOException ioe) {
        final String messageError = "Error calling " + url + ": " + ioe.getMessage();
        handler.emitError(messageError, messageError);
        InstallLog.getInstance().error(messageError);

    }
    return status;
}
 
开发者ID:apache,项目名称:syncope,代码行数:20,代码来源:HttpUtils.java

示例6: buildBasicHttpContext

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
private void buildBasicHttpContext()
{
    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.overrideParamter("nc", String.valueOf(serverNounceCount++));
    digestScheme.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
    digestScheme.overrideParamter("qop", "auth");
    authCache.put(target, digestScheme);
    
    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:13,代码来源:RestUtils.java

示例7: buildBasicHttpContext

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
private void buildBasicHttpContext()
{
    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestScheme = new DigestScheme();
    digestScheme.overrideParamter("nc", String.valueOf(serverNounceCount++));
    digestScheme.overrideParamter("cnonce", UUID.randomUUID().toString().replaceAll("-", ""));
    digestScheme.overrideParamter("qop", "auth");
    authCache.put(target, digestScheme);

    localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:13,代码来源:RestUtils.java

示例8: process

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
public void process(
        final HttpResponse response, 
        final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(
            ClientContext.TARGET_AUTH_STATE);
    if (authState != null) {
        AuthScheme authScheme = authState.getAuthScheme();
        // Stick the auth scheme to the local context, so
        // we could try to authenticate subsequent requests
        // preemptively
        if (authScheme instanceof DigestScheme) {
            context.setAttribute("preemptive-auth", authScheme);
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:16,代码来源:ClientPreemptiveDigestAuthentication.java

示例9: testCredentialsFound

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
@Test
public void testCredentialsFound() throws Exception {
    final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
    final HttpHost authhost = new HttpHost("somehost", 80);
    final HttpClientContext context = HttpClientContext.create();

    final Map<String, Header> challenges = new HashMap<String, Header>();
    challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
    challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));

    final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register("basic", new BasicSchemeFactory())
        .register("digest", new DigestSchemeFactory()).build();
    context.setAuthSchemeRegistry(authSchemeRegistry);

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope("somehost", 80, "realm2"),
            new UsernamePasswordCredentials("user", "pwd"));
    context.setCredentialsProvider(credentialsProvider);

    final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
    Assert.assertNotNull(options);
    Assert.assertEquals(1, options.size());
    final AuthOption option = options.remove();
    Assert.assertTrue(option.getAuthScheme() instanceof DigestScheme);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:28,代码来源:TestAuthenticationStrategy.java

示例10: testUnsupportedScheme

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
@Test
public void testUnsupportedScheme() throws Exception {
    final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
    final HttpHost authhost = new HttpHost("somehost", 80);
    final HttpClientContext context = HttpClientContext.create();

    final Map<String, Header> challenges = new HashMap<String, Header>();
    challenges.put("basic", new BasicHeader(AUTH.WWW_AUTH, "Basic realm=\"realm1\""));
    challenges.put("digest", new BasicHeader(AUTH.WWW_AUTH, "Digest realm=\"realm2\", nonce=\"1234\""));
    challenges.put("whatever", new BasicHeader(AUTH.WWW_AUTH, "Whatever realm=\"realm3\""));

    final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register("basic", new BasicSchemeFactory())
        .register("digest", new DigestSchemeFactory()).build();
    context.setAuthSchemeRegistry(authSchemeRegistry);

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope("somehost", 80),
            new UsernamePasswordCredentials("user", "pwd"));
    context.setCredentialsProvider(credentialsProvider);

    final Queue<AuthOption> options = authStrategy.select(challenges, authhost, response, context);
    Assert.assertNotNull(options);
    Assert.assertEquals(2, options.size());
    final AuthOption option1 = options.remove();
    Assert.assertTrue(option1.getAuthScheme() instanceof DigestScheme);
    final AuthOption option2 = options.remove();
    Assert.assertTrue(option2.getAuthScheme() instanceof BasicScheme);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:31,代码来源:TestAuthenticationStrategy.java

示例11: getAuthCache

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
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;
}
 
开发者ID:gocd-contrib,项目名称:gocd-build-status-notifier,代码行数:10,代码来源:HTTPClient.java

示例12: invokeHTTPRequestWithAuth

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
private int invokeHTTPRequestWithAuth(HttpHost httpHost, HttpPost httpPost,
		String contentType, String acceptContentType, String userName,
		String password) throws ClientProtocolException, IOException {

	DefaultHttpClient httpClient = new DefaultHttpClient();

	if (acceptContentType != null && !acceptContentType.isEmpty()) {
		httpPost.setHeader(HTTP_HEADERS.Accept.name(), acceptContentType);
	}
	if (contentType != null && !contentType.isEmpty()) {
		httpPost.setHeader("Content-Type", contentType);
	}

	httpClient.getCredentialsProvider().setCredentials(
			new AuthScope(httpHost.getHostName(), httpHost.getPort()),
			new UsernamePasswordCredentials(userName, password));

	AuthCache authCache = new BasicAuthCache();
	DigestScheme digestScheme = new DigestScheme();

	digestScheme.overrideParamter("realm", "SPARQL"); // Virtuoso specific
	// digestScheme.overrideParamter("nonce", new Nonc);

	authCache.put(httpHost, digestScheme);

	BasicHttpContext localcontext = new BasicHttpContext();
	localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

	// Execute the request
	HttpResponse response = httpClient.execute(httpHost, httpPost,
			localcontext);

	return response.getStatusLine().getStatusCode();
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:35,代码来源:RDFGeneratorServlet.java

示例13: invokeHTTPDeleteWithAuth

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
private int invokeHTTPDeleteWithAuth(HttpHost httpHost, String url,
		String userName, String password) throws ClientProtocolException,
		IOException {
	HttpDelete httpDelete = new HttpDelete(url);

	DefaultHttpClient httpClient = new DefaultHttpClient();

	httpClient.getCredentialsProvider().setCredentials(
			new AuthScope(httpHost.getHostName(), httpHost.getPort()),
			new UsernamePasswordCredentials(userName, password));

	AuthCache authCache = new BasicAuthCache();
	DigestScheme digestScheme = new DigestScheme();

	digestScheme.overrideParamter("realm", "SPARQL"); // Virtuoso specific
	// digestScheme.overrideParamter("nonce", new Nonc);

	authCache.put(httpHost, digestScheme);

	BasicHttpContext localcontext = new BasicHttpContext();
	localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

	// Execute the request
	HttpResponse response = httpClient.execute(httpHost, httpDelete,
			localcontext);

	logger.info(Integer.toString(response.getStatusLine().getStatusCode()));

	return response.getStatusLine().getStatusCode();
}
 
开发者ID:therelaxist,项目名称:spring-usc,代码行数:31,代码来源:RDFGeneratorServlet.java

示例14: createHttpContext

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
private HttpContext createHttpContext(URI uri){
    AuthCache authCache = new BasicAuthCache();
    DigestScheme digestScheme = new DigestScheme();
    HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort());
    authCache.put(targetHost, digestScheme);
    
    BasicHttpContext localcontext = new BasicHttpContext();
    localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
    return localcontext;
}
 
开发者ID:nopbyte,项目名称:compose-idm,代码行数:11,代码来源:DigestHttpComponentsClientHttpRequestFactory.java

示例15: preemptive

import org.apache.http.impl.auth.DigestScheme; //导入依赖的package包/类
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;
   }
 
开发者ID:AnujaK,项目名称:restfiddle,代码行数:16,代码来源:DigestAuthHandler.java


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