|
29 | 29 | import org.springframework.beans.BeanMetadataElement;
|
30 | 30 | import org.springframework.beans.BeansException;
|
31 | 31 | import org.springframework.beans.factory.FactoryBean;
|
32 |
| -import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter; |
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;
|
36 | 35 | import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
37 | 36 | import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
|
38 | 37 | import org.springframework.beans.factory.support.ManagedList;
|
39 |
| -import org.springframework.beans.factory.support.RegisteredBean; |
40 | 38 | import org.springframework.context.ApplicationContext;
|
41 | 39 | import org.springframework.context.ApplicationContextAware;
|
42 | 40 | import org.springframework.context.annotation.Bean;
|
@@ -113,79 +111,56 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
|
113 | 111 | }
|
114 | 112 | }
|
115 | 113 |
|
116 |
| - @Bean |
117 |
| - static SpringSecurityHandlerMappingIntrospectorBeanDefinitionRegistryPostProcessor springSecurityHandlerMappingIntrospectorBeanDefinitionRegistryPostProcessor() { |
118 |
| - return new SpringSecurityHandlerMappingIntrospectorBeanDefinitionRegistryPostProcessor(); |
119 |
| - } |
120 |
| - |
121 | 114 | /**
|
122 |
| - * Used to ensure Spring MVC request matching is cached. Creates a |
123 |
| - * {@link BeanDefinitionRegistryPostProcessor} that detects if a bean named |
| 115 | + * Used to ensure Spring MVC request matching is cached. |
| 116 | + * |
| 117 | + * Creates a {@link BeanDefinitionRegistryPostProcessor} that detects if a bean named |
124 | 118 | * HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME is defined. If so, it moves the
|
125 | 119 | * AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME to another bean name
|
126 | 120 | * and then adds a {@link CompositeFilter} that contains
|
127 | 121 | * {@link HandlerMappingIntrospector#createCacheFilter()} and the original
|
128 | 122 | * FilterChainProxy under the original Bean name.
|
129 |
| - * |
130 | 123 | * @return
|
131 | 124 | */
|
132 |
| - static class SpringSecurityHandlerMappingIntrospectorBeanDefinitionRegistryPostProcessor |
133 |
| - implements BeanDefinitionRegistryPostProcessor { |
134 |
| - |
135 |
| - @Override |
136 |
| - public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { |
137 |
| - if (!registry.containsBeanDefinition(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) { |
138 |
| - return; |
| 125 | + @Bean |
| 126 | + static BeanDefinitionRegistryPostProcessor springSecurityHandlerMappingIntrospectorBeanDefinitionRegistryPostProcessor() { |
| 127 | + return new BeanDefinitionRegistryPostProcessor() { |
| 128 | + @Override |
| 129 | + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { |
139 | 130 | }
|
140 | 131 |
|
141 |
| - BeanDefinition hmiRequestTransformer = BeanDefinitionBuilder |
142 |
| - .rootBeanDefinition(HandlerMappingIntrospectorRequestTransformer.class) |
143 |
| - .addConstructorArgReference(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME) |
144 |
| - .getBeanDefinition(); |
145 |
| - registry.registerBeanDefinition(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME + "RequestTransformer", |
146 |
| - hmiRequestTransformer); |
147 |
| - |
148 |
| - BeanDefinition filterChainProxy = registry |
149 |
| - .getBeanDefinition(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME); |
150 |
| - |
151 |
| - BeanDefinitionBuilder hmiCacheFilterBldr = BeanDefinitionBuilder |
152 |
| - .rootBeanDefinition(HandlerMappingIntrospectorCachFilterFactoryBean.class) |
153 |
| - .setRole(BeanDefinition.ROLE_INFRASTRUCTURE); |
154 |
| - |
155 |
| - ManagedList<BeanMetadataElement> filters = new ManagedList<>(); |
156 |
| - filters.add(hmiCacheFilterBldr.getBeanDefinition()); |
157 |
| - filters.add(filterChainProxy); |
158 |
| - BeanDefinitionBuilder compositeSpringSecurityFilterChainBldr = BeanDefinitionBuilder |
159 |
| - .rootBeanDefinition(CompositeFilterChainProxy.class) |
160 |
| - .addConstructorArgValue(filters); |
161 |
| - |
162 |
| - registry.removeBeanDefinition(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME); |
163 |
| - registry.registerBeanDefinition(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME, |
164 |
| - compositeSpringSecurityFilterChainBldr.getBeanDefinition()); |
165 |
| - } |
166 |
| - |
167 |
| - @Override |
168 |
| - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { |
169 |
| - |
170 |
| - } |
171 |
| - |
172 |
| - } |
173 |
| - |
174 |
| - /** |
175 |
| - * Used to exclude the |
176 |
| - * {@link SpringSecurityHandlerMappingIntrospectorBeanDefinitionRegistryPostProcessor} |
177 |
| - * from AOT processing. See <a href= |
178 |
| - * "https://github.com/spring-projects/spring-security/issues/14362">gh-14362</a> |
179 |
| - */ |
180 |
| - static class SpringSecurityHandlerMappingIntrospectorBeanRegistrationExcludeFilter |
181 |
| - implements BeanRegistrationExcludeFilter { |
182 |
| - |
183 |
| - @Override |
184 |
| - public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) { |
185 |
| - Class<?> beanClass = registeredBean.getBeanClass(); |
186 |
| - return SpringSecurityHandlerMappingIntrospectorBeanDefinitionRegistryPostProcessor.class == beanClass; |
187 |
| - } |
| 132 | + @Override |
| 133 | + public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { |
| 134 | + if (!registry.containsBeanDefinition(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) { |
| 135 | + return; |
| 136 | + } |
188 | 137 |
|
| 138 | + BeanDefinition hmiRequestTransformer = BeanDefinitionBuilder |
| 139 | + .rootBeanDefinition(HandlerMappingIntrospectorRequestTransformer.class) |
| 140 | + .addConstructorArgReference(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME) |
| 141 | + .getBeanDefinition(); |
| 142 | + registry.registerBeanDefinition(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME + "RequestTransformer", |
| 143 | + hmiRequestTransformer); |
| 144 | + |
| 145 | + BeanDefinition filterChainProxy = registry |
| 146 | + .getBeanDefinition(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME); |
| 147 | + |
| 148 | + BeanDefinitionBuilder hmiCacheFilterBldr = BeanDefinitionBuilder |
| 149 | + .rootBeanDefinition(HandlerMappingIntrospectorCachFilterFactoryBean.class) |
| 150 | + .setRole(BeanDefinition.ROLE_INFRASTRUCTURE); |
| 151 | + |
| 152 | + ManagedList<BeanMetadataElement> filters = new ManagedList<>(); |
| 153 | + filters.add(hmiCacheFilterBldr.getBeanDefinition()); |
| 154 | + filters.add(filterChainProxy); |
| 155 | + BeanDefinitionBuilder compositeSpringSecurityFilterChainBldr = BeanDefinitionBuilder |
| 156 | + .rootBeanDefinition(CompositeFilterChainProxy.class) |
| 157 | + .addConstructorArgValue(filters); |
| 158 | + |
| 159 | + registry.removeBeanDefinition(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME); |
| 160 | + registry.registerBeanDefinition(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME, |
| 161 | + compositeSpringSecurityFilterChainBldr.getBeanDefinition()); |
| 162 | + } |
| 163 | + }; |
189 | 164 | }
|
190 | 165 |
|
191 | 166 | /**
|
|
0 commit comments