@@ -147,7 +147,7 @@ public void testExpiredTokensDeletedAfterExpiration() throws Exception {
147
147
Instant created = Instant .now ();
148
148
149
149
InvalidateTokenResponse invalidateResponse = restClient .security ().invalidateToken (
150
- new InvalidateTokenRequest (accessToken , null , null , null ), SECURITY_REQUEST_OPTIONS );
150
+ InvalidateTokenRequest . accessToken (accessToken ), SECURITY_REQUEST_OPTIONS );
151
151
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (1 ));
152
152
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
153
153
assertThat (invalidateResponse .getErrors (), empty ());
@@ -174,7 +174,7 @@ public void testExpiredTokensDeletedAfterExpiration() throws Exception {
174
174
if (deleteTriggered .compareAndSet (false , true )) {
175
175
// invalidate a invalid token... doesn't matter that it is bad... we just want this action to trigger the deletion
176
176
InvalidateTokenResponse invalidateResponseTwo = restClient .security ()
177
- .invalidateToken (new InvalidateTokenRequest ("fooobar" , null , null , null ),
177
+ .invalidateToken (InvalidateTokenRequest . accessToken ("fooobar" ),
178
178
SECURITY_REQUEST_OPTIONS );
179
179
assertThat (invalidateResponseTwo .getInvalidatedTokens (), equalTo (0 ));
180
180
assertThat (invalidateResponseTwo .getPreviouslyInvalidatedTokens (), equalTo (0 ));
@@ -189,12 +189,13 @@ public void testExpiredTokensDeletedAfterExpiration() throws Exception {
189
189
190
190
// Now the documents are deleted, try to invalidate the access token and refresh token again
191
191
InvalidateTokenResponse invalidateAccessTokenResponse = restClient .security ().invalidateToken (
192
- new InvalidateTokenRequest (accessToken , null , null , null ), SECURITY_REQUEST_OPTIONS );
192
+ InvalidateTokenRequest . accessToken (accessToken ), SECURITY_REQUEST_OPTIONS );
193
193
assertThat (invalidateAccessTokenResponse .getInvalidatedTokens (), equalTo (0 ));
194
194
assertThat (invalidateAccessTokenResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
195
195
assertThat (invalidateAccessTokenResponse .getErrors (), empty ());
196
+
196
197
InvalidateTokenResponse invalidateRefreshTokenResponse = restClient .security ().invalidateToken (
197
- new InvalidateTokenRequest (refreshToken , null , null , null ), SECURITY_REQUEST_OPTIONS );
198
+ InvalidateTokenRequest . refreshToken (refreshToken ), SECURITY_REQUEST_OPTIONS );
198
199
assertThat (invalidateRefreshTokenResponse .getInvalidatedTokens (), equalTo (0 ));
199
200
assertThat (invalidateRefreshTokenResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
200
201
assertThat (invalidateRefreshTokenResponse .getErrors (), empty ());
@@ -208,7 +209,7 @@ public void testInvalidateAllTokensForUser() throws Exception {
208
209
SecuritySettingsSourceField .TEST_PASSWORD .toCharArray ()), SECURITY_REQUEST_OPTIONS );
209
210
}
210
211
InvalidateTokenResponse invalidateResponse = restClient .security ().invalidateToken (
211
- new InvalidateTokenRequest ( null , null , null , SecuritySettingsSource .TEST_USER_NAME ),
212
+ InvalidateTokenRequest . userTokens ( SecuritySettingsSource .TEST_USER_NAME ),
212
213
RequestOptions .DEFAULT .toBuilder ().addHeader ("Authorization" ,
213
214
UsernamePasswordToken .basicAuthHeaderValue (SecuritySettingsSource .TEST_SUPERUSER ,
214
215
SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING )).build ());
@@ -225,7 +226,7 @@ public void testInvalidateAllTokensForRealm() throws Exception {
225
226
SecuritySettingsSourceField .TEST_PASSWORD .toCharArray ()), SECURITY_REQUEST_OPTIONS );
226
227
}
227
228
InvalidateTokenResponse invalidateResponse = restClient .security ().invalidateToken (
228
- new InvalidateTokenRequest ( null , null , "file" , null ),
229
+ InvalidateTokenRequest . realmTokens ( "file" ),
229
230
RequestOptions .DEFAULT .toBuilder ().addHeader ("Authorization" ,
230
231
UsernamePasswordToken .basicAuthHeaderValue (SecuritySettingsSource .TEST_SUPERUSER ,
231
232
SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING )).build ());
@@ -242,7 +243,7 @@ public void testInvalidateAllTokensForRealmThatHasNone() throws IOException {
242
243
SecuritySettingsSourceField .TEST_PASSWORD .toCharArray ()), SECURITY_REQUEST_OPTIONS );
243
244
}
244
245
InvalidateTokenResponse invalidateResponse = restClient .security ().invalidateToken (
245
- new InvalidateTokenRequest ( null , null , "saml" , null ),
246
+ InvalidateTokenRequest . realmTokens ( "saml" ),
246
247
RequestOptions .DEFAULT .toBuilder ().addHeader ("Authorization" ,
247
248
UsernamePasswordToken .basicAuthHeaderValue (SecuritySettingsSource .TEST_SUPERUSER ,
248
249
SecuritySettingsSourceField .TEST_PASSWORD_SECURE_STRING )).build ());
@@ -257,12 +258,12 @@ public void testInvalidateMultipleTimes() throws IOException {
257
258
SecuritySettingsSource .TEST_USER_NAME , SecuritySettingsSourceField .TEST_PASSWORD .toCharArray ()), SECURITY_REQUEST_OPTIONS );
258
259
259
260
InvalidateTokenResponse invalidateResponse = restClient .security ()
260
- .invalidateToken (new InvalidateTokenRequest (response .getAccessToken (), null , null , null ), SECURITY_REQUEST_OPTIONS );
261
+ .invalidateToken (InvalidateTokenRequest . accessToken (response .getAccessToken ()), SECURITY_REQUEST_OPTIONS );
261
262
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (1 ));
262
263
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
263
264
assertThat (invalidateResponse .getErrors (), empty ());
264
265
InvalidateTokenResponse invalidateAgainResponse = restClient .security ()
265
- .invalidateToken (new InvalidateTokenRequest (response .getAccessToken (), null , null , null ), SECURITY_REQUEST_OPTIONS );
266
+ .invalidateToken (InvalidateTokenRequest . accessToken (response .getAccessToken ()), SECURITY_REQUEST_OPTIONS );
266
267
assertThat (invalidateAgainResponse .getInvalidatedTokens (), equalTo (0 ));
267
268
assertThat (invalidateAgainResponse .getPreviouslyInvalidatedTokens (), equalTo (1 ));
268
269
assertThat (invalidateAgainResponse .getErrors (), empty ());
@@ -272,37 +273,36 @@ public void testInvalidateNotValidAccessTokens() throws Exception {
272
273
final RestHighLevelClient restClient = new TestRestHighLevelClient ();
273
274
// Perform a request to invalidate a token, before the tokens index is created
274
275
ElasticsearchStatusException e = expectThrows (ElasticsearchStatusException .class , () -> restClient .security ()
275
- .invalidateToken (new InvalidateTokenRequest (generateAccessToken (Version .CURRENT ), null , null , null ),
276
+ .invalidateToken (InvalidateTokenRequest . accessToken (generateAccessToken (Version .CURRENT )),
276
277
SECURITY_REQUEST_OPTIONS ));
277
278
assertThat (e .status (), equalTo (RestStatus .BAD_REQUEST ));
278
279
// Create a token to trigger index creation
279
280
restClient .security ().createToken (CreateTokenRequest .passwordGrant (
280
281
SecuritySettingsSource .TEST_USER_NAME , SecuritySettingsSourceField .TEST_PASSWORD .toCharArray ()), SECURITY_REQUEST_OPTIONS );
281
282
InvalidateTokenResponse invalidateResponse = restClient .security ()
282
- .invalidateToken (new InvalidateTokenRequest ("!this_is_not_a_base64_string_and_we_should_fail_decoding_it" , null , null , null ),
283
+ .invalidateToken (InvalidateTokenRequest . accessToken ("!this_is_not_a_base64_string_and_we_should_fail_decoding_it" ),
283
284
SECURITY_REQUEST_OPTIONS );
284
285
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
285
286
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
286
287
assertThat (invalidateResponse .getErrors (), empty ());
287
288
288
289
invalidateResponse = restClient .security ()
289
- .invalidateToken (new InvalidateTokenRequest ("10we+might+assume+this+is+valid+old+token" , null , null ,
290
- null ), SECURITY_REQUEST_OPTIONS );
290
+ .invalidateToken (InvalidateTokenRequest .accessToken ("10we+might+assume+this+is+valid+old+token" ), SECURITY_REQUEST_OPTIONS );
291
291
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
292
292
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
293
293
assertThat (invalidateResponse .getErrors (), empty ());
294
294
295
295
invalidateResponse = restClient .security ()
296
- .invalidateToken (new InvalidateTokenRequest (generateInvalidShortAccessToken (Version .CURRENT ), null , null ,
297
- null ), SECURITY_REQUEST_OPTIONS );
296
+ .invalidateToken (InvalidateTokenRequest . accessToken (generateInvalidShortAccessToken (Version .CURRENT )) ,
297
+ SECURITY_REQUEST_OPTIONS );
298
298
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
299
299
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
300
300
assertThat (invalidateResponse .getErrors (), empty ());
301
301
302
302
// Generate a token that could be a valid token string for the version we are on, and should decode fine, but is not found in our
303
303
// tokens index
304
304
invalidateResponse = restClient .security ()
305
- .invalidateToken (new InvalidateTokenRequest (generateAccessToken (Version .CURRENT ), null , null , null ),
305
+ .invalidateToken (InvalidateTokenRequest . accessToken (generateAccessToken (Version .CURRENT )),
306
306
SECURITY_REQUEST_OPTIONS );
307
307
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
308
308
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
@@ -313,30 +313,29 @@ public void testInvalidateNotValidRefreshTokens() throws Exception {
313
313
final RestHighLevelClient restClient = new TestRestHighLevelClient ();
314
314
// Perform a request to invalidate a refresh token, before the tokens index is created
315
315
ElasticsearchStatusException e = expectThrows (ElasticsearchStatusException .class , () -> restClient .security ()
316
- .invalidateToken (new InvalidateTokenRequest ( null ,
317
- TokenService .prependVersionAndEncodeRefreshToken (Version .CURRENT , UUIDs .randomBase64UUID ()), null , null ),
316
+ .invalidateToken (InvalidateTokenRequest . refreshToken (
317
+ TokenService .prependVersionAndEncodeRefreshToken (Version .CURRENT , UUIDs .randomBase64UUID ())),
318
318
SECURITY_REQUEST_OPTIONS ));
319
319
assertThat (e .status (), equalTo (RestStatus .BAD_REQUEST ));
320
320
// Create a token to trigger index creation
321
321
restClient .security ().createToken (CreateTokenRequest .passwordGrant (
322
322
SecuritySettingsSource .TEST_USER_NAME , SecuritySettingsSourceField .TEST_PASSWORD .toCharArray ()), SECURITY_REQUEST_OPTIONS );
323
323
InvalidateTokenResponse invalidateResponse = restClient .security ()
324
- .invalidateToken (new InvalidateTokenRequest ( null , "!this_is_not_a_base64_string_and_we_should_fail_decoding_it" , null , null ),
324
+ .invalidateToken (InvalidateTokenRequest . refreshToken ( "!this_is_not_a_base64_string_and_we_should_fail_decoding_it" ),
325
325
SECURITY_REQUEST_OPTIONS );
326
326
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
327
327
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
328
328
assertThat (invalidateResponse .getErrors (), empty ());
329
329
330
330
invalidateResponse = restClient .security ()
331
- .invalidateToken (new InvalidateTokenRequest (null , "10we+might+assume+this+is+valid+old+token" , null ,
332
- null ), SECURITY_REQUEST_OPTIONS );
331
+ .invalidateToken (InvalidateTokenRequest .refreshToken ("10we+might+assume+this+is+valid+old+token" ), SECURITY_REQUEST_OPTIONS );
333
332
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
334
333
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
335
334
assertThat (invalidateResponse .getErrors (), empty ());
336
335
337
336
invalidateResponse = restClient .security ()
338
- .invalidateToken (new InvalidateTokenRequest ( null ,
339
- TokenService .prependVersionAndEncodeRefreshToken (Version .CURRENT , randomAlphaOfLength (32 )), null , null ),
337
+ .invalidateToken (InvalidateTokenRequest . refreshToken (
338
+ TokenService .prependVersionAndEncodeRefreshToken (Version .CURRENT , randomAlphaOfLength (32 ))),
340
339
SECURITY_REQUEST_OPTIONS );
341
340
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
342
341
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
@@ -345,8 +344,8 @@ public void testInvalidateNotValidRefreshTokens() throws Exception {
345
344
// Generate a token that could be a valid token string for the version we are on, and should decode fine, but is not found in our
346
345
// tokens index
347
346
invalidateResponse = restClient .security ()
348
- .invalidateToken (new InvalidateTokenRequest ( null ,
349
- TokenService .prependVersionAndEncodeRefreshToken (Version .CURRENT , UUIDs .randomBase64UUID ()), null , null ),
347
+ .invalidateToken (InvalidateTokenRequest . refreshToken (
348
+ TokenService .prependVersionAndEncodeRefreshToken (Version .CURRENT , UUIDs .randomBase64UUID ())),
350
349
SECURITY_REQUEST_OPTIONS );
351
350
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (0 ));
352
351
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
@@ -377,7 +376,7 @@ public void testRefreshingInvalidatedToken() throws IOException {
377
376
SecuritySettingsSource .TEST_USER_NAME , SecuritySettingsSourceField .TEST_PASSWORD .toCharArray ()), SECURITY_REQUEST_OPTIONS );
378
377
assertNotNull (createTokenResponse .getRefreshToken ());
379
378
InvalidateTokenResponse invalidateResponse = restClient .security ()
380
- .invalidateToken (new InvalidateTokenRequest ( null , createTokenResponse .getRefreshToken (), null , null ), SECURITY_REQUEST_OPTIONS );
379
+ .invalidateToken (InvalidateTokenRequest . refreshToken ( createTokenResponse .getRefreshToken ()), SECURITY_REQUEST_OPTIONS );
381
380
assertThat (invalidateResponse .getInvalidatedTokens (), equalTo (1 ));
382
381
assertThat (invalidateResponse .getPreviouslyInvalidatedTokens (), equalTo (0 ));
383
382
assertThat (invalidateResponse .getErrors (), empty ());
0 commit comments