1
1
/*
2
- * Copyright 2002-2022 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.
22
22
23
23
import jakarta .servlet .Filter ;
24
24
25
- import org .springframework .beans .factory .BeanClassLoaderAware ;
25
+ import org .springframework .beans .factory .ObjectProvider ;
26
26
import org .springframework .beans .factory .annotation .Autowired ;
27
27
import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
28
28
import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
65
65
* @see WebSecurity
66
66
*/
67
67
@ Configuration (proxyBeanMethods = false )
68
- public class WebSecurityConfiguration implements ImportAware , BeanClassLoaderAware {
68
+ public class WebSecurityConfiguration implements ImportAware {
69
69
70
70
private WebSecurity webSecurity ;
71
71
72
72
private Boolean debugEnabled ;
73
73
74
- private List <SecurityConfigurer <Filter , WebSecurity >> webSecurityConfigurers ;
75
-
76
74
private List <SecurityFilterChain > securityFilterChains = Collections .emptyList ();
77
75
78
76
private List <WebSecurityCustomizer > webSecurityCustomizers = Collections .emptyList ();
79
77
80
- private ClassLoader beanClassLoader ;
81
-
82
- @ Autowired (required = false )
83
- private HttpSecurity httpSecurity ;
84
-
85
78
@ Bean
86
79
public static DelegatingApplicationListener delegatingApplicationListener () {
87
80
return new DelegatingApplicationListener ();
@@ -99,14 +92,15 @@ public SecurityExpressionHandler<FilterInvocation> webSecurityExpressionHandler(
99
92
* @throws Exception
100
93
*/
101
94
@ Bean (name = AbstractSecurityWebApplicationInitializer .DEFAULT_FILTER_NAME )
102
- public Filter springSecurityFilterChain () throws Exception {
95
+ public Filter springSecurityFilterChain (ObjectProvider < HttpSecurity > provider ) throws Exception {
103
96
boolean hasFilterChain = !this .securityFilterChains .isEmpty ();
104
97
if (!hasFilterChain ) {
105
98
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 ();
110
104
});
111
105
}
112
106
for (SecurityFilterChain securityFilterChain : this .securityFilterChains ) {
@@ -164,7 +158,6 @@ public void setFilterChainProxySecurityConfigurer(ObjectPostProcessor<Object> ob
164
158
for (SecurityConfigurer <Filter , WebSecurity > webSecurityConfigurer : webSecurityConfigurers ) {
165
159
this .webSecurity .apply (webSecurityConfigurer );
166
160
}
167
- this .webSecurityConfigurers = webSecurityConfigurers ;
168
161
}
169
162
170
163
@ Autowired (required = false )
@@ -193,11 +186,6 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
193
186
}
194
187
}
195
188
196
- @ Override
197
- public void setBeanClassLoader (ClassLoader classLoader ) {
198
- this .beanClassLoader = classLoader ;
199
- }
200
-
201
189
/**
202
190
* A custom version of the Spring provided AnnotationAwareOrderComparator that uses
203
191
* {@link AnnotationUtils#findAnnotation(Class, Class)} to look on super class
0 commit comments