Skip to content

Commit

Permalink
develop: CORS config fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blablanumerodeux committed Mar 31, 2020
1 parent f954b65 commit c896a08
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/main/java/org/danslarue/homeless/HomelessApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,32 +41,32 @@ 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"))
.authorities("ROLE_USER");
}

@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
Expand Down

0 comments on commit c896a08

Please sign in to comment.