diff --git a/src/main/java/org/danslarue/homeless/HomelessApplication.java b/src/main/java/org/danslarue/homeless/HomelessApplication.java index b3ed872..e4768d1 100644 --- a/src/main/java/org/danslarue/homeless/HomelessApplication.java +++ b/src/main/java/org/danslarue/homeless/HomelessApplication.java @@ -11,8 +11,9 @@ import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.spi.DocumentationType; @@ -40,16 +41,15 @@ public Docket api() { @Override protected void configure(HttpSecurity httpSecurity) throws Exception { - httpSecurity.csrf().disable() + httpSecurity.cors() + .and().csrf().disable() .authorizeRequests().anyRequest().authenticated() .and().httpBasic(); - } @Autowired public void configureGlobal(AuthenticationManagerBuilder authentication) - throws Exception - { + throws Exception { authentication.inMemoryAuthentication() .withUser("admin") .password(passwordEncoder().encode("nimda")) @@ -57,15 +57,16 @@ public void configureGlobal(AuthenticationManagerBuilder authentication) } @Bean - public WebMvcConfigurer corsConfigurer() { - return new WebMvcConfigurer() { - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/*") - .allowedOrigins("http://localhost:4200") - .allowedOrigins("https://homeless.project.lambla.eu"); - } - }; + public CorsFilter corsFilter() { + final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOrigin("https://homeless.project.lambla.eu"); + config.addAllowedOrigin("http://localhost:4200"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); } @Bean