Commit 6aaaa90
committed
Do not reuse the same refresh token multiple times
- The "add a UAA token to HTTP request headers" flow works like this:
- User makes a request using AbstractReactorOperations -> Operator
- This adds an "Authorization" header, using Provider#getToken mono ;
if a value is cached it uses that, otherwise it uses whatever flow
is available to request a token.
- If the response is unauthorized, it means the access token is
expired, and the Operator calls Provider#invalidate ; and then
retries the request, which will trigger another #getToken call.
- There was a race condition, when an access_token was cached and
multiple request used it concurrently, they would all call
AbstractUaaTokenProvider#invalidate, and all reuse the same refresh
token. This is an issue when the UAA is configured with non-reusable
refresh tokens (revocable + rotating or unique), only the first
refresh token request succeeds, and all other refresh token requests
fail.
- This PR addresses this by ensuring that the cached refresh token is
removed from the cache right before being used. Any other call to
#invalidate will be a no-op.
- This is NOT a perfect fix, and there are some smaller scale race
conditions happening. For example, #invalidate calls
refreshTokens.remove and accessTokens.put sequentially. It is possible
that a concurrent request calls invalidate, finds the refreshTokens
cache empty, and then will populate accessTokens through #getToken ;
in that case there could be a race condition and two tokens fetched.
- Re-architecting the whole token logic is too big of a lift for the
project, so we accept that this solution is not perfect - as long as
the issues are recoverable.
- Fixes #1146
Signed-off-by: Daniel Garnier-Moiroux <[email protected]>1 parent 5fac7cf commit 6aaaa90
File tree
1 file changed
+38
-26
lines changed- cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/tokenprovider
1 file changed
+38
-26
lines changedLines changed: 38 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
120 | 123 | | |
121 | 124 | | |
122 | 125 | | |
| |||
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
136 | 163 | | |
137 | 164 | | |
138 | 165 | | |
| |||
227 | 254 | | |
228 | 255 | | |
229 | 256 | | |
230 | | - | |
231 | | - | |
| 257 | + | |
232 | 258 | | |
233 | 259 | | |
234 | 260 | | |
| |||
297 | 323 | | |
298 | 324 | | |
299 | 325 | | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
320 | 332 | | |
321 | 333 | | |
322 | | - | |
323 | | - | |
| 334 | + | |
| 335 | + | |
324 | 336 | | |
325 | 337 | | |
326 | 338 | | |
| |||
0 commit comments