使用摘要身份验证java保护rest web服务

使用摘要身份验证java保护rest web服务,java,rest,authentication,digest,Java,Rest,Authentication,Digest,我正在用ApacheHttpClient 4.3.3开发一个rest客户端,它支持HTTP基本和摘要身份验证。我需要一个带有摘要身份验证的RESTWebService示例来测试我的客户端。任何人都可以帮助我,即使是在线rest web服务也会非常感激 这是摘要身份验证的客户端代码: final HttpHost targetHost = new HttpHost("localhost", 8080, "http"); final CredentialsProvider credsProv

我正在用ApacheHttpClient 4.3.3开发一个rest客户端,它支持HTTP基本和摘要身份验证。我需要一个带有摘要身份验证的RESTWebService示例来测试我的客户端。任何人都可以帮助我,即使是在线rest web服务也会非常感激

这是摘要身份验证的客户端代码:

final HttpHost targetHost = new HttpHost("localhost", 8080, "http");
    final CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(user, password));

    // Create AuthCache instance
    final AuthCache authCache = new BasicAuthCache();
    // Generate DIGEST scheme object and add it to the local auth cache
    DigestScheme digestAuth = new DigestScheme();
    // Suppose we already know the realm name
    digestAuth.overrideParamter("realm", "some-realm");
    // Suppose we already know the expected nonce value
    digestAuth.overrideParamter("nonce", "some-nonce");
    authCache.put(targetHost, digestAuth);

    // Add AuthCache to the execution context
    HttpClientContext context = HttpClientContext.create();
    context.setAuthCache(authCache);
之后,我可以打电话:

RestClient genericRestClient = new GenericRestClient.Builder(METHOD_URL)
            .setUser(DEFAULT_USER).setPassword(DEFAULT_PASS)
            .setAuthType(AuthenticationType.DIGEST_AUTH)
            .setHttpVersion(HTTPVersion.HTTP_1_1).build();
    genericRestClient.doGet();
我需要使用RESTWeb服务和摘要身份验证来测试我的客户机

我从以下web服务开始:

@GET
@Path("/get")
@Produces("application/json")
public Product getProduct(@Context HttpHeaders headers) {
    .....

    Product product = new Product();
    product.setName("Product 1");
    product.setQty(50);

    return product;

感谢您提供的任何帮助

我终于找到了一个关于spring security的好例子,可以帮助你们中的一些人。

您能提供更多详细信息吗。例如。。有什么问题吗?毫无疑问,我需要一个带有摘要身份验证的RESTWebService示例来测试我的客户端。甚至在线web服务也受欢迎。