|
28 | 28 | */
|
29 | 29 | package com.sun.identity.authentication.client;
|
30 | 30 |
|
| 31 | +import static java.util.Arrays.asList; |
| 32 | + |
31 | 33 | import com.iplanet.am.util.AMClientDetector;
|
32 | 34 | import com.iplanet.am.util.SystemProperties;
|
33 | 35 | import com.iplanet.dpro.session.SessionException;
|
|
91 | 93 | import java.net.URLDecoder;
|
92 | 94 | import java.security.AccessController;
|
93 | 95 | import java.util.ArrayList;
|
94 |
| -import java.util.Arrays; |
95 | 96 | import java.util.Collections;
|
96 | 97 | import java.util.Enumeration;
|
97 | 98 | import java.util.HashMap;
|
|
100 | 101 | import java.util.Iterator;
|
101 | 102 | import java.util.List;
|
102 | 103 | import java.util.Map;
|
| 104 | +import java.util.Objects; |
103 | 105 | import java.util.ResourceBundle;
|
104 | 106 | import java.util.Set;
|
105 | 107 | import java.util.StringTokenizer;
|
@@ -333,7 +335,7 @@ protected AuthClientUtils() {
|
333 | 335 | private static List<String> getHeaderNameListForProperty(String property) {
|
334 | 336 | String value = SystemProperties.get(property);
|
335 | 337 | if (value != null) {
|
336 |
| - return Arrays.asList(value.toLowerCase().split(",")); |
| 338 | + return asList(value.toLowerCase().split(",")); |
337 | 339 | }
|
338 | 340 | return Collections.EMPTY_LIST;
|
339 | 341 | }
|
@@ -2529,8 +2531,9 @@ public static Map<String, Object> sendAuthRequestToOrigServer(HttpServletRequest
|
2529 | 2531 | // If we don't do this the server might going to deny the request because of invalid domain access.
|
2530 | 2532 | conn.setRequestProperty("Host", request.getHeader("host"));
|
2531 | 2533 |
|
| 2534 | + List<Cookie> cookies = removeLocalLoadBalancingCookie(asList(request.getCookies())); |
2532 | 2535 | // replay cookies
|
2533 |
| - strCookies = getCookiesString(request); |
| 2536 | + strCookies = getCookiesString(cookies); |
2534 | 2537 | if (strCookies != null) {
|
2535 | 2538 | if (utilDebug.messageEnabled()) {
|
2536 | 2539 | utilDebug.message("Sending cookies : " + strCookies);
|
@@ -2573,7 +2576,7 @@ public static Map<String, Object> sendAuthRequestToOrigServer(HttpServletRequest
|
2573 | 2576 | if (queryParams.containsKey(entry.getKey())) {
|
2574 | 2577 | // TODO: do we need to care about params that can be both in GET and POST?
|
2575 | 2578 | } else {
|
2576 |
| - postParams.put(entry.getKey(), new HashSet<String>(Arrays.asList(entry.getValue()))); |
| 2579 | + postParams.put(entry.getKey(), new HashSet<String>(asList(entry.getValue()))); |
2577 | 2580 | }
|
2578 | 2581 | }
|
2579 | 2582 |
|
@@ -2677,6 +2680,22 @@ public static Map<String, Object> sendAuthRequestToOrigServer(HttpServletRequest
|
2677 | 2680 | return origRequestData;
|
2678 | 2681 | }
|
2679 | 2682 |
|
| 2683 | + /** |
| 2684 | + * Filter the load balancing cookie if it points to this server to avoid potential infinite redirect loop. |
| 2685 | + */ |
| 2686 | + private static List<Cookie> removeLocalLoadBalancingCookie(final List<Cookie> cookies) { |
| 2687 | + final String lblCookieName = getlbCookieName(); |
| 2688 | + final String lblCookieValue = getlbCookieValue(); |
| 2689 | + final List<Cookie> filteredCookies = new ArrayList<>(); |
| 2690 | + for (final Cookie cookie : cookies) { |
| 2691 | + if (!Objects.equals(cookie.getName(), lblCookieName) |
| 2692 | + && !Objects.equals(cookie.getValue(), lblCookieValue)) { |
| 2693 | + filteredCookies.add(cookie); |
| 2694 | + } |
| 2695 | + } |
| 2696 | + return filteredCookies; |
| 2697 | + } |
| 2698 | + |
2680 | 2699 | private static boolean isSameServer(URL url1, URL url2) {
|
2681 | 2700 | int port1 = url1.getPort() != -1 ? url1.getPort() : url1.getDefaultPort();
|
2682 | 2701 | int port2 = url2.getPort() != -1 ? url2.getPort() : url2.getDefaultPort();
|
@@ -2736,25 +2755,21 @@ private static String getFormData(Map<String, Set<String>> params) {
|
2736 | 2755 | }
|
2737 | 2756 |
|
2738 | 2757 | // Get cookies string from HTTP request object
|
2739 |
| - private static String getCookiesString(HttpServletRequest request) { |
2740 |
| - Cookie cookies[] = request.getCookies(); |
| 2758 | + private static String getCookiesString(List<Cookie> cookies) { |
2741 | 2759 | StringBuilder cookieStr = null;
|
2742 | 2760 | String strCookies = null;
|
2743 | 2761 | // Process Cookies
|
2744 | 2762 | if (cookies != null) {
|
2745 |
| - for (int nCookie = 0; nCookie < cookies.length; nCookie++) { |
| 2763 | + for (final Cookie cookie : cookies) { |
2746 | 2764 | if (utilDebug.messageEnabled()) {
|
2747 |
| - utilDebug.message("Cookie name='{}', value='{}'", |
2748 |
| - cookies[nCookie].getName(), cookies[nCookie].getValue()); |
| 2765 | + utilDebug.message("Cookie name='{}', value='{}'", cookie.getName(), cookie.getValue()); |
2749 | 2766 | }
|
2750 | 2767 | if (cookieStr == null) {
|
2751 | 2768 | cookieStr = new StringBuilder();
|
2752 | 2769 | } else {
|
2753 | 2770 | cookieStr.append(";");
|
2754 | 2771 | }
|
2755 |
| - cookieStr.append(cookies[nCookie].getName()) |
2756 |
| - .append("=") |
2757 |
| - .append(cookies[nCookie].getValue()); |
| 2772 | + cookieStr.append(cookie.getName()).append("=").append(cookie.getValue()); |
2758 | 2773 | }
|
2759 | 2774 | }
|
2760 | 2775 | if (cookieStr != null) {
|
|
0 commit comments