|
4 | 4 |
|
5 | 5 | import java.util.Base64;
|
6 | 6 |
|
7 |
| -/** Adds Basic Authorization header to requests. */ |
| 7 | +/** |
| 8 | + * Adds Basic Authorization header to requests. |
| 9 | + */ |
8 | 10 | public final class BasicAuthIntercept implements RequestIntercept {
|
9 | 11 |
|
10 | 12 | private final String headerValue;
|
11 | 13 |
|
12 |
| - /** Construct with the username and password. */ |
| 14 | + /** |
| 15 | + * Construct with the username and password. |
| 16 | + */ |
13 | 17 | public BasicAuthIntercept(String username, String password) {
|
14 |
| - this.headerValue = "Basic " + encode(username, password); |
| 18 | + this.headerValue = header(username, password); |
15 | 19 | }
|
16 | 20 |
|
17 |
| - /** Return Base64 encoding of {@literal username:password} */ |
| 21 | + /** |
| 22 | + * Return the Basic header value with the encoding of {@literal username:password} |
| 23 | + * <p> |
| 24 | + * Provided as a helper method for code that wants the header value to then |
| 25 | + * apply explicitly rather than using this as a request intercept. |
| 26 | + * |
| 27 | + * @return {@code "Basic " + encode(username, password)} |
| 28 | + */ |
| 29 | + public static String header(String username, String password) { |
| 30 | + return "Basic " + encode(username, password); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Return Base64 encoding of {@literal username:password} |
| 35 | + * <p> |
| 36 | + * Provided as a helper method for code that wants to encode the username |
| 37 | + * password pair and use that explicitly rather than using this as a request intercept. |
| 38 | + */ |
18 | 39 | public static String encode(String username, String password) {
|
19 | 40 | return Base64.getEncoder().encodeToString((username + ":" + password).getBytes(UTF_8));
|
20 | 41 | }
|
|
0 commit comments