@@ -1286,7 +1286,7 @@ public ZonedDateTime getFirstZonedDateTime(String headerName) {
1286
1286
* {@link IllegalArgumentException} ({@code true}) or rather return {@code null}
1287
1287
* in that case ({@code false})
1288
1288
* @return the parsed date header, or {@code null} if none (or invalid)
1289
- */
1289
+ */
1290
1290
@ Nullable
1291
1291
private ZonedDateTime getFirstZonedDateTime (String headerName , boolean rejectInvalid ) {
1292
1292
String headerValue = getFirst (headerName );
@@ -1570,57 +1570,52 @@ public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) {
1570
1570
}
1571
1571
1572
1572
/**
1573
- * Returns a {@code HttpHeaders} consumer that adds Basic Authentication.
1573
+ * Return a {@code HttpHeaders} consumer that adds Basic Authentication.
1574
1574
* More specifically: a consumer that adds an {@linkplain #AUTHORIZATION
1575
- * Authorization} header based on the given username and password. Meant
1576
- * to be used in combination with
1575
+ * Authorization} header based on the given username and password.
1576
+ * Meant to be used in combination with
1577
1577
* {@link org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec#headers(java.util.function.Consumer)}.
1578
1578
* <p>Note that Basic Authentication only supports characters in the
1579
1579
* {@linkplain StandardCharsets#ISO_8859_1 ISO-8859-1} character set.
1580
- *
1581
1580
* @param username the username
1582
1581
* @param password the password
1583
1582
* @return a consumer that adds a Basic Authentication header
1583
+ * @since 5.1
1584
1584
*/
1585
- public static Consumer <HttpHeaders > basicAuthenticationConsumer (String username ,String password ) {
1585
+ public static Consumer <HttpHeaders > basicAuthenticationConsumer (String username , String password ) {
1586
1586
return basicAuthenticationConsumer (() -> username , () -> password );
1587
1587
1588
1588
}
1589
1589
1590
1590
/**
1591
- * Returns a {@code HttpHeaders} consumer that adds Basic Authentication.
1591
+ * Return a {@code HttpHeaders} consumer that adds Basic Authentication.
1592
1592
* More specifically: a consumer that adds an {@linkplain #AUTHORIZATION
1593
1593
* Authorization} header based on the given username and password
1594
1594
* suppliers. Meant to be used in combination with
1595
1595
* {@link org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec#headers(java.util.function.Consumer)}.
1596
1596
* <p>Note that Basic Authentication only supports characters in the
1597
1597
* {@linkplain StandardCharsets#ISO_8859_1 ISO-8859-1} character set.
1598
- *
1599
1598
* @param usernameSupplier supplier for the username
1600
1599
* @param passwordSupplier supplier for the password
1601
1600
* @return a consumer that adds a Basic Authentication header
1601
+ * @since 5.1
1602
1602
*/
1603
- public static Consumer <HttpHeaders > basicAuthenticationConsumer (Supplier < String > usernameSupplier ,
1604
- Supplier <String > passwordSupplier ) {
1603
+ public static Consumer <HttpHeaders > basicAuthenticationConsumer (
1604
+ Supplier <String > usernameSupplier , Supplier < String > passwordSupplier ) {
1605
1605
1606
1606
Assert .notNull (usernameSupplier , "Username Supplier must not be null" );
1607
1607
Assert .notNull (passwordSupplier , "Password Supplier must not be null" );
1608
-
1609
1608
return new BasicAuthenticationConsumer (usernameSupplier , passwordSupplier );
1610
1609
}
1611
1610
1612
1611
1613
- /**
1614
- * @see #basicAuthenticationConsumer
1615
- */
1616
1612
private static class BasicAuthenticationConsumer implements Consumer <HttpHeaders > {
1617
1613
1618
1614
private final Supplier <String > usernameSupplier ;
1619
1615
1620
1616
private final Supplier <String > passwordSupplier ;
1621
1617
1622
- public BasicAuthenticationConsumer (Supplier <String > usernameSupplier ,
1623
- Supplier <String > passwordSupplier ) {
1618
+ public BasicAuthenticationConsumer (Supplier <String > usernameSupplier , Supplier <String > passwordSupplier ) {
1624
1619
this .usernameSupplier = usernameSupplier ;
1625
1620
this .passwordSupplier = passwordSupplier ;
1626
1621
}
@@ -1629,17 +1624,14 @@ public BasicAuthenticationConsumer(Supplier<String> usernameSupplier,
1629
1624
public void accept (HttpHeaders httpHeaders ) {
1630
1625
String username = this .usernameSupplier .get ();
1631
1626
String password = this .passwordSupplier .get ();
1632
-
1633
1627
Assert .state (username != null , "Supplied username is null" );
1634
1628
Assert .state (password != null , "Supplied password is null" );
1635
-
1636
1629
checkIllegalCharacters (username , password );
1637
1630
1638
1631
String credentialsString = username + ":" + password ;
1639
1632
byte [] credentialBytes = credentialsString .getBytes (StandardCharsets .ISO_8859_1 );
1640
1633
byte [] encodedBytes = Base64 .getEncoder ().encode (credentialBytes );
1641
1634
String encodedCredentials = new String (encodedBytes , StandardCharsets .ISO_8859_1 );
1642
-
1643
1635
httpHeaders .set (HttpHeaders .AUTHORIZATION , "Basic " + encodedCredentials );
1644
1636
}
1645
1637
@@ -1651,6 +1643,6 @@ private static void checkIllegalCharacters(String username, String password) {
1651
1643
"Username or password contains characters that cannot be encoded to ISO-8859-1" );
1652
1644
}
1653
1645
}
1654
-
1655
1646
}
1647
+
1656
1648
}
0 commit comments