| | |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | | import org.springframework.security.web.SecurityFilterChain; |
| | | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; |
| | | import org.springframework.web.cors.CorsConfiguration; |
| | | import org.springframework.web.cors.CorsConfigurationSource; |
| | | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
| | | |
| | | @Configuration |
| | | @EnableWebSecurity |
| | |
| | | @Bean |
| | | public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { |
| | | http |
| | | .cors(cors -> cors.configurationSource(corsConfigurationSource())) |
| | | .csrf(AbstractHttpConfigurer::disable) |
| | | .sessionManagement(session -> session |
| | | .sessionCreationPolicy(SessionCreationPolicy.STATELESS)) |
| | |
| | | } |
| | | |
| | | @Bean |
| | | public CorsConfigurationSource corsConfigurationSource() { |
| | | CorsConfiguration configuration = new CorsConfiguration(); |
| | | configuration.addAllowedOriginPattern("*"); |
| | | configuration.addAllowedMethod("*"); |
| | | configuration.addAllowedHeader("*"); |
| | | configuration.setAllowCredentials(true); |
| | | configuration.addExposedHeader("*"); |
| | | configuration.setMaxAge(3600L); |
| | | |
| | | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| | | source.registerCorsConfiguration("/**", configuration); |
| | | return source; |
| | | } |
| | | |
| | | @Bean |
| | | public PasswordEncoder passwordEncoder() { |
| | | return new BCryptPasswordEncoder(); |
| | | } |