11package com .bezkoder .springjwt .security ;
22
3- import com .bezkoder .springjwt .security .jwt .AuthEntryPointJwt ;
4- import com .bezkoder .springjwt .security .jwt .AuthTokenFilter ;
5- import com .bezkoder .springjwt .security .services .UserDetailsServiceImpl ;
6- import lombok .RequiredArgsConstructor ;
3+ import org .springframework .beans .factory .annotation .Autowired ;
74import org .springframework .context .annotation .Bean ;
85import org .springframework .context .annotation .Configuration ;
96import org .springframework .security .authentication .AuthenticationManager ;
2017import org .springframework .security .web .SecurityFilterChain ;
2118import org .springframework .security .web .authentication .UsernamePasswordAuthenticationFilter ;
2219
23- @ RequiredArgsConstructor
20+ import com .bezkoder .springjwt .security .jwt .AuthEntryPointJwt ;
21+ import com .bezkoder .springjwt .security .jwt .AuthTokenFilter ;
22+ import com .bezkoder .springjwt .security .services .UserDetailsServiceImpl ;
23+
2424@ Configuration
2525@ EnableGlobalMethodSecurity (
26- // securedEnabled = true,
27- // jsr250Enabled = true,
28- prePostEnabled = true )
26+ // securedEnabled = true,
27+ // jsr250Enabled = true,
28+ prePostEnabled = true )
2929public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
30- @ Autowired
31- UserDetailsServiceImpl userDetailsService ;
32-
33- private final UserDetailsServiceImpl userDetailsService ;
30+ @ Autowired
31+ UserDetailsServiceImpl userDetailsService ;
3432
35- private final AuthEntryPointJwt unauthorizedHandler ;
33+ @ Autowired
34+ private AuthEntryPointJwt unauthorizedHandler ;
3635
3736 @ Bean
3837 public AuthTokenFilter authenticationJwtTokenFilter () {
@@ -43,27 +42,27 @@ public AuthTokenFilter authenticationJwtTokenFilter() {
4342// public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
4443// authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
4544// }
46-
47- @ Bean
48- public DaoAuthenticationProvider authenticationProvider () {
49- DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider ();
50-
51- authProvider .setUserDetailsService (userDetailsService );
52- authProvider .setPasswordEncoder (passwordEncoder ());
53-
54- return authProvider ;
55- }
45+
46+ @ Bean
47+ public DaoAuthenticationProvider authenticationProvider () {
48+ DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider ();
49+
50+ authProvider .setUserDetailsService (userDetailsService );
51+ authProvider .setPasswordEncoder (passwordEncoder ());
52+
53+ return authProvider ;
54+ }
5655
5756// @Bean
5857// @Override
5958// public AuthenticationManager authenticationManagerBean() throws Exception {
6059// return super.authenticationManagerBean();
6160// }
62-
63- @ Bean
64- public AuthenticationManager authenticationManager (AuthenticationConfiguration authConfig ) throws Exception {
65- return authConfig .getAuthenticationManager ();
66- }
61+
62+ @ Bean
63+ public AuthenticationManager authenticationManager (AuthenticationConfiguration authConfig ) throws Exception {
64+ return authConfig .getAuthenticationManager ();
65+ }
6766
6867 @ Bean
6968 public PasswordEncoder passwordEncoder () {
@@ -81,21 +80,20 @@ public PasswordEncoder passwordEncoder() {
8180//
8281// http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
8382// }
84-
85- @ Bean
86- public SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
87- http .cors ().and ().csrf ().disable ()
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 ());
95-
96- http .addFilterBefore (authenticationJwtTokenFilter (), UsernamePasswordAuthenticationFilter .class );
97-
98- return http .build ();
99- }
100-
101- }
83+
84+ @ Bean
85+ public SecurityFilterChain filterChain (HttpSecurity http ) throws Exception {
86+ http .cors ().and ().csrf ().disable ()
87+ .exceptionHandling ().authenticationEntryPoint (unauthorizedHandler ).and ()
88+ .sessionManagement ().sessionCreationPolicy (SessionCreationPolicy .STATELESS ).and ()
89+ .authorizeRequests ().antMatchers ("/api/auth/**" ).permitAll ()
90+ .antMatchers ("/api/test/**" ).permitAll ()
91+ .anyRequest ().authenticated ();
92+
93+ http .authenticationProvider (authenticationProvider ());
94+
95+ http .addFilterBefore (authenticationJwtTokenFilter (), UsernamePasswordAuthenticationFilter .class );
96+
97+ return http .build ();
98+ }
99+ }
0 commit comments