|
16 | 16 |
|
17 | 17 | package org.springframework.security.config.annotation.web.configurers.oauth2.server.authorization; |
18 | 18 |
|
19 | | -import java.util.Map; |
20 | | - |
21 | 19 | import com.nimbusds.jose.jwk.source.JWKSource; |
22 | 20 | import com.nimbusds.jose.proc.SecurityContext; |
23 | 21 |
|
24 | | -import org.springframework.beans.factory.BeanFactoryUtils; |
25 | | -import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
26 | | -import org.springframework.beans.factory.NoUniqueBeanDefinitionException; |
27 | 22 | import org.springframework.context.ApplicationContext; |
28 | 23 | import org.springframework.core.ResolvableType; |
29 | 24 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
|
45 | 40 | import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenCustomizer; |
46 | 41 | import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenGenerator; |
47 | 42 | import org.springframework.util.Assert; |
48 | | -import org.springframework.util.StringUtils; |
49 | 43 |
|
50 | 44 | /** |
51 | 45 | * Utility methods for the OAuth 2.0 Configurers. |
@@ -207,41 +201,16 @@ static AuthorizationServerSettings getAuthorizationServerSettings(HttpSecurity h |
207 | 201 | } |
208 | 202 |
|
209 | 203 | static <T> T getBean(HttpSecurity httpSecurity, Class<T> type) { |
210 | | - return httpSecurity.getSharedObject(ApplicationContext.class).getBean(type); |
211 | | - } |
212 | | - |
213 | | - @SuppressWarnings("unchecked") |
214 | | - static <T> T getBean(HttpSecurity httpSecurity, ResolvableType type) { |
215 | | - ApplicationContext context = httpSecurity.getSharedObject(ApplicationContext.class); |
216 | | - String[] names = context.getBeanNamesForType(type); |
217 | | - if (names.length == 1) { |
218 | | - return (T) context.getBean(names[0]); |
219 | | - } |
220 | | - if (names.length > 1) { |
221 | | - throw new NoUniqueBeanDefinitionException(type, names); |
222 | | - } |
223 | | - throw new NoSuchBeanDefinitionException(type); |
| 204 | + return httpSecurity.getSharedObject(ApplicationContext.class).getBeanProvider(type).getObject(); |
224 | 205 | } |
225 | 206 |
|
226 | 207 | static <T> T getOptionalBean(HttpSecurity httpSecurity, Class<T> type) { |
227 | | - Map<String, T> beansMap = BeanFactoryUtils |
228 | | - .beansOfTypeIncludingAncestors(httpSecurity.getSharedObject(ApplicationContext.class), type); |
229 | | - if (beansMap.size() > 1) { |
230 | | - throw new NoUniqueBeanDefinitionException(type, beansMap.size(), |
231 | | - "Expected single matching bean of type '" + type.getName() + "' but found " + beansMap.size() + ": " |
232 | | - + StringUtils.collectionToCommaDelimitedString(beansMap.keySet())); |
233 | | - } |
234 | | - return (!beansMap.isEmpty() ? beansMap.values().iterator().next() : null); |
| 208 | + return httpSecurity.getSharedObject(ApplicationContext.class).getBeanProvider(type).getIfUnique(); |
235 | 209 | } |
236 | 210 |
|
237 | 211 | @SuppressWarnings("unchecked") |
238 | 212 | static <T> T getOptionalBean(HttpSecurity httpSecurity, ResolvableType type) { |
239 | | - ApplicationContext context = httpSecurity.getSharedObject(ApplicationContext.class); |
240 | | - String[] names = context.getBeanNamesForType(type); |
241 | | - if (names.length > 1) { |
242 | | - throw new NoUniqueBeanDefinitionException(type, names); |
243 | | - } |
244 | | - return (names.length == 1) ? (T) context.getBean(names[0]) : null; |
| 213 | + return (T) httpSecurity.getSharedObject(ApplicationContext.class).getBeanProvider(type).getIfUnique(); |
245 | 214 | } |
246 | 215 |
|
247 | 216 | } |
0 commit comments