简体   繁体   中英

securing rest web service with digest authentication java

I'm developing a rest client, with apache httpclient 4.3.3, which supports HTTP Basic and Digest authentication. I need an example of rest webservice with digest authentication to test my client. Can anyone help me, even an online rest web service could be very appreciated.

this is the client code for digest authentication:

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);

after that, I can call:

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();

I need to cosume a rest web service with digest authentication to test my client.

I have begun with this web service:

@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;

thank you for any help you can provide

我终于找到了一个很好的示例spring-security-rest-digest-auth和spring security,它可能对某些人有帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM