Skip to content

Commit

Permalink
Merge "JERSEY-2428: SslContext and HostVerifier not passed on nonPree…
Browse files Browse the repository at this point in the history
…mptive auth"
  • Loading branch information
pavelbucek authored and Gerrit Code Review committed Dec 15, 2015
2 parents 326b74b + 4451b36 commit 3ba648c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
* then the request is repeated with authentication information. This mode has negative impact on the performance.
* The advantage is that it does not send credentials when they are not needed. This mode must
* be combined with usage of SSL/TLS as the password is send only BASE64 encoded.
* <p/>
* Please note that when you use non-preemptive authentication, Jersey client will make 2 requests to a resource,
* which also means that all registered filters will be invoked twice.
* </li>
* <li><b>DIGEST:</b> Http digest authentication. Does not require usage of SSL/TLS.</li>
* <li><b>UNIVERSAL:</b> Combination of basic and digest authentication. The feature works in non-preemptive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ private void updateCache(ClientRequestContext request, boolean success, Type ope
* {@code false} otherwise).
*/
static boolean repeatRequest(ClientRequestContext request, ClientResponseContext response, String newAuthorizationHeader) {
Client client = ClientBuilder.newClient(request.getConfiguration());
Client client = request.getClient();

String method = request.getMethod();
MediaType mediaType = request.getMediaType();
URI lUri = request.getUri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,31 @@ public void testSSLAuth1() throws Exception {

assertTrue(caught);
}

/**
* Test that a response to an authentication challenge has the same SSL configuration as the original request.
*/
@Test
public void testSSLWithNonPreemptiveAuth() throws Exception {
final SSLContext sslContext = getSslContext();

final ClientConfig cc = new ClientConfig().connectorProvider(connectorProvider);
final Client client = ClientBuilder.newBuilder()
.withConfig(cc)
.sslContext(sslContext)
.build();

// client basic auth demonstration
HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basicBuilder()
.nonPreemptive()
.credentials("user", "password")
.build();

client.register(authFeature);
final WebTarget target = client.target(Server.BASE_URI).register(new LoggingFilter());

final Response response = target.path("/").request().get(Response.class);

assertEquals(200, response.getStatus());
}
}

0 comments on commit 3ba648c

Please sign in to comment.