|
15 | 15 | */
|
16 | 16 | package org.springframework.security.config.annotation.web.configurers.oauth2.client;
|
17 | 17 |
|
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.HashMap; |
| 21 | +import java.util.LinkedHashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | + |
18 | 25 | import org.springframework.beans.factory.BeanFactoryUtils;
|
19 | 26 | import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
20 | 27 | import org.springframework.context.ApplicationContext;
|
|
71 | 78 | import org.springframework.util.Assert;
|
72 | 79 | import org.springframework.util.ClassUtils;
|
73 | 80 |
|
74 |
| -import java.util.ArrayList; |
75 |
| -import java.util.Collections; |
76 |
| -import java.util.HashMap; |
77 |
| -import java.util.LinkedHashMap; |
78 |
| -import java.util.List; |
79 |
| -import java.util.Map; |
80 |
| - |
81 | 81 | /**
|
82 | 82 | * An {@link AbstractHttpConfigurer} for OAuth 2.0 Login,
|
83 | 83 | * which leverages the OAuth 2.0 Authorization Code Grant Flow.
|
|
135 | 135 | public final class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>> extends
|
136 | 136 | AbstractAuthenticationFilterConfigurer<B, OAuth2LoginConfigurer<B>, OAuth2LoginAuthenticationFilter> {
|
137 | 137 |
|
138 |
| - private final ApplicationContext context; |
139 | 138 | private final AuthorizationEndpointConfig authorizationEndpointConfig = new AuthorizationEndpointConfig();
|
140 | 139 | private final TokenEndpointConfig tokenEndpointConfig = new TokenEndpointConfig();
|
141 | 140 | private final RedirectionEndpointConfig redirectionEndpointConfig = new RedirectionEndpointConfig();
|
142 | 141 | private final UserInfoEndpointConfig userInfoEndpointConfig = new UserInfoEndpointConfig();
|
143 | 142 | private String loginPage;
|
144 | 143 | private String loginProcessingUrl = OAuth2LoginAuthenticationFilter.DEFAULT_FILTER_PROCESSES_URI;
|
145 | 144 |
|
146 |
| - public OAuth2LoginConfigurer(ApplicationContext context) { |
147 |
| - Assert.notNull(context, "context cannot be null"); |
148 |
| - this.context = context; |
149 |
| - } |
150 |
| - |
151 | 145 | /**
|
152 | 146 | * Sets the repository of client registrations.
|
153 | 147 | *
|
@@ -652,9 +646,13 @@ private OAuth2UserService<OAuth2UserRequest, OAuth2User> getOAuth2UserService()
|
652 | 646 | }
|
653 | 647 |
|
654 | 648 | private <T> T getBeanOrNull(ResolvableType type) {
|
655 |
| - String[] names = this.context.getBeanNamesForType(type); |
| 649 | + ApplicationContext context = getBuilder().getSharedObject(ApplicationContext.class); |
| 650 | + if (context == null) { |
| 651 | + return null; |
| 652 | + } |
| 653 | + String[] names = context.getBeanNamesForType(type); |
656 | 654 | if (names.length == 1) {
|
657 |
| - return (T) this.context.getBean(names[0]); |
| 655 | + return (T) context.getBean(names[0]); |
658 | 656 | }
|
659 | 657 | return null;
|
660 | 658 | }
|
|
0 commit comments