如何将 Spring Cloud Gateway 与 Spring 授权服务器下游路由

问题描述 投票:0回答:1

这个问题是https://github.com/spring-cloud/spring-cloud-gateway/issues/3636问题的后续问题,该问题还附加了MCVE。

正确配置它的推荐方法是什么。

spring-security spring-cloud-gateway
1个回答
0
投票

访问http://dummy.traefik.me/login时不经过安全过滤链,如果是这样的话我想可以这样做

 private ServerWebExchangeMatcher getSecurityMatcher() {
        return exchange -> {
            URI uri = exchange.getRequest().getURI();
            if (uri.getHost().equals("dummy.traefik.me")) {
                return ServerWebExchangeMatcher.MatchResult.notMatch();
            }
            return ServerWebExchangeMatcher.MatchResult.match();
        };
    }

    @Bean
    SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        http
                .securityMatcher(getSecurityMatcher())
                .authorizeExchange(authorizeRequests -> authorizeRequests
                        .anyExchange()
                        .authenticated()
                )
                .formLogin(withDefaults())
                .logout(withDefaults());

        return http.build();
    }
© www.soinside.com 2019 - 2024. All rights reserved.