33
33
import org .springframework .http .client .AbstractClientHttpRequestFactoryWrapper ;
34
34
import org .springframework .http .client .ClientHttpRequestFactory ;
35
35
import org .springframework .http .client .ClientHttpRequestInterceptor ;
36
- import org .springframework .http .client .support .BasicAuthorizationInterceptor ;
36
+ import org .springframework .http .client .support .BasicAuthenticationInterceptor ;
37
37
import org .springframework .http .converter .HttpMessageConverter ;
38
38
import org .springframework .util .Assert ;
39
39
import org .springframework .util .CollectionUtils ;
@@ -74,7 +74,7 @@ public class RestTemplateBuilder {
74
74
75
75
private final ResponseErrorHandler errorHandler ;
76
76
77
- private final BasicAuthorizationInterceptor basicAuthorization ;
77
+ private final BasicAuthenticationInterceptor basicAuthentication ;
78
78
79
79
private final Set <RestTemplateCustomizer > restTemplateCustomizers ;
80
80
@@ -95,7 +95,7 @@ public RestTemplateBuilder(RestTemplateCustomizer... customizers) {
95
95
this .requestFactorySupplier = null ;
96
96
this .uriTemplateHandler = null ;
97
97
this .errorHandler = null ;
98
- this .basicAuthorization = null ;
98
+ this .basicAuthentication = null ;
99
99
this .restTemplateCustomizers = Collections
100
100
.unmodifiableSet (new LinkedHashSet <>(Arrays .asList (customizers )));
101
101
this .requestFactoryCustomizer = new RequestFactoryCustomizer ();
@@ -106,7 +106,7 @@ private RestTemplateBuilder(boolean detectRequestFactory, String rootUri,
106
106
Set <HttpMessageConverter <?>> messageConverters ,
107
107
Supplier <ClientHttpRequestFactory > requestFactorySupplier ,
108
108
UriTemplateHandler uriTemplateHandler , ResponseErrorHandler errorHandler ,
109
- BasicAuthorizationInterceptor basicAuthorization ,
109
+ BasicAuthenticationInterceptor basicAuthentication ,
110
110
Set <RestTemplateCustomizer > restTemplateCustomizers ,
111
111
RequestFactoryCustomizer requestFactoryCustomizer ,
112
112
Set <ClientHttpRequestInterceptor > interceptors ) {
@@ -116,7 +116,7 @@ private RestTemplateBuilder(boolean detectRequestFactory, String rootUri,
116
116
this .requestFactorySupplier = requestFactorySupplier ;
117
117
this .uriTemplateHandler = uriTemplateHandler ;
118
118
this .errorHandler = errorHandler ;
119
- this .basicAuthorization = basicAuthorization ;
119
+ this .basicAuthentication = basicAuthentication ;
120
120
this .restTemplateCustomizers = restTemplateCustomizers ;
121
121
this .requestFactoryCustomizer = requestFactoryCustomizer ;
122
122
this .interceptors = interceptors ;
@@ -132,7 +132,7 @@ private RestTemplateBuilder(boolean detectRequestFactory, String rootUri,
132
132
public RestTemplateBuilder detectRequestFactory (boolean detectRequestFactory ) {
133
133
return new RestTemplateBuilder (detectRequestFactory , this .rootUri ,
134
134
this .messageConverters , this .requestFactorySupplier ,
135
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
135
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
136
136
this .restTemplateCustomizers , this .requestFactoryCustomizer ,
137
137
this .interceptors );
138
138
}
@@ -146,7 +146,7 @@ public RestTemplateBuilder detectRequestFactory(boolean detectRequestFactory) {
146
146
public RestTemplateBuilder rootUri (String rootUri ) {
147
147
return new RestTemplateBuilder (this .detectRequestFactory , rootUri ,
148
148
this .messageConverters , this .requestFactorySupplier ,
149
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
149
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
150
150
this .restTemplateCustomizers , this .requestFactoryCustomizer ,
151
151
this .interceptors );
152
152
}
@@ -182,7 +182,7 @@ public RestTemplateBuilder messageConverters(
182
182
Collections .unmodifiableSet (
183
183
new LinkedHashSet <HttpMessageConverter <?>>(messageConverters )),
184
184
this .requestFactorySupplier , this .uriTemplateHandler , this .errorHandler ,
185
- this .basicAuthorization , this .restTemplateCustomizers ,
185
+ this .basicAuthentication , this .restTemplateCustomizers ,
186
186
this .requestFactoryCustomizer , this .interceptors );
187
187
}
188
188
@@ -214,7 +214,7 @@ public RestTemplateBuilder additionalMessageConverters(
214
214
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
215
215
append (this .messageConverters , messageConverters ),
216
216
this .requestFactorySupplier , this .uriTemplateHandler , this .errorHandler ,
217
- this .basicAuthorization , this .restTemplateCustomizers ,
217
+ this .basicAuthentication , this .restTemplateCustomizers ,
218
218
this .requestFactoryCustomizer , this .interceptors );
219
219
}
220
220
@@ -230,7 +230,7 @@ public RestTemplateBuilder defaultMessageConverters() {
230
230
Collections .unmodifiableSet (
231
231
new LinkedHashSet <>(new RestTemplate ().getMessageConverters ())),
232
232
this .requestFactorySupplier , this .uriTemplateHandler , this .errorHandler ,
233
- this .basicAuthorization , this .restTemplateCustomizers ,
233
+ this .basicAuthentication , this .restTemplateCustomizers ,
234
234
this .requestFactoryCustomizer , this .interceptors );
235
235
}
236
236
@@ -263,7 +263,7 @@ public RestTemplateBuilder interceptors(
263
263
Assert .notNull (interceptors , "interceptors must not be null" );
264
264
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
265
265
this .messageConverters , this .requestFactorySupplier ,
266
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
266
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
267
267
this .restTemplateCustomizers , this .requestFactoryCustomizer ,
268
268
Collections .unmodifiableSet (new LinkedHashSet <>(interceptors )));
269
269
}
@@ -295,7 +295,7 @@ public RestTemplateBuilder additionalInterceptors(
295
295
Assert .notNull (interceptors , "interceptors must not be null" );
296
296
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
297
297
this .messageConverters , this .requestFactorySupplier ,
298
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
298
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
299
299
this .restTemplateCustomizers , this .requestFactoryCustomizer ,
300
300
append (this .interceptors , interceptors ));
301
301
}
@@ -337,7 +337,7 @@ public RestTemplateBuilder requestFactory(
337
337
"RequestFactory Supplier must not be null" );
338
338
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
339
339
this .messageConverters , requestFactorySupplier , this .uriTemplateHandler ,
340
- this .errorHandler , this .basicAuthorization , this .restTemplateCustomizers ,
340
+ this .errorHandler , this .basicAuthentication , this .restTemplateCustomizers ,
341
341
this .requestFactoryCustomizer , this .interceptors );
342
342
}
343
343
@@ -351,7 +351,7 @@ public RestTemplateBuilder uriTemplateHandler(UriTemplateHandler uriTemplateHand
351
351
Assert .notNull (uriTemplateHandler , "UriTemplateHandler must not be null" );
352
352
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
353
353
this .messageConverters , this .requestFactorySupplier , uriTemplateHandler ,
354
- this .errorHandler , this .basicAuthorization , this .restTemplateCustomizers ,
354
+ this .errorHandler , this .basicAuthentication , this .restTemplateCustomizers ,
355
355
this .requestFactoryCustomizer , this .interceptors );
356
356
}
357
357
@@ -365,23 +365,37 @@ public RestTemplateBuilder errorHandler(ResponseErrorHandler errorHandler) {
365
365
Assert .notNull (errorHandler , "ErrorHandler must not be null" );
366
366
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
367
367
this .messageConverters , this .requestFactorySupplier ,
368
- this .uriTemplateHandler , errorHandler , this .basicAuthorization ,
368
+ this .uriTemplateHandler , errorHandler , this .basicAuthentication ,
369
369
this .restTemplateCustomizers , this .requestFactoryCustomizer ,
370
370
this .interceptors );
371
371
}
372
372
373
373
/**
374
374
* Add HTTP basic authentication to requests. See
375
- * {@link BasicAuthorizationInterceptor } for details.
375
+ * {@link BasicAuthenticationInterceptor } for details.
376
376
* @param username the user name
377
377
* @param password the password
378
378
* @return a new builder instance
379
+ * @deprecated since 2.1.0 in favor of
380
+ * {@link #basicAuthentication(String username, String password)}
379
381
*/
380
382
public RestTemplateBuilder basicAuthorization (String username , String password ) {
383
+ return basicAuthentication (username , password );
384
+ }
385
+
386
+ /**
387
+ * Add HTTP basic authentication to requests. See
388
+ * {@link BasicAuthenticationInterceptor} for details.
389
+ * @param username the user name
390
+ * @param password the password
391
+ * @return a new builder instance
392
+ * @since 2.1.0
393
+ */
394
+ public RestTemplateBuilder basicAuthentication (String username , String password ) {
381
395
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
382
396
this .messageConverters , this .requestFactorySupplier ,
383
397
this .uriTemplateHandler , this .errorHandler ,
384
- new BasicAuthorizationInterceptor (username , password ),
398
+ new BasicAuthenticationInterceptor (username , password ),
385
399
this .restTemplateCustomizers , this .requestFactoryCustomizer ,
386
400
this .interceptors );
387
401
}
@@ -417,7 +431,7 @@ public RestTemplateBuilder customizers(
417
431
"RestTemplateCustomizers must not be null" );
418
432
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
419
433
this .messageConverters , this .requestFactorySupplier ,
420
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
434
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
421
435
Collections .unmodifiableSet (new LinkedHashSet <RestTemplateCustomizer >(
422
436
restTemplateCustomizers )),
423
437
this .requestFactoryCustomizer , this .interceptors );
@@ -451,7 +465,7 @@ public RestTemplateBuilder additionalCustomizers(
451
465
Assert .notNull (customizers , "RestTemplateCustomizers must not be null" );
452
466
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
453
467
this .messageConverters , this .requestFactorySupplier ,
454
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
468
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
455
469
append (this .restTemplateCustomizers , customizers ),
456
470
this .requestFactoryCustomizer , this .interceptors );
457
471
}
@@ -465,7 +479,7 @@ public RestTemplateBuilder additionalCustomizers(
465
479
public RestTemplateBuilder setConnectTimeout (Duration connectTimeout ) {
466
480
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
467
481
this .messageConverters , this .requestFactorySupplier ,
468
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
482
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
469
483
this .restTemplateCustomizers ,
470
484
this .requestFactoryCustomizer .connectTimeout (connectTimeout ),
471
485
this .interceptors );
@@ -492,7 +506,7 @@ public RestTemplateBuilder setConnectTimeout(int connectTimeout) {
492
506
public RestTemplateBuilder setReadTimeout (Duration readTimeout ) {
493
507
return new RestTemplateBuilder (this .detectRequestFactory , this .rootUri ,
494
508
this .messageConverters , this .requestFactorySupplier ,
495
- this .uriTemplateHandler , this .errorHandler , this .basicAuthorization ,
509
+ this .uriTemplateHandler , this .errorHandler , this .basicAuthentication ,
496
510
this .restTemplateCustomizers ,
497
511
this .requestFactoryCustomizer .readTimeout (readTimeout ),
498
512
this .interceptors );
@@ -556,8 +570,8 @@ public <T extends RestTemplate> T configure(T restTemplate) {
556
570
if (this .rootUri != null ) {
557
571
RootUriTemplateHandler .addTo (restTemplate , this .rootUri );
558
572
}
559
- if (this .basicAuthorization != null ) {
560
- restTemplate .getInterceptors ().add (this .basicAuthorization );
573
+ if (this .basicAuthentication != null ) {
574
+ restTemplate .getInterceptors ().add (this .basicAuthentication );
561
575
}
562
576
restTemplate .getInterceptors ().addAll (this .interceptors );
563
577
if (!CollectionUtils .isEmpty (this .restTemplateCustomizers )) {
0 commit comments