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

Commit a4ece0c

Browse files
author
alessandro.gherardi
committed
Rolled back 2nd change
1 parent 24b3490 commit a4ece0c

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

connectors/apache-connector/src/test/java/org/glassfish/jersey/apache/connector/AuthTest.java

-32
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,6 @@ public String getDigest(@Context HttpHeaders h) {
182182
return "GET";
183183
}
184184

185-
@GET
186-
@Path("basicAndDigest")
187-
public String getBasicAndDigest(@Context HttpHeaders h) {
188-
String value = h.getRequestHeaders().getFirst("Authorization");
189-
if (value == null) {
190-
throw new WebApplicationException(
191-
Response.status(401).header("WWW-Authenticate", "Basic realm=\"WallyWorld\"")
192-
.header("WWW-Authenticate", "Digest realm=\"WallyWorld\"")
193-
.entity("Forbidden").build());
194-
} else if (value.startsWith("Basic")) {
195-
throw new WebApplicationException(
196-
Response.status(401).header("WWW-Authenticate", "Basic realm=\"WallyWorld\"")
197-
.header("WWW-Authenticate", "Digest realm=\"WallyWorld\"")
198-
.entity("Digest authentication expected").build());
199-
}
200-
201-
return "GET";
202-
}
203-
204185
@POST
205186
public String post(@Context HttpHeaders h, String e) {
206187
requestCount++;
@@ -310,19 +291,6 @@ public void testAuthGetWithDigestFilter() {
310291
assertEquals(cm.getTotalStats().getLeased(), 0);
311292
}
312293

313-
@Test
314-
public void testAuthGetWithBasicAndDigestFilter() {
315-
ClientConfig cc = new ClientConfig();
316-
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
317-
cc.connectorProvider(new ApacheConnectorProvider());
318-
cc.property(ApacheClientProperties.CONNECTION_MANAGER, cm);
319-
Client client = ClientBuilder.newClient(cc);
320-
client.register(HttpAuthenticationFeature.universal("name", "password"));
321-
WebTarget r = client.target(getBaseUri()).path("test/basicAndDigest");
322-
323-
assertEquals("GET", r.request().get(String.class));
324-
}
325-
326294
@Test
327295
@Ignore("JERSEY-1750: Cannot retry request with a non-repeatable request entity. How to buffer the entity?"
328296
+ " Allow repeatable write in jersey?")

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

+8-14
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,15 @@ public void filter(ClientRequestContext request, ClientResponseContext response)
220220
Type result = null; // which authentication is requested: BASIC or DIGEST
221221
boolean authenticate;
222222

223-
// If the server requests both BASIC and DIGEST, prefer DIGEST since it's stronger
224-
// (see https://tools.ietf.org/html/rfc2617#section-4.6)
225223
if (response.getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
226-
List<String> authStrings = response.getHeaders().get(HttpHeaders.WWW_AUTHENTICATE);
227-
if (authStrings != null) {
228-
for (String authString : authStrings) {
229-
final String upperCaseAuth = authString.trim().toUpperCase();
230-
if (result == null && upperCaseAuth.startsWith("BASIC")) {
231-
result = Type.BASIC;
232-
} else if (upperCaseAuth.startsWith("DIGEST")) {
233-
result = Type.DIGEST;
234-
}
235-
}
236-
237-
if (result == null) {
224+
String authString = response.getHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE);
225+
if (authString != null) {
226+
final String upperCaseAuth = authString.trim().toUpperCase();
227+
if (upperCaseAuth.startsWith("BASIC")) {
228+
result = Type.BASIC;
229+
} else if (upperCaseAuth.startsWith("DIGEST")) {
230+
result = Type.DIGEST;
231+
} else {
238232
// unknown authentication -> this filter cannot authenticate with this method
239233
return;
240234
}

0 commit comments

Comments
 (0)