|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.web.reactive.function.client;
|
18 | 18 |
|
19 | 19 | import java.nio.charset.Charset;
|
20 |
| -import java.util.Map; |
21 |
| -import java.util.function.Consumer; |
22 | 20 | import java.util.function.Function;
|
23 | 21 | import java.util.function.Predicate;
|
24 | 22 |
|
25 |
| -import org.jspecify.annotations.Nullable; |
26 | 23 | import reactor.core.publisher.Mono;
|
27 | 24 |
|
28 | 25 | import org.springframework.core.io.buffer.DataBufferUtils;
|
|
41 | 38 | */
|
42 | 39 | public abstract class ExchangeFilterFunctions {
|
43 | 40 |
|
44 |
| - /** |
45 |
| - * Name of the request attribute with {@link Credentials} for {@link #basicAuthentication()}. |
46 |
| - */ |
47 |
| - private static final String BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE = |
48 |
| - ExchangeFilterFunctions.class.getName() + ".basicAuthenticationCredentials"; |
49 |
| - |
50 |
| - |
51 | 41 | /**
|
52 | 42 | * Consume up to the specified number of bytes from the response body and
|
53 | 43 | * cancel if any more data arrives.
|
@@ -100,81 +90,4 @@ public static ExchangeFilterFunction basicAuthentication(String username, String
|
100 | 90 | .build());
|
101 | 91 | }
|
102 | 92 |
|
103 |
| - /** |
104 |
| - * Variant of {@link #basicAuthentication(String, String)} that looks up |
105 |
| - * the {@link Credentials Credentials} in a |
106 |
| - * {@link #BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE request attribute}. |
107 |
| - * @return the filter to use |
108 |
| - * @see Credentials |
109 |
| - * @deprecated as of Spring 5.1 in favor of using |
110 |
| - * {@link HttpHeaders#setBasicAuth(String, String)} while building the request. |
111 |
| - */ |
112 |
| - @Deprecated |
113 |
| - public static ExchangeFilterFunction basicAuthentication() { |
114 |
| - return (request, next) -> { |
115 |
| - Object attr = request.attributes().get(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE); |
116 |
| - if (attr instanceof Credentials cred) { |
117 |
| - return next.exchange(ClientRequest.from(request) |
118 |
| - .headers(headers -> headers.setBasicAuth(cred.username, cred.password)) |
119 |
| - .build()); |
120 |
| - } |
121 |
| - else { |
122 |
| - return next.exchange(request); |
123 |
| - } |
124 |
| - }; |
125 |
| - } |
126 |
| - |
127 |
| - |
128 |
| - /** |
129 |
| - * Stores username and password for HTTP basic authentication. |
130 |
| - * @deprecated as of Spring 5.1 in favor of using |
131 |
| - * {@link HttpHeaders#setBasicAuth(String, String)} while building the request. |
132 |
| - */ |
133 |
| - @Deprecated |
134 |
| - public static final class Credentials { |
135 |
| - |
136 |
| - private final String username; |
137 |
| - |
138 |
| - private final String password; |
139 |
| - |
140 |
| - /** |
141 |
| - * Create a new {@code Credentials} instance with the given username and password. |
142 |
| - * @param username the username |
143 |
| - * @param password the password |
144 |
| - */ |
145 |
| - public Credentials(String username, String password) { |
146 |
| - Assert.notNull(username, "'username' must not be null"); |
147 |
| - Assert.notNull(password, "'password' must not be null"); |
148 |
| - this.username = username; |
149 |
| - this.password = password; |
150 |
| - } |
151 |
| - |
152 |
| - /** |
153 |
| - * Return a {@literal Consumer} that stores the given username and password |
154 |
| - * as a request attribute of type {@code Credentials} that is in turn |
155 |
| - * used by {@link ExchangeFilterFunctions#basicAuthentication()}. |
156 |
| - * @param username the username |
157 |
| - * @param password the password |
158 |
| - * @return a consumer that can be passed into |
159 |
| - * {@linkplain ClientRequest.Builder#attributes(java.util.function.Consumer)} |
160 |
| - * @see ClientRequest.Builder#attributes(java.util.function.Consumer) |
161 |
| - * @see #BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE |
162 |
| - */ |
163 |
| - public static Consumer<Map<String, Object>> basicAuthenticationCredentials(String username, String password) { |
164 |
| - Credentials credentials = new Credentials(username, password); |
165 |
| - return (map -> map.put(BASIC_AUTHENTICATION_CREDENTIALS_ATTRIBUTE, credentials)); |
166 |
| - } |
167 |
| - |
168 |
| - @Override |
169 |
| - public boolean equals(@Nullable Object other) { |
170 |
| - return (this == other ||(other instanceof Credentials that && |
171 |
| - this.username.equals(that.username) && this.password.equals(that.password))); |
172 |
| - } |
173 |
| - |
174 |
| - @Override |
175 |
| - public int hashCode() { |
176 |
| - return this.username.hashCode() * 31 + this.password.hashCode(); |
177 |
| - } |
178 |
| - } |
179 |
| - |
180 | 93 | }
|
0 commit comments