|
32 | 32 | @EnableMethodSecurity(prePostEnabled = true) |
33 | 33 | public class WebSecurityConfig { |
34 | 34 |
|
35 | | - @Autowired |
36 | | - public PasswordEncoder passwordEncoder; |
| 35 | + @Autowired |
| 36 | + public PasswordEncoder passwordEncoder; |
37 | 37 |
|
38 | | - @Autowired |
39 | | - private CustomUserDetailsService jwtUserDetailsService; |
| 38 | + @Autowired |
| 39 | + private CustomUserDetailsService jwtUserDetailsService; |
40 | 40 |
|
41 | | - @Autowired |
42 | | - private RestAuthenticationEntryPoint restAuthenticationEntryPoint; |
| 41 | + @Autowired |
| 42 | + private RestAuthenticationEntryPoint restAuthenticationEntryPoint; |
43 | 43 |
|
44 | | - @Autowired |
45 | | - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { |
46 | | - auth.userDetailsService(jwtUserDetailsService) |
47 | | - .passwordEncoder(passwordEncoder); |
48 | | - } |
| 44 | + @Autowired |
| 45 | + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { |
| 46 | + auth.userDetailsService(jwtUserDetailsService).passwordEncoder(passwordEncoder); |
| 47 | + } |
49 | 48 |
|
50 | | - @Autowired |
51 | | - TokenHelper tokenHelper; |
| 49 | + @Autowired |
| 50 | + TokenHelper tokenHelper; |
52 | 51 |
|
53 | | - @Bean |
54 | | - public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) |
55 | | - throws Exception { |
56 | | - return authenticationConfiguration.getAuthenticationManager(); |
57 | | - } |
| 52 | + @Bean |
| 53 | + public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) |
| 54 | + throws Exception { |
| 55 | + return authenticationConfiguration.getAuthenticationManager(); |
| 56 | + } |
58 | 57 |
|
59 | | - @Bean |
60 | | - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
| 58 | + @Bean |
| 59 | + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
61 | 60 |
|
62 | | - http |
63 | | - .addFilterBefore(new TokenAuthenticationFilter(tokenHelper, jwtUserDetailsService), |
64 | | - BasicAuthenticationFilter.class) |
65 | | - .authorizeHttpRequests(authorize -> authorize |
66 | | - .requestMatchers( |
67 | | - antMatcher(HttpMethod.GET, "/"), |
68 | | - antMatcher(HttpMethod.GET, "/auth/**"), |
69 | | - antMatcher(HttpMethod.GET, "/webjars/**"), |
70 | | - antMatcher(HttpMethod.GET, "/*.html"), |
71 | | - antMatcher(HttpMethod.GET, "/favicon.ico"), |
72 | | - antMatcher(HttpMethod.GET, "/**/*.html"), |
73 | | - antMatcher(HttpMethod.GET, "/**/*.css"), |
74 | | - antMatcher(HttpMethod.GET, "/**/*.js")) |
75 | | - .permitAll() |
76 | | - .requestMatchers("/auth/**").permitAll() |
77 | | - .anyRequest().authenticated()) |
78 | | - .sessionManagement(sec -> sec.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) |
79 | | - .exceptionHandling( |
80 | | - exceptionHandler -> exceptionHandler.authenticationEntryPoint(restAuthenticationEntryPoint)) |
81 | | - .csrf(csrf -> csrf.disable()); |
| 61 | + http.addFilterBefore(new TokenAuthenticationFilter(tokenHelper, jwtUserDetailsService), |
| 62 | + BasicAuthenticationFilter.class) |
| 63 | + .authorizeHttpRequests(authorize -> authorize |
| 64 | + .requestMatchers(antMatcher(HttpMethod.GET, "/"), antMatcher(HttpMethod.GET, "/auth/**"), |
| 65 | + antMatcher(HttpMethod.GET, "/webjars/**"), antMatcher(HttpMethod.GET, "/*.html"), |
| 66 | + antMatcher(HttpMethod.GET, "/favicon.ico"), antMatcher(HttpMethod.GET, "/**/*.html"), |
| 67 | + antMatcher(HttpMethod.GET, "/**/*.css"), antMatcher(HttpMethod.GET, "/**/*.js")) |
| 68 | + .permitAll().requestMatchers("/auth/**").permitAll().anyRequest().authenticated()) |
| 69 | + .sessionManagement(sec -> sec.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) |
| 70 | + .exceptionHandling( |
| 71 | + exceptionHandler -> exceptionHandler.authenticationEntryPoint(restAuthenticationEntryPoint)) |
| 72 | + .csrf(csrf -> csrf.disable()); |
82 | 73 |
|
83 | | - return http.build(); |
84 | | - } |
| 74 | + return http.build(); |
| 75 | + } |
85 | 76 |
|
86 | | - @Bean |
87 | | - public WebSecurityCustomizer webSecurityCustomizer() { |
88 | | - // TokenAuthenticationFilter will ignore the below paths |
89 | | - return (web) -> { |
90 | | - web.ignoring() |
91 | | - .requestMatchers(HttpMethod.POST, "/auth/login") |
92 | | - .requestMatchers( |
93 | | - antMatcher(HttpMethod.GET, "/"), |
94 | | - antMatcher(HttpMethod.GET, "/webjars/**"), |
95 | | - antMatcher(HttpMethod.GET, "/*.html"), |
96 | | - antMatcher(HttpMethod.GET, "/favicon.ico"), |
97 | | - antMatcher(HttpMethod.GET, "/**/*.html"), |
98 | | - antMatcher(HttpMethod.GET, "/**path/*.css"), |
99 | | - antMatcher(HttpMethod.GET, "/**path/*.js")); |
100 | | - }; |
101 | | - } |
| 77 | + @Bean |
| 78 | + public WebSecurityCustomizer webSecurityCustomizer() { |
| 79 | + // TokenAuthenticationFilter will ignore the below paths |
| 80 | + return (web) -> { |
| 81 | + web.ignoring().requestMatchers(HttpMethod.POST, "/auth/login").requestMatchers( |
| 82 | + antMatcher(HttpMethod.GET, "/"), antMatcher(HttpMethod.GET, "/webjars/**"), |
| 83 | + antMatcher(HttpMethod.GET, "/*.html"), antMatcher(HttpMethod.GET, "/favicon.ico"), |
| 84 | + antMatcher(HttpMethod.GET, "/**/*.html"), antMatcher(HttpMethod.GET, "/**path/*.css"), |
| 85 | + antMatcher(HttpMethod.GET, "/**path/*.js")); |
| 86 | + }; |
| 87 | + } |
102 | 88 | } |
0 commit comments