springcloud-gateway网关(自定义filter)

@Configuration
@Slf4j
public class CustomGlobalFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        log.info("进入自定义的filter");
        if (exchange.getRequest().getQueryParams().get("username") != null) {

            log.info("用户身份信息合法,放行请求继续执行!!!");
            return chain.filter(exchange);//放行请求
        }
        log.info("非法用户,拒绝访问!!!");
        return exchange.getResponse().setComplete();
    }

    @Override
    public int getOrder() {
        return -1;
    }
}

 

posted @ 2020-08-12 14:37  陶海军  阅读(1038)  评论(0编辑  收藏  举报