feat: 登录信息加密传输

This commit is contained in:
2026-06-23 16:00:47 +08:00
parent 03ad011f64
commit e56f043483
33 changed files with 2273 additions and 113 deletions

View File

@@ -1,10 +1,18 @@
package tech.easyflow.usercenter.controller.auth;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.easyflow.auth.entity.CredentialKeyVO;
import tech.easyflow.auth.entity.EncryptedCredentialDTO;
import tech.easyflow.auth.entity.LoginDTO;
import tech.easyflow.auth.entity.LoginVO;
import tech.easyflow.auth.service.AuthCredentialKeyService;
import tech.easyflow.auth.service.AuthService;
import tech.easyflow.common.captcha.tainai.CaptchaVerificationService;
import tech.easyflow.common.domain.Result;
import tech.easyflow.common.web.jsonbody.JsonBody;
@@ -20,13 +28,30 @@ public class UcAuthController {
@Resource
private AuthService authService;
@Resource
private AuthCredentialKeyService credentialKeyService;
@Resource
private CaptchaVerificationService captchaVerificationService;
/**
* 获取登录加密公钥。
*/
@GetMapping("credential-key")
public Result<CredentialKeyVO> credentialKey() {
return Result.ok(credentialKeyService.getCurrentCredentialKey());
}
/**
* 登录
* @param loginDTO 登录参数
* @param encryptedCredential 加密登录参数
*/
@PostMapping("login")
public Result<LoginVO> login(@JsonBody LoginDTO loginDTO) {
public Result<LoginVO> login(@JsonBody EncryptedCredentialDTO encryptedCredential) {
JSONObject payload = credentialKeyService.decryptPayload(encryptedCredential);
if (!captchaVerificationService.verify(payload.getString("validToken"))) {
return captchaVerificationService.failureResult();
}
LoginDTO loginDTO = toLoginDTO(payload);
LoginVO res = authService.login(loginDTO);
return Result.ok(res);
}
@@ -48,4 +73,11 @@ public class UcAuthController {
List<String> permissionList = StpUtil.getPermissionList();
return Result.ok(permissionList);
}
private LoginDTO toLoginDTO(JSONObject payload) {
LoginDTO loginDTO = new LoginDTO();
loginDTO.setAccount(payload.getString("account"));
loginDTO.setPassword(payload.getString("password"));
return loginDTO;
}
}

View File

@@ -1,10 +1,13 @@
package tech.easyflow.usercenter.controller.system;
import cn.hutool.crypto.digest.BCrypt;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.easyflow.auth.entity.EncryptedCredentialDTO;
import tech.easyflow.auth.service.AuthCredentialKeyService;
import tech.easyflow.common.domain.Result;
import tech.easyflow.common.entity.LoginAccount;
import tech.easyflow.common.satoken.util.SaTokenUtil;
@@ -29,6 +32,8 @@ public class UcSysAccountController {
@Resource
private SysAccountService service;
@Resource
private AuthCredentialKeyService credentialKeyService;
/**
* 获取用户的信息
@@ -61,14 +66,14 @@ public class UcSysAccountController {
/**
* 修改密码
*
* @param password 用户的旧密码
* @param newPassword 新密码
* @param confirmPassword 确认密码
* @param encryptedCredential 加密后的旧密码、新密码与确认密码
*/
@PostMapping("/updatePassword")
public Result<Void> updatePassword(@JsonBody(value = "password", required = true) String password,
@JsonBody(value = "newPassword", required = true) String newPassword,
@JsonBody(value = "confirmPassword", required = true) String confirmPassword) {
public Result<Void> updatePassword(@JsonBody EncryptedCredentialDTO encryptedCredential) {
JSONObject payload = credentialKeyService.decryptPayload(encryptedCredential);
String password = payload.getString("password");
String newPassword = payload.getString("newPassword");
String confirmPassword = payload.getString("confirmPassword");
BigInteger loginAccountId = SaTokenUtil.getLoginAccount().getId();
SysAccount record = service.getById(loginAccountId);
if (record == null) {