6
6
import static com .github .throyer .common .springboot .constants .SECURITY .LOGIN_ERROR_URL ;
7
7
import static com .github .throyer .common .springboot .constants .SECURITY .LOGIN_URL ;
8
8
import static com .github .throyer .common .springboot .constants .SECURITY .LOGOUT_URL ;
9
+ import static com .github .throyer .common .springboot .constants .SECURITY .PASSWORD_ENCODER ;
9
10
import static com .github .throyer .common .springboot .constants .SECURITY .PASSWORD_PARAMETER ;
10
11
import static com .github .throyer .common .springboot .constants .SECURITY .PUBLIC_API_ROUTES ;
11
12
import static com .github .throyer .common .springboot .constants .SECURITY .SESSION_COOKIE_NAME ;
25
26
import org .springframework .context .annotation .Bean ;
26
27
import org .springframework .context .annotation .Configuration ;
27
28
import org .springframework .core .annotation .Order ;
29
+ import org .springframework .security .authentication .AuthenticationManager ;
30
+ import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
31
+ import org .springframework .security .config .annotation .authentication .configuration .AuthenticationConfiguration ;
28
32
import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
29
33
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
30
34
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
@@ -46,13 +50,29 @@ public class SpringSecurityConfiguration {
46
50
47
51
@ Autowired
48
52
public SpringSecurityConfiguration (
49
- SessionService sessionService ,
50
- AuthorizationMiddleware filter
53
+ SessionService sessionService ,
54
+ AuthorizationMiddleware filter
51
55
) {
52
56
this .sessionService = sessionService ;
53
57
this .filter = filter ;
54
58
}
55
59
60
+ @ Autowired
61
+ protected void globalConfiguration (
62
+ AuthenticationManagerBuilder authentication
63
+ ) throws Exception {
64
+ authentication
65
+ .userDetailsService (sessionService )
66
+ .passwordEncoder (PASSWORD_ENCODER );
67
+ }
68
+
69
+ @ Bean
70
+ public AuthenticationManager authenticationManager (
71
+ AuthenticationConfiguration configuration
72
+ ) throws Exception {
73
+ return configuration .getAuthenticationManager ();
74
+ }
75
+
56
76
@ Bean
57
77
public WebSecurityCustomizer webSecurityCustomizer () {
58
78
return (web ) -> web .ignoring ().antMatchers (STATIC_FILES );
@@ -74,8 +94,7 @@ public SecurityFilterChain api(HttpSecurity http) throws Exception {
74
94
.disable ()
75
95
.exceptionHandling ()
76
96
.authenticationEntryPoint ((request , response , exception ) -> forbidden (response ))
77
- .and ()
78
- .userDetailsService (sessionService )
97
+ .and ()
79
98
.sessionManagement ()
80
99
.sessionCreationPolicy (STATELESS )
81
100
.and ()
@@ -100,17 +119,15 @@ public SecurityFilterChain app(HttpSecurity http) throws Exception {
100
119
.authenticated ()
101
120
.and ()
102
121
.csrf ()
103
- .disable ()
104
- .userDetailsService (sessionService )
122
+ .disable ()
105
123
.formLogin ()
106
124
.loginPage (LOGIN_URL )
107
125
.failureUrl (LOGIN_ERROR_URL )
108
126
.defaultSuccessUrl (HOME_URL )
109
127
.usernameParameter (USERNAME_PARAMETER )
110
128
.passwordParameter (PASSWORD_PARAMETER )
111
129
.and ()
112
- .rememberMe ()
113
- .userDetailsService (sessionService )
130
+ .rememberMe ()
114
131
.key (TOKEN_SECRET )
115
132
.tokenValiditySeconds (DAY_MILLISECONDS )
116
133
.and ()
0 commit comments