Проблемы конфигурации безопасности при миграции с Zuul на Spring Cloud Gateway - PullRequest
0 голосов
/ 11 марта 2019

Я пытаюсь перенести свой полнофункциональный микросервис Zuul на Spring Cloud Gateway и получаю следующий ответ при отправке запросов через шлюз:

HTTP/1.1 403 Forbidden

Server: xxxxxxxxxxxx

Date: Mon, 11 Mar 2019 15:31:15 GMT

Content-Type: text/plain

Transfer-Encoding: chunked

Connection: keep-alive

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: 0

X-Content-Type-Options: nosniff

X-Frame-Options: DENY

X-XSS-Protection: 1 ; mode=block

Content-Encoding: gzip



CSRF Token has been associated to this client

Ниже приведена моя конфигурация безопасности Spring Cloud Gateway:

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

@EnableWebFluxSecurity
public class SecurityConfiguration {

  @Bean
  SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity serverHttpSecurity)
      throws Exception {
    return serverHttpSecurity.csrf().disable().authorizeExchange().pathMatchers("/**").permitAll()
        .and().build();
  }

}

Вот конфигурация, которая работает с Zuul:

import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(final HttpSecurity httpSecurity) throws Exception {
    httpSecurity.authorizeRequests().antMatchers("/**").permitAll().and().csrf().disable();
  }
}

У меня отключена защита CSRF в конфигурации безопасности Spring Cloud Gateway, так почему я получаю 403 с ответом CSRF Token has been associated to this client?

Я нахожусь в Spring Cloud Finchley.SR3 / Spring Boot 2.0.8.RELEASE.

...