Commit 920410f
Added Support for providing configuration option for supplying password function (#157)
Motivation:
Currently r2dbc-mysql does not support IAM based Authentication for
authenticating with AWS Aurora RDS database. The way IAM based
authentication works is requesting token from AWS RDS for that hostname
and username (which is same as AWS IAM Role name). These tokens are
valid for 15 minutes, cannot reuse same token after 15 minutes.
By adding configuration option for supplying password function, whenever
a new connection is made then password is retrieved using supplier
function each time.
Modification:
Modified `MySqlConnectionFactoryProvider` - Added new configurable
option.
`Option<Publisher<String>> PASSWORD_SUPPLIER =
Option.valueOf("passwordSupplier");`
Modified `MySqlConnectionConfiguration` - Added the new configuration
for Password Supplier function.
`Publisher<String> passwordSupplier;`
Modified `MySqlConnectionFactory` - Retrieves Password Supplier function
from configuration, and then retrieves password each time connection
factory is created.
Result:
Users can provide a supplier function using `PASSWORD_SUPPLIER` option.
This function will be used for retrieving password/token each time.
```
public ConnectionFactory writeConnectionFactory(final RdsTokenGenerator rdsTokenGenerator) {
return ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(ConnectionFactoryOptions.DRIVER, "mysql")
.option(ConnectionFactoryOptions.HOST, "Hostname of AWS Aurora DB instance")
.option(ConnectionFactoryOptions.PORT, 3306)
.option(ConnectionFactoryOptions.USER, "IAM ROLE Having access to RDS")
.option(MySqlConnectionFactoryProvider.PASSWORD_SUPPLIER, rdsTokenGenerator. generateAuthenticationToken())
.build());
}
```
Example of `RdsTokenGenerator`
```
public class RdsTokenGenerator {
public Mono<String> generateAuthenticationToken() {
return Mono.fromCallable(() -> RdsUtilities.builder()
.credentialsProvider(DefaultCredentialsProvider.create())
.region(Region.US_EAST_1)
.build();
.generateAuthenticationToken((builder) ->
builder
.hostname(hostname)
.port(port)
.username(user)
))
.flatMap(token -> LOGGER.info("Retrieved token from RdsUtilities")
.then(Mono.just(token)))
.subscribeOn(Schedulers.boundedElastic());
}
}
```1 parent 393d25b commit 920410f
File tree
5 files changed
+126
-20
lines changed- src
- main/java/io/asyncer/r2dbc/mysql
- test/java/io/asyncer/r2dbc/mysql
5 files changed
+126
-20
lines changedLines changed: 30 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
100 | | - | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
| 122 | + | |
118 | 123 | | |
119 | 124 | | |
120 | 125 | | |
| |||
204 | 209 | | |
205 | 210 | | |
206 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
207 | 217 | | |
208 | 218 | | |
209 | 219 | | |
| |||
229 | 239 | | |
230 | 240 | | |
231 | 241 | | |
232 | | - | |
| 242 | + | |
| 243 | + | |
233 | 244 | | |
234 | 245 | | |
235 | 246 | | |
236 | 247 | | |
237 | 248 | | |
238 | 249 | | |
239 | | - | |
| 250 | + | |
240 | 251 | | |
241 | 252 | | |
242 | 253 | | |
| |||
248 | 259 | | |
249 | 260 | | |
250 | 261 | | |
251 | | - | |
| 262 | + | |
252 | 263 | | |
253 | 264 | | |
254 | 265 | | |
255 | 266 | | |
256 | 267 | | |
257 | 268 | | |
258 | 269 | | |
259 | | - | |
| 270 | + | |
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
| |||
327 | 338 | | |
328 | 339 | | |
329 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
330 | 344 | | |
331 | 345 | | |
332 | 346 | | |
| |||
351 | 365 | | |
352 | 366 | | |
353 | 367 | | |
354 | | - | |
| 368 | + | |
355 | 369 | | |
356 | 370 | | |
357 | 371 | | |
| |||
779 | 793 | | |
780 | 794 | | |
781 | 795 | | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
782 | 806 | | |
783 | 807 | | |
784 | 808 | | |
| |||
Lines changed: 49 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
91 | 94 | | |
92 | 95 | | |
93 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
94 | 116 | | |
95 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
96 | 132 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
110 | 145 | | |
111 | 146 | | |
112 | 147 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
206 | 215 | | |
207 | 216 | | |
208 | 217 | | |
| |||
261 | 270 | | |
262 | 271 | | |
263 | 272 | | |
| 273 | + | |
| 274 | + | |
264 | 275 | | |
265 | 276 | | |
266 | 277 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
192 | 210 | | |
193 | 211 | | |
194 | 212 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| 39 | + | |
37 | 40 | | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| |||
390 | 394 | | |
391 | 395 | | |
392 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
393 | 411 | | |
394 | 412 | | |
395 | 413 | | |
| |||
0 commit comments