用户部分信息 加密处理
This commit is contained in:
+14
@@ -96,6 +96,20 @@ public class PasswordUtil {
|
|||||||
return bytesToHexString(encipheredData);
|
return bytesToHexString(encipheredData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义加密明文字符串
|
||||||
|
*
|
||||||
|
* @param plaintext
|
||||||
|
* 待加密的明文字符串
|
||||||
|
* @return 加密后的密文字符串
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String encrypt(String plaintext) {
|
||||||
|
|
||||||
|
return encrypt(plaintext, ALGORITHM, Salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解密密文字符串
|
* 解密密文字符串
|
||||||
*
|
*
|
||||||
|
|||||||
+63
-15
@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.jero.common.exception.JeroBootException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
@@ -137,20 +138,42 @@ public class SysUserController {
|
|||||||
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
||||||
public Result<SysUser> add(@RequestBody JSONObject jsonObject) {
|
public Result<SysUser> add(@RequestBody JSONObject jsonObject) {
|
||||||
Result<SysUser> result = new Result<SysUser>();
|
Result<SysUser> result = new Result<SysUser>();
|
||||||
String selectedRoles = jsonObject.getString("selectedroles");
|
try {
|
||||||
String selectedDeparts = jsonObject.getString("selecteddeparts");
|
String selectedRoles = jsonObject.getString("selectedroles");
|
||||||
try {
|
String selectedDeparts = jsonObject.getString("selecteddeparts");
|
||||||
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
String rsaPublicKey = jsonObject.getString("rsaPublicKey");
|
||||||
user.setCreateTime(new Date());//设置创建时间
|
String rsaPrivateKey = String.valueOf(redisUtil.get(rsaPublicKey));
|
||||||
String salt = oConvertUtils.randomGen(8);
|
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
||||||
user.setSalt(salt);
|
String email;
|
||||||
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
|
String phone;
|
||||||
user.setPassword(passwordEncode);
|
try {
|
||||||
user.setStatus(1);
|
//1:先用私钥解密数据
|
||||||
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
email = CommonUtils.decryptBtRsaPriKey(user.getEmail(), rsaPrivateKey);
|
||||||
sysUserService.addUserWithRole(user, selectedRoles);
|
phone = CommonUtils.decryptBtRsaPriKey(user.getPhone(), rsaPrivateKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JeroBootException("解密失败!", e);
|
||||||
|
}
|
||||||
|
//3:把数据加密在放回来
|
||||||
|
email = PasswordUtil.encrypt(email);
|
||||||
|
phone = PasswordUtil.encrypt(phone);
|
||||||
|
user.setEmail(email);
|
||||||
|
user.setPhone(phone);
|
||||||
|
String password;
|
||||||
|
try {
|
||||||
|
password = CommonUtils.decryptBtRsaPriKey(user.getPassword(), rsaPrivateKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JeroBootException("解密失败!", e);
|
||||||
|
}
|
||||||
|
user.setCreateTime(new Date());//设置创建时间
|
||||||
|
String salt = oConvertUtils.randomGen(8);
|
||||||
|
user.setSalt(salt);
|
||||||
|
String passwordEncode = PasswordUtil.encrypt(user.getUsername(), password, salt);
|
||||||
|
user.setPassword(passwordEncode);
|
||||||
|
user.setStatus(1);
|
||||||
|
user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||||
|
sysUserService.addUserWithRole(user, selectedRoles);
|
||||||
sysUserService.addUserWithDepart(user, selectedDeparts);
|
sysUserService.addUserWithDepart(user, selectedDeparts);
|
||||||
result.success("添加成功!");
|
result.success("添加成功!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
result.error500("操作失败");
|
result.error500("操作失败");
|
||||||
@@ -162,6 +185,10 @@ public class SysUserController {
|
|||||||
@RequiresPermissions("user:edit")
|
@RequiresPermissions("user:edit")
|
||||||
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
@RequestMapping(value = "/edit", method = RequestMethod.PUT)
|
||||||
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
|
public Result<SysUser> edit(@RequestBody JSONObject jsonObject) {
|
||||||
|
String rsaPublicKey = jsonObject.getString("rsaPublicKey");
|
||||||
|
String roles = jsonObject.getString("selectedroles");
|
||||||
|
String departs = jsonObject.getString("selecteddeparts");
|
||||||
|
String rsaPrivateKey = String.valueOf(redisUtil.get(rsaPublicKey));
|
||||||
Result<SysUser> result = new Result<SysUser>();
|
Result<SysUser> result = new Result<SysUser>();
|
||||||
try {
|
try {
|
||||||
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
|
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
|
||||||
@@ -170,11 +197,23 @@ public class SysUserController {
|
|||||||
result.error500("未找到对应实体");
|
result.error500("未找到对应实体");
|
||||||
}else {
|
}else {
|
||||||
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
||||||
|
String email;
|
||||||
|
String phone;
|
||||||
|
try {
|
||||||
|
//1:先用私钥解密数据
|
||||||
|
email = CommonUtils.decryptBtRsaPriKey(user.getEmail(), rsaPrivateKey);
|
||||||
|
phone = CommonUtils.decryptBtRsaPriKey(user.getPhone(), rsaPrivateKey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JeroBootException("解密失败!", e);
|
||||||
|
}
|
||||||
|
//3:把数据加密在放回来
|
||||||
|
email = PasswordUtil.encrypt(email);
|
||||||
|
phone = PasswordUtil.encrypt(phone);
|
||||||
|
user.setEmail(email);
|
||||||
|
user.setPhone(phone);
|
||||||
user.setUpdateTime(new Date());
|
user.setUpdateTime(new Date());
|
||||||
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
|
//String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), sysUser.getSalt());
|
||||||
user.setPassword(sysUser.getPassword());
|
user.setPassword(sysUser.getPassword());
|
||||||
String roles = jsonObject.getString("selectedroles");
|
|
||||||
String departs = jsonObject.getString("selecteddeparts");
|
|
||||||
sysUserService.editUserWithRole(user, roles);
|
sysUserService.editUserWithRole(user, roles);
|
||||||
sysUserService.editUserWithDepart(user, departs);
|
sysUserService.editUserWithDepart(user, departs);
|
||||||
sysUserService.updateNullPhoneEmail();
|
sysUserService.updateNullPhoneEmail();
|
||||||
@@ -542,6 +581,15 @@ public class SysUserController {
|
|||||||
String oldpassword = json.getString("oldpassword");
|
String oldpassword = json.getString("oldpassword");
|
||||||
String password = json.getString("password");
|
String password = json.getString("password");
|
||||||
String confirmpassword = json.getString("confirmpassword");
|
String confirmpassword = json.getString("confirmpassword");
|
||||||
|
String RSAPublicKey = json.getString("rsaPublicKey");
|
||||||
|
String RSAPrivateKey = String.valueOf(redisUtil.get(RSAPublicKey));
|
||||||
|
try {
|
||||||
|
oldpassword = CommonUtils.decryptBtRsaPriKey(oldpassword, RSAPrivateKey);
|
||||||
|
password = CommonUtils.decryptBtRsaPriKey(password, RSAPrivateKey);
|
||||||
|
confirmpassword = CommonUtils.decryptBtRsaPriKey(confirmpassword, RSAPrivateKey);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(),e);
|
||||||
|
}
|
||||||
SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
|
SysUser user = this.sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username));
|
||||||
if(user==null) {
|
if(user==null) {
|
||||||
return Result.error("用户不存在!");
|
return Result.error("用户不存在!");
|
||||||
|
|||||||
Reference in New Issue
Block a user