|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 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.
|
|
29 | 29 | import org.springframework.beans.factory.BeanInitializationException;
|
30 | 30 | import org.springframework.beans.factory.ListableBeanFactory;
|
31 | 31 | import org.springframework.beans.factory.ObjectProvider;
|
32 |
| -import org.springframework.beans.factory.annotation.Autowired; |
33 | 32 | import org.springframework.beans.factory.config.BeanDefinition;
|
34 | 33 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
35 | 34 | import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
@@ -118,43 +117,31 @@ OAuth2AuthorizedClientManagerRegistrar authorizedClientManagerRegistrar() {
|
118 | 117 | @Configuration(proxyBeanMethods = false)
|
119 | 118 | static class OAuth2ClientWebMvcSecurityConfiguration implements WebMvcConfigurer {
|
120 | 119 |
|
121 |
| - private OAuth2AuthorizedClientManager authorizedClientManager; |
| 120 | + private final OAuth2AuthorizedClientManager authorizedClientManager; |
122 | 121 |
|
123 |
| - private SecurityContextHolderStrategy securityContextHolderStrategy; |
| 122 | + private final ObjectProvider<SecurityContextHolderStrategy> securityContextHolderStrategy; |
124 | 123 |
|
125 |
| - private OAuth2AuthorizedClientManagerRegistrar authorizedClientManagerRegistrar; |
| 124 | + private final OAuth2AuthorizedClientManagerRegistrar authorizedClientManagerRegistrar; |
| 125 | + |
| 126 | + OAuth2ClientWebMvcSecurityConfiguration(ObjectProvider<OAuth2AuthorizedClientManager> authorizedClientManager, |
| 127 | + ObjectProvider<SecurityContextHolderStrategy> securityContextHolderStrategy, |
| 128 | + OAuth2AuthorizedClientManagerRegistrar authorizedClientManagerRegistrar) { |
| 129 | + this.authorizedClientManager = authorizedClientManager.getIfUnique(); |
| 130 | + this.securityContextHolderStrategy = securityContextHolderStrategy; |
| 131 | + this.authorizedClientManagerRegistrar = authorizedClientManagerRegistrar; |
| 132 | + } |
126 | 133 |
|
127 | 134 | @Override
|
128 | 135 | public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
|
129 | 136 | OAuth2AuthorizedClientManager authorizedClientManager = getAuthorizedClientManager();
|
130 | 137 | if (authorizedClientManager != null) {
|
131 | 138 | OAuth2AuthorizedClientArgumentResolver resolver = new OAuth2AuthorizedClientArgumentResolver(
|
132 | 139 | authorizedClientManager);
|
133 |
| - if (this.securityContextHolderStrategy != null) { |
134 |
| - resolver.setSecurityContextHolderStrategy(this.securityContextHolderStrategy); |
135 |
| - } |
| 140 | + this.securityContextHolderStrategy.ifAvailable(resolver::setSecurityContextHolderStrategy); |
136 | 141 | argumentResolvers.add(resolver);
|
137 | 142 | }
|
138 | 143 | }
|
139 | 144 |
|
140 |
| - @Autowired(required = false) |
141 |
| - void setAuthorizedClientManager(List<OAuth2AuthorizedClientManager> authorizedClientManagers) { |
142 |
| - if (authorizedClientManagers.size() == 1) { |
143 |
| - this.authorizedClientManager = authorizedClientManagers.get(0); |
144 |
| - } |
145 |
| - } |
146 |
| - |
147 |
| - @Autowired(required = false) |
148 |
| - void setSecurityContextHolderStrategy(SecurityContextHolderStrategy strategy) { |
149 |
| - this.securityContextHolderStrategy = strategy; |
150 |
| - } |
151 |
| - |
152 |
| - @Autowired |
153 |
| - void setAuthorizedClientManagerRegistrar( |
154 |
| - OAuth2AuthorizedClientManagerRegistrar authorizedClientManagerRegistrar) { |
155 |
| - this.authorizedClientManagerRegistrar = authorizedClientManagerRegistrar; |
156 |
| - } |
157 |
| - |
158 | 145 | private OAuth2AuthorizedClientManager getAuthorizedClientManager() {
|
159 | 146 | if (this.authorizedClientManager != null) {
|
160 | 147 | return this.authorizedClientManager;
|
|
0 commit comments