| | |
| | | import org.springframework.core.io.buffer.DataBuffer;
|
| | | import org.springframework.core.io.buffer.DataBufferUtils;
|
| | | import org.springframework.http.server.reactive.ServerHttpRequest;
|
| | | import org.springframework.http.server.reactive.ServerHttpResponse;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.ruoyi.common.core.utils.ServletUtils;
|
| | | import com.ruoyi.common.core.utils.StringUtils;
|
| | | import com.ruoyi.common.core.web.domain.AjaxResult;
|
| | | import com.ruoyi.gateway.config.properties.CaptchaProperties;
|
| | | import com.ruoyi.gateway.service.ValidateCodeService;
|
| | | import reactor.core.publisher.Flux;
|
| | | import reactor.core.publisher.Mono;
|
| | |
|
| | | /**
|
| | | * 验证码过滤器
|
| | |
| | | ServerHttpRequest request = exchange.getRequest();
|
| | |
|
| | | // 非登录请求或验证码关闭,不处理
|
| | | if (!StringUtils.containsIgnoreCase(request.getURI().getPath(), AUTH_URL) || !captchaProperties.isEnabled())
|
| | | if (!StringUtils.containsIgnoreCase(request.getURI().getPath(), AUTH_URL) || !captchaProperties.getEnabled())
|
| | | {
|
| | | return chain.filter(exchange);
|
| | | }
|
| | |
| | | }
|
| | | catch (Exception e)
|
| | | {
|
| | | ServerHttpResponse response = exchange.getResponse();
|
| | | response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
|
| | | return exchange.getResponse().writeWith(
|
| | | Mono.just(response.bufferFactory().wrap(JSON.toJSONBytes(AjaxResult.error(e.getMessage())))));
|
| | | return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage());
|
| | | }
|
| | | return chain.filter(exchange);
|
| | | };
|