|
|
|
@ -3,6 +3,7 @@ package com.ruoyi.gateway.filter;
|
|
|
|
|
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;
|
|
|
|
@ -25,6 +26,12 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object>
|
|
|
|
|
@Autowired
|
|
|
|
|
private ValidateCodeService validateCodeService;
|
|
|
|
|
|
|
|
|
|
private static final String BASIC_ = "Basic ";
|
|
|
|
|
|
|
|
|
|
private static final String CODE = "code";
|
|
|
|
|
|
|
|
|
|
private static final String UUID = "uuid";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public GatewayFilter apply(Object config)
|
|
|
|
|
{
|
|
|
|
@ -36,10 +43,18 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object>
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
validateCodeService.checkCapcha(request.getQueryParams().getFirst("code"),
|
|
|
|
|
request.getQueryParams().getFirst("uuid"));
|
|
|
|
|
validateCodeService.checkCapcha(request.getQueryParams().getFirst(CODE),
|
|
|
|
|
request.getQueryParams().getFirst(UUID));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|