| | |
| | | package com.ruoyi.gateway.filter;
|
| | |
|
| | | import com.ruoyi.common.core.utils.web.WebUtils;
|
| | | import com.ruoyi.gateway.config.properties.IgnoreClientProperties;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.cloud.gateway.filter.GatewayFilter;
|
| | | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
|
| | | import org.springframework.http.HttpHeaders;
|
| | | import org.springframework.http.server.reactive.ServerHttpRequest;
|
| | | import org.springframework.http.server.reactive.ServerHttpResponse;
|
| | | import org.springframework.stereotype.Component;
|
| | |
| | | @Autowired
|
| | | private ValidateCodeService validateCodeService;
|
| | |
|
| | | @Autowired
|
| | | private IgnoreClientProperties ignoreClient;
|
| | | private static final String BASIC_ = "Basic ";
|
| | |
|
| | | private static final String CODE = "code";
|
| | |
|
| | | private static final String UUID = "uuid";
|
| | |
|
| | | @Override
|
| | | public GatewayFilter apply(Object config)
|
| | |
| | | {
|
| | | return chain.filter(exchange);
|
| | | }
|
| | |
|
| | | // 消息头存在内容,且不存在验证码参数,不处理
|
| | | String header = request.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
|
| | | if (StringUtils.isNotEmpty(header) && StringUtils.startsWith(header, BASIC_)
|
| | | && !request.getQueryParams().containsKey(CODE) && !request.getQueryParams().containsKey(UUID))
|
| | | {
|
| | | return chain.filter(exchange);
|
| | | }
|
| | | try
|
| | | {
|
| | | // swagger的oauth2.0验证码放行操作
|
| | | String[] clientInfos = WebUtils.getClientId(request);
|
| | | if (ignoreClient.getClients().contains(clientInfos[0]))
|
| | | {
|
| | | return chain.filter(exchange);
|
| | | }
|
| | |
|
| | | validateCodeService.checkCapcha(request.getQueryParams().getFirst("code"),
|
| | | request.getQueryParams().getFirst("uuid"));
|
| | | validateCodeService.checkCapcha(request.getQueryParams().getFirst(CODE),
|
| | | request.getQueryParams().getFirst(UUID));
|
| | | }
|
| | | catch (Exception e)
|
| | | {
|