|
3 | 3 |
|
4 | 4 | import comp9323.group12.backend.component.auth.RestAuthenticationFailureHandler;
|
5 | 5 | import comp9323.group12.backend.component.auth.RestAuthenticationSuccessHandler;
|
| 6 | +import org.apache.catalina.filters.CorsFilter; |
6 | 7 | import org.springframework.beans.factory.annotation.Autowired;
|
| 8 | +import org.springframework.boot.web.servlet.FilterRegistrationBean; |
7 | 9 | import org.springframework.context.annotation.Bean;
|
| 10 | +import org.springframework.core.Ordered; |
8 | 11 | import org.springframework.http.HttpMethod;
|
9 | 12 | import org.springframework.security.config.Customizer;
|
10 | 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
@@ -58,9 +61,41 @@ CorsConfigurationSource corsConfigurationSource() {
|
58 | 61 | CorsConfiguration configuration = new CorsConfiguration();
|
59 | 62 | configuration.setAllowedOrigins(Arrays.asList("*"));
|
60 | 63 | configuration.setAllowedMethods(Arrays.asList("GET","POST", "OPTIONS", "PUT", "DELETE"));
|
| 64 | + configuration.setAllowedHeaders(Arrays.asList("X-Requested-With", "Origin", "Content-Type", "Accept", |
| 65 | + "Authorization", "Access-Control-Allow-Credentials", "Access-Control-Allow-Headers", "Access-Control-Allow-Methods", |
| 66 | + "Access-Control-Allow-Origin", "Access-Control-Expose-Headers", "Access-Control-Max-Age", |
| 67 | + "Access-Control-Request-Headers", "Access-Control-Request-Method", "Age", "Allow", "Alternates", |
| 68 | + "Content-Range", "Content-Disposition", "Content-Description")); |
| 69 | + configuration.setAllowCredentials(true); |
61 | 70 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
62 | 71 | source.registerCorsConfiguration("/**", configuration);
|
63 | 72 | return source;
|
64 | 73 | }
|
| 74 | + |
| 75 | +// @Bean |
| 76 | +// public FilterRegisterationBean conrsfileter() { |
| 77 | +// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| 78 | +// CorsConfiguration config = new CorsConfiguration(); |
| 79 | +// config.setAllowCredentials(true); |
| 80 | +// config.addAllowedOrigin("*"); |
| 81 | +// config.addAllowedHeader("*"); |
| 82 | +// config.addAllowedMethod("*"); |
| 83 | +// source.registerCorsConfiguration("/**", config); |
| 84 | +// FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); |
| 85 | +// bean.setOrder(Ordered.HIGHEST_PRECEDENCE); |
| 86 | +// } |
| 87 | +//@Bean |
| 88 | +//public FilterRegistrationBean corsFilter() { |
| 89 | +// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| 90 | +// CorsConfiguration config = new CorsConfiguration(); |
| 91 | +// config.setAllowCredentials(true); |
| 92 | +// config.addAllowedOrigin("*"); |
| 93 | +// config.addAllowedHeader("*"); |
| 94 | +// config.addAllowedMethod("*"); |
| 95 | +// source.registerCorsConfiguration("/**", config); |
| 96 | +// FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); |
| 97 | +// bean.setOrder(Ordered.HIGHEST_PRECEDENCE); |
| 98 | +// return bean; |
| 99 | +//} |
65 | 100 | }
|
66 | 101 |
|
0 commit comments