【问题标题】:securing rest web service with digest authentication java使用摘要身份验证 java 保护 REST Web 服务
【发布时间】:2014-05-06 16:01:47
【问题描述】:

我正在使用 apache httpclient 4.3.3 开发一个 rest 客户端,它支持 HTTP Basic 和 Digest 身份验证。 我需要一个带有摘要身份验证的 REST Web 服务示例来测试我的客户端。任何人都可以帮助我,即使是在线 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();

我需要使用带有摘要身份验证的 REST 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;

感谢您提供的任何帮助

【问题讨论】:

  • 您能否提供更多详细信息。
  • 如..有什么问题?没有问题。
  • 我需要一个带有摘要身份验证的 REST Web 服务示例来测试我的客户端。甚至欢迎在线网络服务。

标签: java rest authentication digest


【解决方案1】:

我终于找到了一个很好的例子spring-security-rest-digest-auth,它可能对你们中的一些人有所帮助。

【讨论】:

    猜你喜欢
    • 2012-02-19
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2013-11-12
    • 2013-01-31
    • 2010-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多