7
7
import org .springframework .context .annotation .Configuration ;
8
8
import org .springframework .data .jpa .repository .config .EnableJpaAuditing ;
9
9
import org .springframework .data .web .config .EnableSpringDataWebSupport ;
10
- import org .springframework .http .HttpMethod ;
11
10
import org .springframework .scheduling .annotation .EnableAsync ;
12
11
import org .springframework .security .authentication .AuthenticationManager ;
13
12
import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
14
13
import org .springframework .security .config .annotation .web .WebSecurityConfigurer ;
15
14
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
16
15
import org .springframework .security .config .annotation .web .builders .WebSecurity ;
17
16
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
18
- import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
19
17
import org .springframework .security .core .userdetails .UserDetailsService ;
20
18
import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
21
19
import org .springframework .security .crypto .password .PasswordEncoder ;
20
+ import org .springframework .security .web .SecurityFilterChain ;
22
21
import org .springframework .security .web .authentication .AuthenticationSuccessHandler ;
23
22
import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
24
23
import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
37
36
@ EnableConfigurationProperties ({
38
37
SimpleworklistProperties .class
39
38
})
40
- public class WebSecurityConfig extends WebSecurityConfigurerAdapter implements WebSecurityConfigurer <WebSecurity > {
39
+ public class WebSecurityConfig implements WebSecurityConfigurer <WebSecurity > {
41
40
42
41
private final AuthenticationManagerBuilder authenticationManagerBuilder ;
43
42
private final AuthenticationSuccessHandler authenticationSuccessHandler ;
@@ -56,8 +55,48 @@ public WebSecurityConfig(
56
55
this .simpleworklistProperties = simpleworklistProperties ;
57
56
}
58
57
58
+ @ Bean
59
+ public UserDetailsService userDetailsService (){
60
+ return this .applicationUserDetailsService ;
61
+ }
62
+
63
+ /**
64
+ * @see <a href="https://bcrypt-generator.com/">bcrypt-generator.com</a>
65
+ * @return PasswordEncoder encoder
66
+ */
67
+ @ Bean
68
+ public PasswordEncoder encoder (){
69
+ int strength = simpleworklistProperties .getWebSecurity ().getStrengthBCryptPasswordEncoder ();
70
+ return new BCryptPasswordEncoder (strength );
71
+ }
72
+
73
+ @ Bean
74
+ public AuthenticationManager authenticationManager () throws Exception {
75
+ return authenticationManagerBuilder
76
+ .userDetailsService (userDetailsService ())
77
+ .passwordEncoder (encoder ()).and ().build ();
78
+ }
79
+
80
+ @ Bean
81
+ public UsernamePasswordAuthenticationFilter authenticationFilter () throws Exception {
82
+ UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter ();
83
+ filter .setAuthenticationManager (authenticationManager ());
84
+ filter .setFilterProcessesUrl (simpleworklistProperties .getWebSecurity ().getLoginProcessingUrl ());
85
+ return filter ;
86
+ }
87
+
88
+ @ Override
89
+ public void init (WebSecurity builder ) throws Exception {
90
+
91
+ }
92
+
59
93
@ Override
60
- protected void configure (HttpSecurity http ) throws Exception {
94
+ public void configure (WebSecurity builder ) throws Exception {
95
+
96
+ }
97
+
98
+ @ Bean
99
+ public SecurityFilterChain securityFilterChain (HttpSecurity http ) throws Exception {
61
100
http
62
101
.headers ()
63
102
.disable ()
@@ -88,35 +127,7 @@ protected void configure(HttpSecurity http) throws Exception {
88
127
.deleteCookies (simpleworklistProperties .getWebSecurity ().getCookieNamesToClear ())
89
128
.invalidateHttpSession (simpleworklistProperties .getWebSecurity ().getInvalidateHttpSession ())
90
129
.permitAll ();
130
+ return http .build ();
91
131
}
92
132
93
- @ Bean
94
- public UserDetailsService userDetailsService (){
95
- return this .applicationUserDetailsService ;
96
- }
97
-
98
- /**
99
- * @see <a href="https://bcrypt-generator.com/">bcrypt-generator.com</a>
100
- * @return PasswordEncoder encoder
101
- */
102
- @ Bean
103
- public PasswordEncoder encoder (){
104
- int strength = simpleworklistProperties .getWebSecurity ().getStrengthBCryptPasswordEncoder ();
105
- return new BCryptPasswordEncoder (strength );
106
- }
107
-
108
- @ Bean
109
- public AuthenticationManager authenticationManager () throws Exception {
110
- return authenticationManagerBuilder
111
- .userDetailsService (userDetailsService ())
112
- .passwordEncoder (encoder ()).and ().build ();
113
- }
114
-
115
- @ Bean
116
- public UsernamePasswordAuthenticationFilter authenticationFilter () throws Exception {
117
- UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter ();
118
- filter .setAuthenticationManager (authenticationManager ());
119
- filter .setFilterProcessesUrl (simpleworklistProperties .getWebSecurity ().getLoginProcessingUrl ());
120
- return filter ;
121
- }
122
133
}
0 commit comments