|
2 | 2 |
|
3 | 3 | import org.springframework.beans.factory.annotation.Autowired;
|
4 | 4 | import org.springframework.beans.factory.annotation.Value;
|
| 5 | +import org.springframework.context.annotation.Bean; |
5 | 6 | import org.springframework.context.annotation.Configuration;
|
6 | 7 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
7 | 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
10 | 11 | import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
|
11 | 12 | import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
|
12 | 13 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
| 14 | +import org.springframework.web.cors.CorsConfiguration; |
| 15 | +import org.springframework.web.cors.CorsConfigurationSource; |
| 16 | +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
| 17 | + |
| 18 | +import java.util.Arrays; |
13 | 19 |
|
14 | 20 | @Configuration
|
15 | 21 | public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
@@ -56,4 +62,14 @@ protected void configure(HttpSecurity http) throws Exception {
|
56 | 62 | http.headers().frameOptions().disable();
|
57 | 63 | }
|
58 | 64 | }
|
| 65 | + |
| 66 | + @Bean |
| 67 | + CorsConfigurationSource corsConfigurationSource() { |
| 68 | + CorsConfiguration configuration = new CorsConfiguration(); |
| 69 | + configuration.setAllowedOrigins(Arrays.asList("https://sample-angular-project.herokuapp.com","http://localhost:4200")); |
| 70 | + configuration.setAllowedMethods(Arrays.asList("GET","POST","PUT","DELETE")); |
| 71 | + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| 72 | + source.registerCorsConfiguration("/**", configuration); |
| 73 | + return source; |
| 74 | + } |
59 | 75 | }
|
0 commit comments