11/*
2- * Copyright 2002-2022 the original author or authors.
2+ * Copyright 2002-2024 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2222
2323import jakarta .servlet .Filter ;
2424
25- import org .springframework .beans .factory .BeanClassLoaderAware ;
25+ import org .springframework .beans .factory .ObjectProvider ;
2626import org .springframework .beans .factory .annotation .Autowired ;
2727import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
2828import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
6565 * @see WebSecurity
6666 */
6767@ Configuration (proxyBeanMethods = false )
68- public class WebSecurityConfiguration implements ImportAware , BeanClassLoaderAware {
68+ public class WebSecurityConfiguration implements ImportAware {
6969
7070 private WebSecurity webSecurity ;
7171
7272 private Boolean debugEnabled ;
7373
74- private List <SecurityConfigurer <Filter , WebSecurity >> webSecurityConfigurers ;
75-
7674 private List <SecurityFilterChain > securityFilterChains = Collections .emptyList ();
7775
7876 private List <WebSecurityCustomizer > webSecurityCustomizers = Collections .emptyList ();
7977
80- private ClassLoader beanClassLoader ;
81-
82- @ Autowired (required = false )
83- private HttpSecurity httpSecurity ;
84-
8578 @ Bean
8679 public static DelegatingApplicationListener delegatingApplicationListener () {
8780 return new DelegatingApplicationListener ();
@@ -99,14 +92,15 @@ public SecurityExpressionHandler<FilterInvocation> webSecurityExpressionHandler(
9992 * @throws Exception
10093 */
10194 @ Bean (name = AbstractSecurityWebApplicationInitializer .DEFAULT_FILTER_NAME )
102- public Filter springSecurityFilterChain () throws Exception {
95+ public Filter springSecurityFilterChain (ObjectProvider < HttpSecurity > provider ) throws Exception {
10396 boolean hasFilterChain = !this .securityFilterChains .isEmpty ();
10497 if (!hasFilterChain ) {
10598 this .webSecurity .addSecurityFilterChainBuilder (() -> {
106- this .httpSecurity .authorizeHttpRequests ((authorize ) -> authorize .anyRequest ().authenticated ());
107- this .httpSecurity .formLogin (Customizer .withDefaults ());
108- this .httpSecurity .httpBasic (Customizer .withDefaults ());
109- return this .httpSecurity .build ();
99+ HttpSecurity httpSecurity = provider .getObject ();
100+ httpSecurity .authorizeHttpRequests ((authorize ) -> authorize .anyRequest ().authenticated ());
101+ httpSecurity .formLogin (Customizer .withDefaults ());
102+ httpSecurity .httpBasic (Customizer .withDefaults ());
103+ return httpSecurity .build ();
110104 });
111105 }
112106 for (SecurityFilterChain securityFilterChain : this .securityFilterChains ) {
@@ -164,7 +158,6 @@ public void setFilterChainProxySecurityConfigurer(ObjectPostProcessor<Object> ob
164158 for (SecurityConfigurer <Filter , WebSecurity > webSecurityConfigurer : webSecurityConfigurers ) {
165159 this .webSecurity .apply (webSecurityConfigurer );
166160 }
167- this .webSecurityConfigurers = webSecurityConfigurers ;
168161 }
169162
170163 @ Autowired (required = false )
@@ -193,11 +186,6 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
193186 }
194187 }
195188
196- @ Override
197- public void setBeanClassLoader (ClassLoader classLoader ) {
198- this .beanClassLoader = classLoader ;
199- }
200-
201189 /**
202190 * A custom version of the Spring provided AnnotationAwareOrderComparator that uses
203191 * {@link AnnotationUtils#findAnnotation(Class, Class)} to look on super class
0 commit comments