|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2013, 2025 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials are made available under the
|
5 | 5 | * terms of the Eclipse Public License v. 2.0, which is available at
|
|
17 | 17 | package org.glassfish.jersey.client.authentication;
|
18 | 18 |
|
19 | 19 | import java.util.Base64;
|
| 20 | +import java.util.List; |
20 | 21 | import java.util.Locale;
|
21 |
| -import java.util.logging.Level; |
22 | 22 | import java.util.logging.Logger;
|
23 | 23 |
|
24 | 24 | import javax.ws.rs.client.ClientRequestContext;
|
@@ -96,20 +96,22 @@ public void filterRequest(ClientRequestContext request) {
|
96 | 96 | * @throws ResponseAuthenticationException in case that basic credentials missing or are in invalid format
|
97 | 97 | */
|
98 | 98 | public boolean filterResponseAndAuthenticate(ClientRequestContext request, ClientResponseContext response) {
|
99 |
| - final String authenticate = response.getHeaders().getFirst(HttpHeaders.WWW_AUTHENTICATE); |
100 |
| - if (authenticate != null && authenticate.trim().toUpperCase(Locale.ROOT).startsWith("BASIC")) { |
101 |
| - HttpAuthenticationFilter.Credentials credentials = HttpAuthenticationFilter |
102 |
| - .getCredentials(request, defaultCredentials, HttpAuthenticationFilter.Type.BASIC); |
103 |
| - |
104 |
| - if (credentials == null) { |
105 |
| - if (response.hasEntity()) { |
106 |
| - AuthenticationUtil.discardInputAndClose(response.getEntityStream()); |
107 |
| - } |
108 |
| - throw new ResponseAuthenticationException(null, LocalizationMessages.AUTHENTICATION_CREDENTIALS_MISSING_BASIC()); |
109 |
| - } |
| 99 | + final List<String> authHeaders = response.getHeaders().get(HttpHeaders.WWW_AUTHENTICATE); |
| 100 | + if (authHeaders == null || authHeaders.size() == 0 || authHeaders.stream() |
| 101 | + .noneMatch(h -> h != null && h.toUpperCase(Locale.ROOT).startsWith("BASIC"))) { |
| 102 | + return false; |
| 103 | + } |
| 104 | + |
| 105 | + HttpAuthenticationFilter.Credentials credentials = HttpAuthenticationFilter |
| 106 | + .getCredentials(request, defaultCredentials, HttpAuthenticationFilter.Type.BASIC); |
110 | 107 |
|
111 |
| - return HttpAuthenticationFilter.repeatRequest(request, response, calculateAuthentication(credentials)); |
| 108 | + if (credentials == null) { |
| 109 | + if (response.hasEntity()) { |
| 110 | + AuthenticationUtil.discardInputAndClose(response.getEntityStream()); |
| 111 | + } |
| 112 | + throw new ResponseAuthenticationException(null, LocalizationMessages.AUTHENTICATION_CREDENTIALS_MISSING_BASIC()); |
112 | 113 | }
|
113 |
| - return false; |
| 114 | + |
| 115 | + return HttpAuthenticationFilter.repeatRequest(request, response, calculateAuthentication(credentials)); |
114 | 116 | }
|
115 | 117 | }
|
0 commit comments