Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 4451b36

Browse files
author
Petr Janouch
committed
JERSEY-2428: SslContext and HostVerifier not passed on nonPreemptive auth
Change-Id: Idffc4ce26044a657b482d49e8d5c00a5b6288b6e
1 parent e307513 commit 4451b36

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

core-client/src/main/java/org/glassfish/jersey/client/authentication/HttpAuthenticationFeature.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
* then the request is repeated with authentication information. This mode has negative impact on the performance.
5858
* The advantage is that it does not send credentials when they are not needed. This mode must
5959
* be combined with usage of SSL/TLS as the password is send only BASE64 encoded.
60+
* <p/>
61+
* Please note that when you use non-preemptive authentication, Jersey client will make 2 requests to a resource,
62+
* which also means that all registered filters will be invoked twice.
6063
* </li>
6164
* <li><b>DIGEST:</b> Http digest authentication. Does not require usage of SSL/TLS.</li>
6265
* <li><b>UNIVERSAL:</b> Combination of basic and digest authentication. The feature works in non-preemptive

core-client/src/main/java/org/glassfish/jersey/client/authentication/HttpAuthenticationFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ private void updateCache(ClientRequestContext request, boolean success, Type ope
294294
* {@code false} otherwise).
295295
*/
296296
static boolean repeatRequest(ClientRequestContext request, ClientResponseContext response, String newAuthorizationHeader) {
297-
Client client = ClientBuilder.newClient(request.getConfiguration());
297+
Client client = request.getClient();
298+
298299
String method = request.getMethod();
299300
MediaType mediaType = request.getMediaType();
300301
URI lUri = request.getUri();

tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/client/connector/ssl/SslConnectorConfigurationTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,31 @@ public void testSSLAuth1() throws Exception {
141141

142142
assertTrue(caught);
143143
}
144+
145+
/**
146+
* Test that a response to an authentication challenge has the same SSL configuration as the original request.
147+
*/
148+
@Test
149+
public void testSSLWithNonPreemptiveAuth() throws Exception {
150+
final SSLContext sslContext = getSslContext();
151+
152+
final ClientConfig cc = new ClientConfig().connectorProvider(connectorProvider);
153+
final Client client = ClientBuilder.newBuilder()
154+
.withConfig(cc)
155+
.sslContext(sslContext)
156+
.build();
157+
158+
// client basic auth demonstration
159+
HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basicBuilder()
160+
.nonPreemptive()
161+
.credentials("user", "password")
162+
.build();
163+
164+
client.register(authFeature);
165+
final WebTarget target = client.target(Server.BASE_URI).register(new LoggingFilter());
166+
167+
final Response response = target.path("/").request().get(Response.class);
168+
169+
assertEquals(200, response.getStatus());
170+
}
144171
}

0 commit comments

Comments
 (0)