Облачный шлюз Spring возвращает 403 для всех почтовых запросов, когда включена безопасность

У меня есть следующие услуги:

Сервер Eureka

Сервер аутентификации

  • Spring Gateway
  • Это передаст запрос на вход в службу входа.
  • Все остальные запросы будут аутентифицированы (с использованием токена jwt и секретного ключа) и переданы другим службам.

Служба входа в систему

  • Чтобы проверить логин и выпустить токен jwt

Ниже мой конфиг. Поток даже не доходит до этого кода ..

@Configuration
@EnableWebFluxSecurity
@EnableReactiveMethodSecurity
public class SecurityConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(SecurityConfig.class);

    @Autowired
    private AuthenticationManager authenticationManager;
        
    @Autowired
    private SecurityContextRepository securityContextRepository;
    

    @Bean(value="org.springframework.security.config.annotation.web.reactive.WebFluxSecurityConfiguration.WebFilterChainFilter")
    public SecurityWebFilterChain springSecurityWebFilterChainFilter(ServerHttpSecurity http) {
        LOGGER.info("In the securiry config..................");
        return http
                .csrf().disable()
            .exceptionHandling()
            .authenticationEntryPoint((swe, e) -> {
                return Mono.fromRunnable(() -> {
                    swe.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
                });
            }).accessDeniedHandler((swe, e) -> {
                return Mono.fromRunnable(() -> {
                    swe.getResponse().setStatusCode(HttpStatus.FORBIDDEN);
                });
            })
            .and()
            .authenticationManager(authenticationManager)
            .securityContextRepository(securityContextRepository)
            .authorizeExchange()
            .pathMatchers(HttpMethod.OPTIONS).permitAll()
            .pathMatchers("/login-service/api/login").permitAll()
            .anyExchange().authenticated()
            .and().build();
    }
}

Я всегда получаю 403 с An expected CSRF token cannot be found этой ошибкой, хотя я отключил csrf. Может ли кто-нибудь помочь, что здесь может быть не так?


person Dipen Adroja    schedule 03.04.2021    source источник
comment
Не могли бы вы предоставить дополнительную информацию о настройке вашего проекта? Также почему вы используете @Bean(value="org.springframework.security.config.annotation.web.reactive.WebFluxSecurityConfiguration.WebFilterChainFilter") как явное значение Bean поверх этого метода?   -  person Nagaraj Tantri    schedule 13.04.2021


Ответы (1)


Вы пробовали добавить свою роль:

.authorizeExchange()
.pathMatchers("/login-service/api/login").hasAuthority("ROLE_ADMIN")
.anyExchange().authenticated()
.and().build();
person Carlos Jafet Neto    schedule 13.04.2021