Конфигурации Cors не работают для весеннего webflux на Minikube - PullRequest
0 голосов
/ 13 февраля 2020

У меня есть нижеприведенная весенняя конфигурация безопасности и приложение reactJs, вызывающее бэкэнд-сервис. Оно прекрасно работает, когда я запускаю приложение ReactJs вне minikube, но когда я запускаю его на minikube, я получаю

Запрещен перекрестный запрос: одна и та же политика происхождения запрещает чтение удаленного ресурса

Spring security config

@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
  return http
          .cors()
          .configurationSource(configurationSource())
          .and()
          .csrf().disable()
          .exceptionHandling()
          .authenticationEntryPoint((exchange, e) ->
                  Mono.fromRunnable(() -> exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED)))
          .accessDeniedHandler((exchange, e) ->
                  Mono.fromRunnable(() -> exchange.getResponse().setStatusCode(HttpStatus.FORBIDDEN)))
          .and()
          .securityContextRepository(securityContextRepository)
          .authenticationManager(authenticationManager)
          .authorizeExchange()
          .pathMatchers(HttpMethod.OPTIONS).permitAll()
          .pathMatchers(HttpMethod.POST, "/auth/signin").permitAll()
          .pathMatchers(HttpMethod.POST, "/auth/users").permitAll()
          .anyExchange().authenticated()
          .and().build();
}

private CorsConfigurationSource configurationSource() {
    var config = new CorsConfiguration();
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*");
    config.addAllowedMethod("*");

    return serverWebExchange -> config;
}
...