111 * Authenticator for a particular realm is single threaded. |
111 * Authenticator for a particular realm is single threaded. |
112 * ie. if multiple threads need to get credentials from the user |
112 * ie. if multiple threads need to get credentials from the user |
113 * at the same time, then all but the first will block until |
113 * at the same time, then all but the first will block until |
114 * the first completes its authentication. |
114 * the first completes its authentication. |
115 */ |
115 */ |
116 static private HashMap<String,Thread> requests = new HashMap<>(); |
116 private static HashMap<String,Thread> requests = new HashMap<>(); |
117 |
117 |
118 /* check if a request for this destination is in progress |
118 /* check if a request for this destination is in progress |
119 * return false immediately if not. Otherwise block until |
119 * return false immediately if not. Otherwise block until |
120 * request is finished and return true |
120 * request is finished and return true |
121 */ |
121 */ |
122 static private boolean requestIsInProgress (String key) { |
122 private static boolean requestIsInProgress (String key) { |
123 if (!serializeAuth) { |
123 if (!serializeAuth) { |
124 /* behavior is disabled. Revert to concurrent requests */ |
124 /* behavior is disabled. Revert to concurrent requests */ |
125 return false; |
125 return false; |
126 } |
126 } |
127 synchronized (requests) { |
127 synchronized (requests) { |
145 } |
145 } |
146 |
146 |
147 /* signal completion of an authentication (whether it succeeded or not) |
147 /* signal completion of an authentication (whether it succeeded or not) |
148 * so that other threads can continue. |
148 * so that other threads can continue. |
149 */ |
149 */ |
150 static private void requestCompleted (String key) { |
150 private static void requestCompleted (String key) { |
151 synchronized (requests) { |
151 synchronized (requests) { |
152 Thread thread = requests.get(key); |
152 Thread thread = requests.get(key); |
153 if (thread != null && thread == Thread.currentThread()) { |
153 if (thread != null && thread == Thread.currentThread()) { |
154 boolean waspresent = requests.remove(key) != null; |
154 boolean waspresent = requests.remove(key) != null; |
155 assert waspresent; |
155 assert waspresent; |