@@ -136,11 +136,8 @@ private Future<Void> renew() {
136
136
}
137
137
138
138
private Future <Void > renewToken () {
139
- Promise <Void > promise = vertx .promise ();
140
- client .renewSelf (config .getLong ("lease-duration" , 3600L ), auth -> {
141
- manageAuthenticationResult (promise , auth );
142
- });
143
- return promise .future ();
139
+ return client .renewSelf (config .getLong ("lease-duration" , 3600L ))
140
+ .compose (this ::manageAuthenticationResult );
144
141
}
145
142
146
143
@@ -168,7 +165,6 @@ private Future<Void> authenticate(boolean renew) {
168
165
}
169
166
170
167
private Future <Void > loginWithUserName () {
171
- Promise <Void > promise = vertx .promise ();
172
168
JsonObject req = config .getJsonObject ("user-credentials" );
173
169
Objects .requireNonNull (req , "When using username, the `user-credentials` must be set in the " +
174
170
"configuration" );
@@ -182,21 +178,16 @@ private Future<Void> loginWithUserName() {
182
178
"configuration" );
183
179
184
180
185
- client
186
- .loginWithUserCredentials (username , password , auth -> manageAuthenticationResult (promise , auth ));
187
- return promise .future ();
181
+ return client .loginWithUserCredentials (username , password ).compose (auth -> manageAuthenticationResult (auth ));
188
182
}
189
183
190
184
private Future <Void > loginWithCert () {
191
- Promise <Void > promise = vertx .promise ();
192
185
// No validation, certs are configured on the client itself
193
- client .loginWithCert (auth -> manageAuthenticationResult (promise , auth ));
194
- return promise .future ();
186
+ return client .loginWithCert ().compose (auth -> manageAuthenticationResult (auth ));
195
187
}
196
188
197
189
198
190
private Future <Void > loginWithAppRole () {
199
- Promise <Void > promise = vertx .promise ();
200
191
JsonObject req = config .getJsonObject ("approle" );
201
192
Objects .requireNonNull (req , "When using approle, the `app-role` must be set in the " +
202
193
"configuration" );
@@ -206,38 +197,30 @@ private Future<Void> loginWithAppRole() {
206
197
Objects .requireNonNull (roleId , "When using approle, the role-id must be set in the `approle` configuration" );
207
198
Objects .requireNonNull (secretId , "When using approle, the secret-id must be set in the `approle` configuration" );
208
199
209
- client .loginWithAppRole (roleId , secretId , auth -> manageAuthenticationResult (promise , auth ));
210
- return promise .future ();
200
+ return client .loginWithAppRole (roleId , secretId ).compose (auth -> manageAuthenticationResult (auth ));
211
201
}
212
202
213
203
private Future <Void > loginWithToken () {
214
- Promise <Void > promise = vertx .promise ();
215
204
JsonObject req = config .getJsonObject ("token-request" );
216
205
Objects .requireNonNull (req , "When using a token creation policy, the `token-request` must be set in the " +
217
206
"configuration" );
218
207
219
208
String token = req .getString ("token" );
220
209
Objects .requireNonNull (req , "When using a token creation policy, the `token-request` must be set in the " +
221
210
"configuration and contains the `token` entry with the original token" );
222
- client
211
+ return client
223
212
.setToken (token )
224
- .createToken (new TokenRequest (req ), auth -> manageAuthenticationResult (promise , auth ));
225
- return promise .future ();
213
+ .createToken (new TokenRequest (req )).compose (auth -> manageAuthenticationResult (auth ));
226
214
}
227
215
228
- private void manageAuthenticationResult ( Promise <Void > future , AsyncResult < Auth > auth ) {
229
- if (auth . failed () ) {
230
- future . fail ( auth . cause () );
216
+ private Future <Void > manageAuthenticationResult ( Auth authentication ) {
217
+ if (authentication . getClientToken () == null ) {
218
+ return Future . failedFuture ( "Authentication failed, the token is null" );
231
219
} else {
232
- Auth authentication = auth .result ();
233
- if (authentication .getClientToken () == null ) {
234
- future .fail ("Authentication failed, the token is null" );
235
- } else {
236
- client .setToken (authentication .getClientToken ());
237
- this .renewable = authentication .isRenewable ();
238
- this .validity = System .currentTimeMillis () + (authentication .getLeaseDuration () * 1000 );
239
- future .complete ();
240
- }
220
+ client .setToken (authentication .getClientToken ());
221
+ this .renewable = authentication .isRenewable ();
222
+ this .validity = System .currentTimeMillis () + (authentication .getLeaseDuration () * 1000 );
223
+ return Future .succeededFuture ();
241
224
}
242
225
}
243
226
0 commit comments