This commit is contained in:
caozehui
2025-04-14 14:47:51 +08:00
parent 4a2fb595d0
commit 92b0640f9c
2 changed files with 2 additions and 23 deletions

View File

@@ -46,8 +46,6 @@ public class AuthController extends BaseController {
private final ISysUserService sysUserService;
private final CustomCacheUtil customCacheUtil;
private final String PUBLIC_KEY = "publicKey";
private final String PRIVATE_KEY = "privateKey";
private KeyPair keyPair;
@@ -62,14 +60,6 @@ public class AuthController extends BaseController {
String password = null;
try {
String keyPairJSON = customCacheUtil.get(username, false);
if (StrUtil.isNotBlank(keyPairJSON)) {
Map map = JSON.parseObject(keyPairJSON, Map.class);
keyPair = new KeyPair(RSAUtil.stringToPublicKey(map.get(PUBLIC_KEY).toString()), RSAUtil.stringToPrivateKey(map.get(PRIVATE_KEY).toString()));
}
if (!param.getChecked()) {
customCacheUtil.remove(username);
}
password = RSAUtil.decrypt(param.getPassword(), keyPair.getPrivate());
} catch (Exception e) {
throw new BusinessException(UserResponseEnum.RSA_DECRYT_ERROR);
@@ -128,7 +118,7 @@ public class AuthController extends BaseController {
SysUser user = sysUserService.getById(userId);
String accessTokenNew = JwtUtil.getAccessToken(userId);
request.setAttribute(SecurityConstants.AUTHENTICATE_USERNAME, user.getLoginName());
//String refreshTokenNew = JwtUtil.getRefreshToken(accessTokenNew);
// String refreshTokenNew = JwtUtil.getRefreshToken(accessTokenNew);
token.setAccessToken(accessTokenNew);
token.setRefreshToken(accessToken);
@@ -143,21 +133,12 @@ public class AuthController extends BaseController {
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@ApiOperation("获取RSA公钥")
@GetMapping("/getPublicKey")
public HttpResult<String> publicKey(@RequestParam("username") String username, @RequestParam("checked") Boolean checked, HttpServletRequest request) throws Exception {
public HttpResult<String> publicKey(@RequestParam("username") String username, HttpServletRequest request) throws Exception {
String methodDescribe = getMethodDescribe("publicKey");
LogUtil.njcnDebug(log, "{}获取RSA公钥", methodDescribe);
// 因不确定是否能登陆成功先将登陆名保存到request一遍记录谁执行了登录操作
request.setAttribute(SecurityConstants.AUTHENTICATE_USERNAME, username);
keyPair = RSAUtil.generateKeyPair();
if (checked) {
Map map = new HashMap();
map.put(PUBLIC_KEY, RSAUtil.publicKeyToString(keyPair.getPublic()));
map.put(PRIVATE_KEY, RSAUtil.privateKeyToString(keyPair.getPrivate()));
customCacheUtil.putWithExpireTime(username, JSON.toJSONString(map), DateUnit.DAY.getMillis() * 30);
} else {
customCacheUtil.remove(username);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, RSAUtil.publicKeyToString(keyPair.getPublic()), methodDescribe);
}
}

View File

@@ -100,7 +100,5 @@ public class SysUserParam {
@NotBlank(message = UserValidMessage.PASSWORD_NOT_BLANK)
@Pattern(regexp = PatternRegex.PASSWORD_REGEX, message = UserValidMessage.PASSWORD_FORMAT_ERROR)
private String password;
private Boolean checked;
}
}