4
4
import org .springframework .context .annotation .Bean ;
5
5
import org .springframework .context .annotation .Configuration ;
6
6
import org .springframework .security .authentication .AuthenticationManager ;
7
- import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
7
+ import org .springframework .security .authentication .dao .DaoAuthenticationProvider ;
8
+ //import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
9
+ import org .springframework .security .config .annotation .authentication .configuration .AuthenticationConfiguration ;
8
10
import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
9
11
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
10
- import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
11
- import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
12
+ // import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
13
+ // import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
12
14
import org .springframework .security .config .http .SessionCreationPolicy ;
13
15
import org .springframework .security .crypto .bcrypt .BCryptPasswordEncoder ;
14
16
import org .springframework .security .crypto .password .PasswordEncoder ;
17
+ import org .springframework .security .web .SecurityFilterChain ;
15
18
import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
16
19
17
20
import com .bezkoder .spring .login .security .jwt .AuthEntryPointJwt ;
18
21
import com .bezkoder .spring .login .security .jwt .AuthTokenFilter ;
19
22
import com .bezkoder .spring .login .security .services .UserDetailsServiceImpl ;
20
23
21
24
@ Configuration
22
- @ EnableWebSecurity
25
+ // @EnableWebSecurity
23
26
@ EnableGlobalMethodSecurity (
24
27
// securedEnabled = true,
25
28
// jsr250Enabled = true,
26
29
prePostEnabled = true )
27
- public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
30
+ public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
28
31
@ Autowired
29
32
UserDetailsServiceImpl userDetailsService ;
30
33
@@ -36,31 +39,62 @@ public AuthTokenFilter authenticationJwtTokenFilter() {
36
39
return new AuthTokenFilter ();
37
40
}
38
41
39
- @ Override
40
- public void configure (AuthenticationManagerBuilder authenticationManagerBuilder ) throws Exception {
41
- authenticationManagerBuilder .userDetailsService (userDetailsService ).passwordEncoder (passwordEncoder ());
42
- }
42
+ // @Override
43
+ // public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
44
+ // authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
45
+ // }
43
46
44
47
@ Bean
45
- @ Override
46
- public AuthenticationManager authenticationManagerBean () throws Exception {
47
- return super .authenticationManagerBean ();
48
+ public DaoAuthenticationProvider authenticationProvider () {
49
+ DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider ();
50
+
51
+ authProvider .setUserDetailsService (userDetailsService );
52
+ authProvider .setPasswordEncoder (passwordEncoder ());
53
+
54
+ return authProvider ;
55
+ }
56
+
57
+ // @Bean
58
+ // @Override
59
+ // public AuthenticationManager authenticationManagerBean() throws Exception {
60
+ // return super.authenticationManagerBean();
61
+ // }
62
+
63
+ @ Bean
64
+ public AuthenticationManager authenticationManager (AuthenticationConfiguration authConfig ) throws Exception {
65
+ return authConfig .getAuthenticationManager ();
48
66
}
49
67
50
68
@ Bean
51
69
public PasswordEncoder passwordEncoder () {
52
70
return new BCryptPasswordEncoder ();
53
71
}
54
72
55
- @ Override
56
- protected void configure (HttpSecurity http ) throws Exception {
73
+ // @Override
74
+ // protected void configure(HttpSecurity http) throws Exception {
75
+ // http.cors().and().csrf().disable()
76
+ // .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
77
+ // .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
78
+ // .authorizeRequests().antMatchers("/api/auth/**").permitAll()
79
+ // .antMatchers("/api/test/**").permitAll()
80
+ // .anyRequest().authenticated();
81
+ //
82
+ // http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
83
+ // }
84
+
85
+ @ Bean
86
+ public SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
57
87
http .cors ().and ().csrf ().disable ()
58
- .exceptionHandling ().authenticationEntryPoint (unauthorizedHandler ).and ()
59
- .sessionManagement ().sessionCreationPolicy (SessionCreationPolicy .STATELESS ).and ()
60
- .authorizeRequests ().antMatchers ("/api/auth/**" ).permitAll ()
61
- .antMatchers ("/api/test/**" ).permitAll ()
62
- .anyRequest ().authenticated ();
88
+ .exceptionHandling ().authenticationEntryPoint (unauthorizedHandler ).and ()
89
+ .sessionManagement ().sessionCreationPolicy (SessionCreationPolicy .STATELESS ).and ()
90
+ .authorizeRequests ().antMatchers ("/api/auth/**" ).permitAll ()
91
+ .antMatchers ("/api/test/**" ).permitAll ()
92
+ .anyRequest ().authenticated ();
93
+
94
+ http .authenticationProvider (authenticationProvider ());
63
95
64
96
http .addFilterBefore (authenticationJwtTokenFilter (), UsernamePasswordAuthenticationFilter .class );
97
+
98
+ return http .build ();
65
99
}
66
100
}
0 commit comments