diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java
index 8c6c24b35..2fff0f48d 100644
--- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java
+++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstants.java
@@ -91,4 +91,9 @@ public interface CommonConstants {
* 默认存储bucket
*/
String BUCKET_NAME = "lengleng";
+
+ /**
+ * 滑块验证码
+ */
+ String IMAGE_CODE_TYPE = "blockPuzzle";
}
diff --git a/pigx-gateway/pom.xml b/pigx-gateway/pom.xml
index 80f58f299..fb6e4ba36 100644
--- a/pigx-gateway/pom.xml
+++ b/pigx-gateway/pom.xml
@@ -59,8 +59,8 @@
+ * 验证码 缓存提供支持集群
+ */
+@Primary
+@Component
+@AllArgsConstructor
+public class CaptchaCacheServiceProvider implements CaptchaCacheService {
+ private final StringRedisTemplate stringRedisTemplate;
+
+ @Override
+ public void set(String key, String value, long expiresInSeconds) {
+ stringRedisTemplate.opsForValue().set(key, value, expiresInSeconds, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public boolean exists(String key) {
+ return stringRedisTemplate.hasKey(key);
+ }
+
+ @Override
+ public void delete(String key) {
+ stringRedisTemplate.delete(key);
+ }
+
+ @Override
+ public String get(String key) {
+ return stringRedisTemplate.opsForValue().get(key);
+ }
+}
diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RouterFunctionConfiguration.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RouterFunctionConfiguration.java
index 2b46c6c55..a8aceb874 100644
--- a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RouterFunctionConfiguration.java
+++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/config/RouterFunctionConfiguration.java
@@ -17,10 +17,7 @@
package com.pig4cloud.pigx.gateway.config;
-import com.pig4cloud.pigx.gateway.handler.ImageCodeHandler;
-import com.pig4cloud.pigx.gateway.handler.SwaggerResourceHandler;
-import com.pig4cloud.pigx.gateway.handler.SwaggerSecurityHandler;
-import com.pig4cloud.pigx.gateway.handler.SwaggerUiHandler;
+import com.pig4cloud.pigx.gateway.handler.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
@@ -39,16 +36,19 @@ import org.springframework.web.reactive.function.server.RouterFunctions;
@Configuration
@AllArgsConstructor
public class RouterFunctionConfiguration {
+ private final ImageCodeCheckHandler imageCodeCheckHandler;
+ private final ImageCodeCreateHandler imageCodeCreateHandler;
private final SwaggerResourceHandler swaggerResourceHandler;
private final SwaggerSecurityHandler swaggerSecurityHandler;
private final SwaggerUiHandler swaggerUiHandler;
- private final ImageCodeHandler imageCodeHandler;
@Bean
public RouterFunction routerFunction() {
return RouterFunctions.route(
RequestPredicates.path("/code")
- .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), imageCodeHandler)
+ .and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), imageCodeCreateHandler)
+ .andRoute(RequestPredicates.POST("/check")
+ .and(RequestPredicates.accept(MediaType.ALL)), imageCodeCheckHandler)
.andRoute(RequestPredicates.GET("/swagger-resources")
.and(RequestPredicates.accept(MediaType.ALL)), swaggerResourceHandler)
.andRoute(RequestPredicates.GET("/swagger-resources/configuration/ui")
diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ValidateCodeGatewayFilter.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ValidateCodeGatewayFilter.java
index 020b63618..37a756528 100644
--- a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ValidateCodeGatewayFilter.java
+++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/filter/ValidateCodeGatewayFilter.java
@@ -18,13 +18,17 @@
package com.pig4cloud.pigx.gateway.filter;
import cn.hutool.core.util.StrUtil;
+import com.anji.captcha.model.vo.CaptchaVO;
+import com.anji.captcha.service.CaptchaService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
+import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
import com.pig4cloud.pigx.common.core.exception.ValidateCodeException;
import com.pig4cloud.pigx.common.core.util.R;
+import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
import com.pig4cloud.pigx.common.core.util.WebUtils;
import com.pig4cloud.pigx.gateway.config.FilterIgnorePropertiesConfig;
import lombok.AllArgsConstructor;
@@ -44,8 +48,8 @@ import reactor.core.publisher.Mono;
/**
* @author lengleng
- * @date 2018/7/4
- * 验证码处理
+ * @date 2020/5/19
+ * 登录逻辑验证码处理
*/
@Slf4j
@Component
@@ -125,6 +129,18 @@ public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {
String randomStr = request.getQueryParams().getFirst("randomStr");
+ // 若是滑块登录
+ if (CommonConstants.IMAGE_CODE_TYPE.equalsIgnoreCase(randomStr)) {
+ CaptchaService captchaService = SpringContextHolder.getBean(CaptchaService.class);
+ CaptchaVO vo = new CaptchaVO();
+ vo.setCaptchaVerification(code);
+ if (!captchaService.verification(vo).isSuccess()) {
+ throw new ValidateCodeException("验证码不能为空");
+ }
+
+ return;
+ }
+
//https://gitee.com/log4j/pig/issues/IWA0D
String mobile = request.getQueryParams().getFirst("mobile");
if (StrUtil.isNotBlank(mobile)) {
diff --git a/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handler/ImageCodeCheckHandler.java b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handler/ImageCodeCheckHandler.java
new file mode 100644
index 000000000..4de706ce3
--- /dev/null
+++ b/pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/handler/ImageCodeCheckHandler.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.gateway.handler;
+
+import com.anji.captcha.model.common.ResponseModel;
+import com.anji.captcha.model.vo.CaptchaVO;
+import com.anji.captcha.service.CaptchaService;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.pig4cloud.pigx.common.core.constant.CommonConstants;
+import com.pig4cloud.pigx.common.core.util.R;
+import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
+import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Component;
+import org.springframework.web.reactive.function.BodyInserters;
+import org.springframework.web.reactive.function.server.HandlerFunction;
+import org.springframework.web.reactive.function.server.ServerRequest;
+import org.springframework.web.reactive.function.server.ServerResponse;
+import reactor.core.publisher.Mono;
+
+/**
+ * @author lengleng
+ * @date 2020/5/19
+ * 验证码生成逻辑处理类
+ */
+@Slf4j
+@Component
+@AllArgsConstructor
+public class ImageCodeCheckHandler implements HandlerFunction