Browse Source

修改登陆验证码。

master
刘忱 2 years ago
parent
commit
163d37763c
  1. 56
      win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/KaptchaTextCreator.java
  2. 2
      win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java
  3. 2
      win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java
  4. 4
      win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java
  5. 3
      win-server/src/main/resources/application.yaml

56
win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/KaptchaTextCreator.java

@ -0,0 +1,56 @@
package com.win.framework.captcha.config;
import com.google.code.kaptcha.text.impl.DefaultTextCreator;
import java.util.Random;
/**
* 验证码文本生成器
*
* @author win
*/
public class KaptchaTextCreator extends DefaultTextCreator {
private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(",");
@Override
public String getText() {
Integer result = 0;
Random random = new Random();
int x = random.nextInt(10);
int y = random.nextInt(10);
StringBuilder suChinese = new StringBuilder();
int randomoperands = random.nextInt(3);
if (randomoperands == 0) {
result = x * y;
suChinese.append(CNUMBERS[x]);
suChinese.append("*");
suChinese.append(CNUMBERS[y]);
} else if (randomoperands == 1) {
if ((x != 0) && y % x == 0) {
result = y / x;
suChinese.append(CNUMBERS[y]);
suChinese.append("/");
suChinese.append(CNUMBERS[x]);
} else {
result = x + y;
suChinese.append(CNUMBERS[x]);
suChinese.append("+");
suChinese.append(CNUMBERS[y]);
}
} else {
if (x >= y) {
result = x - y;
suChinese.append(CNUMBERS[x]);
suChinese.append("-");
suChinese.append(CNUMBERS[y]);
} else {
result = y - x;
suChinese.append(CNUMBERS[y]);
suChinese.append("-");
suChinese.append(CNUMBERS[x]);
}
}
suChinese.append("=?@" + result);
return suChinese.toString();
}
}

2
win-framework/win-spring-boot-starter-captcha/src/main/java/com/win/framework/captcha/config/WinCaptchaConfiguration.java

@ -57,7 +57,7 @@ public class WinCaptchaConfiguration {
// KAPTCHA_SESSION_KEY
properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath");
// 验证码文本生成器
properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.win.tms.framework.config.KaptchaTextCreator");
properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.win.framework.captcha.config.KaptchaTextCreator");
// 验证码文本字符间距 默认为2
properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3");
// 验证码文本字符长度 默认为5

2
win-framework/win-spring-boot-starter-security/src/main/java/com/win/framework/security/config/WinWebSecurityConfigurerAdapter.java

@ -128,7 +128,7 @@ public class WinWebSecurityConfigurerAdapter {
// 1.4 设置 App API 无需认证
.antMatchers(buildAppApi("/**")).permitAll()
// 1.5 验证码captcha 允许匿名访问
.antMatchers("/captcha/get", "/captcha/check").permitAll()
.antMatchers("/captcha/captchaImage").permitAll()
// 1.6 webSocket 允许匿名访问
.antMatchers("/websocket/message").permitAll()
// ②:每个项目的自定义规则

4
win-module-system/win-module-system-biz/src/main/java/com/win/module/system/controller/admin/captcha/CaptchaController.java

@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
@ -30,7 +31,7 @@ import static com.win.framework.common.pojo.CommonResult.success;
*
* @author win
*/
@RestController("adminCaptchaController")
@RestController
@RequestMapping("/system/captcha")
public class CaptchaController {
@Resource(name = "captchaProducer")
@ -45,6 +46,7 @@ public class CaptchaController {
/**
* 生成验证码
*/
@PermitAll
@GetMapping("/captchaImage")
public CommonResult<Object> getCode(HttpServletResponse response) throws IOException {
Map<String, Object> data = new HashMap<>();

3
win-server/src/main/resources/application.yaml

@ -142,10 +142,7 @@ win:
- /admin-api/system/tenant/get-id-by-name # 基于名字获取租户,不许带租户编号
- /admin-api/system/captcha/captchaImage # 校验图片验证码,和租户无关
- /admin-api/infra/file/*/get/** # 获取图片,和租户无关
- /admin-api/system/sms/callback/* # 短信回调接口,无法带上租户编号
- /admin-api/pay/notify/** # 支付回调通知,不携带租户编号
- /jmreport/* # 积木报表,无法携带租户编号
- /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号
ignore-tables:
- system_tenant
- system_tenant_package

Loading…
Cancel
Save