Files
bbps-backend/src/main/java/com/billpaymentservice/bbps/config/SecurityConfig.java
T
2025-11-10 10:11:26 +05:30

29 lines
1.2 KiB
Java

package com.billpaymentservice.bbps.config;
import java.util.Arrays;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
@Configuration
public class SecurityConfig {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(Arrays.asList("*")); // Or use specific origin like "http://localhost:4200"
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
config.setAllowedHeaders(Arrays.asList("*"));
config.setAllowCredentials(false); // true only if you're sending cookies
// Use UrlBasedCorsConfigurationSource as it implements CorsConfigurationSource
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config); // Apply CORS to all paths
return source; // Return as CorsConfigurationSource
}
}