Commit c56341e
committed
Introduce AuthToken rotation and session auth support
This update brings support for `AuthToken` rotation (refresh) by replacing existing token with a new token during driver's lifetime.
The main objective of this feature is to allow token rotation for the same identity. Therefore, the rotation support is not intended for a change of identity.
A new type called `AuthTokenManager` has the following 2 primary responsibilities:
- supplying a valid token, which may be one of the following:
- the current token
- a new token, which instructs the driver to use the new token
- handling a token expired failure that originates from the server if it determines the current token to be expired (a timely rotation should generally reduce the likelihood of this happening)
The driver does not make judgements on whether `AuthToken` should be updated. Instead, it calls `AuthTokenManager` to check if the provided token is the same as the previously used token and takes action if not. The driver reserves the right to call the token manager as often as it deems necessary. The manager implementation must be thread-safe and non-blocking for for caller threads. For instance, IO operations must not be done on the calling thread.
The `GraphDatabase` class has been updated to include a set of new methods that accept `AuthTokenManager` instance. A sample of the driver instantiation is shown below:
```java
var manager = /* the manager implementation */
var driver = GraphDatabase.driver(uri, manager);
```
The token rotation benefits from [Bolt 5.1](#bolt-51-support), but works on previous Bolt versions at the expence of replacing existing connections with new connections.
A temporal `AuthTokenManager` implementation is available in a new `AuthTokenManagers` factory. It manages `AuthToken` instances that come with a UTC expiration timestamp and calls a new token supplier, which is provided by the user, when a new token is required.
The temporal manager instantiation example:
```java
import org.neo4j.driver.AuthTokenManagers.TemporalAuthData;
var manager = AuthTokenManagers.temporal(() -> {
var token = // get new token logic
return TemporalAuthData.of(token, timestamp);
});
```
This update includes Bolt 5.1 support. The new `LOGOFF` and `LOGON` messages allow for token management on active Bolt connections.
In addition to the token rotation support, this update also includes support for setting a static `AuthToken` instance on the driver session level.
Unlike the rotation feature, this feature may be used for identity change. As such, it might be referred to as user switching.
It requires a minimum Bolt 5.1 version.
The `Driver` interface has 2 new `session` methods that accept an `AuthToken` instance.
Sample usage:
```java
var token = AuthTokens.bearer("token");
var session = driver.session(Session.class, token);
```
The `Driver` includes a new method that checks session auth is supported.
Sample usage:
```java
var supports = driver.supportsSessionAuth();
```
The `Driver` includes a new method that verifies a given `AuthToken` instance by communicating with the server.
It requires a minimum Bolt 5.1 version.
Sample usage:
```java
var token = AuthTokens.bearer("token");
var successful = driver.verifyAuthentication(token);
```
There are 3 new exceptions:
- `AuthTokenManagerExecutionException` - Indicates that `AuthTokenManager` execution has lead to an unexpected result. This includes invalid results and errors.
- `UnsupportedFeatureException` - Indicates that a given feature is not supported in a particular setup. For instance, session auth feature is not supported on Bolt versions below 5.1.
- `TokenExpiredRetryableException` - Indicates that the token supplied by the `AuthTokenManager` has been deemed as expired by the server. This is a retryable variant of the `TokenExpiredException` used when the driver has an explicit `AuthTokenManager` that might supply a new token following this failure. If driver is instantiated with the static `AuthToken`, the `TokenExpiredException` will be used instead.1 parent c7b1987 commit c56341e
File tree
139 files changed
+5755
-413
lines changed- driver
- src
- main/java/org/neo4j/driver
- exceptions
- internal
- async
- connection
- inbound
- pool
- cluster
- loadbalancing
- handlers
- messaging
- encode
- request
- v3
- v51
- security
- spi
- util
- test/java/org/neo4j/driver
- integration
- internal
- async
- connection
- inbound
- pool
- cluster
- loadbalancing
- handlers
- messaging
- v3
- v41
- v42
- v43
- v44
- v4
- v51
- v5
- security
- util
- io
- stress
- testutil
- cc
- testkit-backend/src/main/java/neo4j/org/testkit/backend
- messages
- requests
- responses
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
139 files changed
+5755
-413
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
436 | 460 | | |
Lines changed: 62 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
Lines changed: 113 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
147 | 183 | | |
148 | 184 | | |
149 | 185 | | |
| |||
172 | 208 | | |
173 | 209 | | |
174 | 210 | | |
175 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
176 | 250 | | |
177 | 251 | | |
178 | 252 | | |
| |||
325 | 399 | | |
326 | 400 | | |
327 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
328 | 420 | | |
329 | 421 | | |
330 | 422 | | |
| |||
0 commit comments