66import static com .github .throyer .common .springboot .constants .SECURITY .LOGIN_ERROR_URL ;
77import static com .github .throyer .common .springboot .constants .SECURITY .LOGIN_URL ;
88import static com .github .throyer .common .springboot .constants .SECURITY .LOGOUT_URL ;
9+ import static com .github .throyer .common .springboot .constants .SECURITY .PASSWORD_ENCODER ;
910import static com .github .throyer .common .springboot .constants .SECURITY .PASSWORD_PARAMETER ;
1011import static com .github .throyer .common .springboot .constants .SECURITY .PUBLIC_API_ROUTES ;
1112import static com .github .throyer .common .springboot .constants .SECURITY .SESSION_COOKIE_NAME ;
2526import org .springframework .context .annotation .Bean ;
2627import org .springframework .context .annotation .Configuration ;
2728import 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 ;
2832import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
2933import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
3034import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
@@ -46,13 +50,29 @@ public class SpringSecurityConfiguration {
4650
4751 @ Autowired
4852 public SpringSecurityConfiguration (
49- SessionService sessionService ,
50- AuthorizationMiddleware filter
53+ SessionService sessionService ,
54+ AuthorizationMiddleware filter
5155 ) {
5256 this .sessionService = sessionService ;
5357 this .filter = filter ;
5458 }
5559
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+
5676 @ Bean
5777 public WebSecurityCustomizer webSecurityCustomizer () {
5878 return (web ) -> web .ignoring ().antMatchers (STATIC_FILES );
@@ -74,8 +94,7 @@ public SecurityFilterChain api(HttpSecurity http) throws Exception {
7494 .disable ()
7595 .exceptionHandling ()
7696 .authenticationEntryPoint ((request , response , exception ) -> forbidden (response ))
77- .and ()
78- .userDetailsService (sessionService )
97+ .and ()
7998 .sessionManagement ()
8099 .sessionCreationPolicy (STATELESS )
81100 .and ()
@@ -100,17 +119,15 @@ public SecurityFilterChain app(HttpSecurity http) throws Exception {
100119 .authenticated ()
101120 .and ()
102121 .csrf ()
103- .disable ()
104- .userDetailsService (sessionService )
122+ .disable ()
105123 .formLogin ()
106124 .loginPage (LOGIN_URL )
107125 .failureUrl (LOGIN_ERROR_URL )
108126 .defaultSuccessUrl (HOME_URL )
109127 .usernameParameter (USERNAME_PARAMETER )
110128 .passwordParameter (PASSWORD_PARAMETER )
111129 .and ()
112- .rememberMe ()
113- .userDetailsService (sessionService )
130+ .rememberMe ()
114131 .key (TOKEN_SECRET )
115132 .tokenValiditySeconds (DAY_MILLISECONDS )
116133 .and ()
0 commit comments