1. 修改密码新增运控系统配置
parent
5213974d9b
commit
cc22b774e5
|
@ -154,7 +154,7 @@ public class TrxServiceImpl implements TrxService {
|
|||
|
||||
// 处理ukey登录用户
|
||||
log.info("开始uKey登录用户入库, userId:" + userId);
|
||||
saveUserByTrx(userId);
|
||||
saveUserByTrx(userId,"");
|
||||
log.info("uKey登录用户入库结束");
|
||||
// 登录
|
||||
log.info("开始uKey登录用户登录云管平台");
|
||||
|
@ -177,8 +177,8 @@ public class TrxServiceImpl implements TrxService {
|
|||
String s1 = MessageDigestUtils.encrypt(trxAuthModel.getPassword(), MessageDigestUtils.SHA_256);
|
||||
log.info("密码s1 sha256值:" + s1);
|
||||
log.info("getRandoms 值:" + trxAuthModel.getRandoms());
|
||||
log.info("待加密 值:" + trxAuthModel.getRandoms()+s1);
|
||||
String rs1 = MessageDigestUtils.encrypt(trxAuthModel.getRandoms()+s1, MessageDigestUtils.SHA_256);
|
||||
log.info("待加密 值:" + trxAuthModel.getRandoms() + s1);
|
||||
String rs1 = MessageDigestUtils.encrypt(trxAuthModel.getRandoms() + s1, MessageDigestUtils.SHA_256);
|
||||
log.info("密码rs1 sha256值:" + rs1);
|
||||
|
||||
Map<String, Object> paramsMap = new HashMap<>();
|
||||
|
@ -202,7 +202,7 @@ public class TrxServiceImpl implements TrxService {
|
|||
|
||||
// 处理ukey登录用户
|
||||
log.info("开始软Key登录用户入库, userId:" + userId);
|
||||
saveUserByTrx(userId);
|
||||
saveUserByTrx(userId,trxAuthModel.getPassword());
|
||||
log.info("软Key登录用户入库结束");
|
||||
// 登录
|
||||
log.info("开始软Key登录用户登录云管平台");
|
||||
|
@ -220,7 +220,7 @@ public class TrxServiceImpl implements TrxService {
|
|||
|
||||
}
|
||||
|
||||
private void saveUserByTrx(String userId) {
|
||||
private void saveUserByTrx(String userId, String password) {
|
||||
User user = userRepository.getByUserId(userId);
|
||||
// 根据userId获取运控系统用户信息
|
||||
JSONObject params = new JSONObject();
|
||||
|
@ -239,7 +239,11 @@ public class TrxServiceImpl implements TrxService {
|
|||
log.info("开始新增天融信登录用户,userId: " + userId);
|
||||
// 新增 以userId作为account 并添加注释
|
||||
UserBean userBean = new UserBean();
|
||||
userBean.setPassword(userId + "CMP");
|
||||
if (password.isEmpty()) {
|
||||
userBean.setPassword(userId + "CMP");
|
||||
} else {
|
||||
userBean.setPassword(password);
|
||||
}
|
||||
userBean.setSex(true);
|
||||
userBean.setIsManager(true);
|
||||
userBean.setUserId(userId);
|
||||
|
|
|
@ -3,14 +3,17 @@ package com.bocloud.sms.service;
|
|||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.alibaba.excel.write.handler.CellWriteHandler;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bocloud.cmp.boot.model.BocloudStatus;
|
||||
import com.bocloud.sms.entity.*;
|
||||
import com.bocloud.sms.enums.YkInf;
|
||||
import com.bocloud.sms.interfaces.UserService;
|
||||
import com.bocloud.sms.model.*;
|
||||
import com.bocloud.sms.repository.*;
|
||||
import com.bocloud.sms.service.utils.ExportUtil;
|
||||
import com.bocloud.sms.service.utils.ImportExcelUtil;
|
||||
import com.bocloud.sms.service.utils.YkUtils;
|
||||
import com.bocloud.sms.utils.FavoriteComparator;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.megatron.common.encrypt.AESEncryptor;
|
||||
|
@ -83,6 +86,8 @@ public class UserServiceImpl implements UserService {
|
|||
private final FavoriteRepository favoriteRepository;
|
||||
private final CloudServiceBeanRepository cloudServiceBeanRepository;
|
||||
private final ApiPermissionRepository apiPermissionRepository;
|
||||
private final YkUtils ykUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
|
@ -636,37 +641,55 @@ public class UserServiceImpl implements UserService {
|
|||
@Override
|
||||
@Transactional
|
||||
public Result changePwd(Long id, String oldPassword, String password, RequestContext requestContext) {
|
||||
String path = User.class.getSimpleName() + "_" + id;
|
||||
try (AutoCloseLock lock = lockFactory.getACLock(path)) {
|
||||
Assert.isTrue(lock.acquire(10, TimeUnit.SECONDS), "请求超时");
|
||||
Assert.isTrue(id.equals(requestContext.getTarget()), "非法请求");
|
||||
User user = userRepository.query(id);
|
||||
Assert.notNull(user, "用户信息不存在!");
|
||||
String salt = UUID.randomUUID().toString();
|
||||
// 加密
|
||||
SHAEncryptor sha = new SHAEncryptor();
|
||||
Encryptor encryptor = new AESEncryptor();
|
||||
// 对原密码解密,并校验。
|
||||
oldPassword = encryptor.decrypt(oldPassword.trim(), null);
|
||||
Assert.isTrue(StringUtils.hasText(oldPassword), "旧密码不存在");
|
||||
Result checkResult = this.check(id, oldPassword);
|
||||
if (checkResult.isFailed()) {
|
||||
return checkResult;
|
||||
|
||||
//1 需要优先调用运控系统修改密码接口,修改完成才能同步本端数据库
|
||||
// 根据userId获取运控系统用户信息
|
||||
log.info("查询当前用户信息,userId: " + id);
|
||||
JSONObject params = new JSONObject();
|
||||
params.put("userId", String.valueOf(id));
|
||||
params.put("oldPwd", oldPassword);
|
||||
params.put("newPwd", password);
|
||||
//请求运控修改密码机接口
|
||||
JSONObject result = ykUtils.call(YkInf.updateUserPwd, params, JSONObject.class);
|
||||
if (result.getInteger("returnCode") == 1) {
|
||||
log.info("运控密码修改成功");
|
||||
|
||||
String path = User.class.getSimpleName() + "_" + id;
|
||||
try (AutoCloseLock lock = lockFactory.getACLock(path)) {
|
||||
Assert.isTrue(lock.acquire(10, TimeUnit.SECONDS), "请求超时");
|
||||
Assert.isTrue(id.equals(requestContext.getTarget()), "非法请求");
|
||||
User user = userRepository.query(id);
|
||||
Assert.notNull(user, "用户信息不存在!");
|
||||
String salt = UUID.randomUUID().toString();
|
||||
// 加密
|
||||
SHAEncryptor sha = new SHAEncryptor();
|
||||
Encryptor encryptor = new AESEncryptor();
|
||||
// 对原密码解密,并校验。
|
||||
oldPassword = encryptor.decrypt(oldPassword.trim(), null);
|
||||
Assert.isTrue(StringUtils.hasText(oldPassword), "旧密码不存在");
|
||||
Result checkResult = this.check(id, oldPassword);
|
||||
if (checkResult.isFailed()) {
|
||||
return checkResult;
|
||||
}
|
||||
// 对前端传过来的密码进行解密
|
||||
password = encryptor.decrypt(password.trim(), null);
|
||||
Assert.isTrue(StringUtils.hasText(password), "新密码不存在。");
|
||||
String encrypt = sha.encrypt(password, salt);
|
||||
user.setPassword(encrypt);
|
||||
user.setLastPwdModifyDate(new Date());
|
||||
userRepository.update(user);
|
||||
// 准备随机数数据
|
||||
AccountSecurity security = securityRepository.getByTarget(user.getId(), Catalog.User);
|
||||
security.setSalt(salt);
|
||||
// 更新随机数
|
||||
securityRepository.update(security);
|
||||
return new Result(true, "修改密码成功");
|
||||
}
|
||||
// 对前端传过来的密码进行解密
|
||||
password = encryptor.decrypt(password.trim(), null);
|
||||
Assert.isTrue(StringUtils.hasText(password), "新密码不存在。");
|
||||
String encrypt = sha.encrypt(password, salt);
|
||||
user.setPassword(encrypt);
|
||||
user.setLastPwdModifyDate(new Date());
|
||||
userRepository.update(user);
|
||||
// 准备随机数数据
|
||||
AccountSecurity security = securityRepository.getByTarget(user.getId(), Catalog.User);
|
||||
security.setSalt(salt);
|
||||
// 更新随机数
|
||||
securityRepository.update(security);
|
||||
return new Result(true, "修改密码成功");
|
||||
|
||||
} else {
|
||||
return new Result(true, "修改密码失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -784,7 +807,7 @@ public class UserServiceImpl implements UserService {
|
|||
List<Role> managerRoles = roleRepository.listByManager(user.getId());
|
||||
if (!ListTool.isEmpty(managerRoles)) {
|
||||
for (Role role : managerRoles) {
|
||||
if(!roleNames.contains(role.getName())){
|
||||
if (!roleNames.contains(role.getName())) {
|
||||
roleNames.add(role.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
public class YkUtils {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
//参考application.yml配置文件
|
||||
//参考application.yml配置文件
|
||||
@Value("${yk.url:http://36.111.150.83:9527/}")
|
||||
private String url;
|
||||
|
||||
|
@ -23,23 +23,27 @@ public class YkUtils {
|
|||
private String systemId;
|
||||
|
||||
|
||||
public <T> T call(YkInf inf, JSONObject params, Class expectCls){
|
||||
YkReqVo reqVo = new YkReqVo(reqUserId,systemId,inf.getUrl(),params);
|
||||
public <T> T call(YkInf inf, JSONObject params, Class expectCls) {
|
||||
YkReqVo reqVo = new YkReqVo(reqUserId, systemId, inf.getUrl(), params);
|
||||
String str = JSONObject.toJSONString(reqVo);
|
||||
logger.info("call yk url [{}]" , url);
|
||||
logger.info("call yk method[{}] req params[{}]",reqVo.getMethod(),str);
|
||||
logger.info("call yk url [{}]", url);
|
||||
logger.info("call yk method[{}] req params[{}]", reqVo.getMethod(), str);
|
||||
String resultStr = HttpUtil.post(url, str, 10000);
|
||||
//logger.info("call method[{}] resp params[{}]",reqVo.getMethod(),resultStr);
|
||||
JSONObject result = JSONObject.parseObject(resultStr);
|
||||
logger.info("call yk result [{}]" , result.toString());
|
||||
logger.info("call yk result [{}]", result.toString());
|
||||
|
||||
if (result.getInteger("returnCode") != 1) {
|
||||
throw new IllegalArgumentException("调用运控接口异常" + result.getString("msg"));
|
||||
}
|
||||
if(JSONObject.class.equals(expectCls)){
|
||||
return (T)result.getJSONObject("data");
|
||||
}else{
|
||||
return (T)result.getString("data");
|
||||
if (JSONObject.class.equals(expectCls)) {
|
||||
if (result.getJSONObject("data") != null) {
|
||||
return (T) result.getJSONObject("data");
|
||||
} else {
|
||||
return (T) result;
|
||||
}
|
||||
} else {
|
||||
return (T) result.getString("data");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ public enum YkInf {
|
|||
getAppList("/system/sysapp/getAppList"),
|
||||
//获取运维工单接口
|
||||
getTaskList("/activiti/rwMainTask/getTaskList"),
|
||||
//修改密码接口
|
||||
updateUserPwd("/system/user/updateUserPwd"),
|
||||
|
||||
getTaskByUser("/system/task/countTaskByUser");
|
||||
|
||||
|
|
Loading…
Reference in New Issue