use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class AesCipherUtil method deCrypto.
/**
* 解密
* @param str
* @return java.lang.String
* @author dolyw.com
* @date 2018/8/31 16:56
*/
public static String deCrypto(String str) {
try {
// Security.addProvider(new com.sun.crypto.provider.SunJCE());
// 实例化支持AES算法的密钥生成器(算法名称命名需按规定,否则抛出异常)
// KeyGenerator 提供对称密钥生成器的功能,支持各种算法
KeyGenerator keygen = KeyGenerator.getInstance("AES");
// 将私钥encryptAESKey先Base64解密后转换为byte[]数组按128位初始化
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(Base64ConvertUtil.decode(encryptAESKey).getBytes());
keygen.init(128, secureRandom);
// SecretKey 负责保存对称密钥 生成密钥
SecretKey desKey = keygen.generateKey();
// 生成Cipher对象,指定其支持的AES算法,Cipher负责完成加密或解密工作
Cipher c = Cipher.getInstance("AES");
// 根据密钥,对Cipher对象进行初始化,DECRYPT_MODE表示解密模式
c.init(Cipher.DECRYPT_MODE, desKey);
// 该字节数组负责保存解密的结果,先对str进行Base64解密,将16进制转换为二进制
byte[] cipherByte = c.doFinal(HexConvertUtil.parseHexStr2Byte(Base64ConvertUtil.decode(str)));
return new String(cipherByte);
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
logger.error("getInstance()方法异常:{}", e.getMessage());
throw new BusinessException("getInstance()方法异常:" + e.getMessage());
} catch (UnsupportedEncodingException e) {
logger.error("Base64解密异常:{}", e.getMessage());
throw new BusinessException("Base64解密异常:" + e.getMessage());
} catch (InvalidKeyException e) {
logger.error("初始化Cipher对象异常:{}", e.getMessage());
throw new BusinessException("初始化Cipher对象异常:" + e.getMessage());
} catch (IllegalBlockSizeException | BadPaddingException e) {
logger.error("解密异常,密钥有误:{}", e.getMessage());
throw new BusinessException("解密异常,密钥有误:" + e.getMessage());
}
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class PropertiesUtil method readProperties.
/**
* 读取配置文件
* @param fileName
* @return void
* @author dolyw.com
* @date 2018/8/31 17:29
*/
public static void readProperties(String fileName) {
InputStream in = null;
try {
in = PropertiesUtil.class.getResourceAsStream("/" + fileName);
BufferedReader bf = new BufferedReader(new InputStreamReader(in));
PROP.load(bf);
} catch (IOException e) {
logger.error("PropertiesUtil工具类读取配置文件出现IOException异常:{}", e.getMessage());
throw new BusinessException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage());
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
logger.error("PropertiesUtil工具类读取配置文件出现IOException异常:{}", e.getMessage());
throw new BusinessException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage());
}
}
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class DeptServiceImpl method addDept.
@Override
public void addDept(SysDept vo) {
String relationCode;
String deptCode = this.getNewDeptCode();
SysDept parent = sysDeptMapper.selectById(vo.getPid());
if ("0".equals(vo.getPid())) {
relationCode = deptCode;
} else if (null == parent) {
throw new BusinessException(BaseResponseCode.DATA_ERROR);
} else {
relationCode = parent.getRelationCode() + deptCode;
}
vo.setDeptNo(deptCode);
vo.setRelationCode(relationCode);
vo.setStatus(1);
sysDeptMapper.insert(vo);
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class DeptServiceImpl method deptTreeList.
@Override
public List<DeptRespNodeVO> deptTreeList(String deptId, Boolean disabled) {
List<SysDept> list;
if (StringUtils.isEmpty(deptId)) {
list = sysDeptMapper.selectList(Wrappers.emptyWrapper());
} else {
SysDept sysDept = sysDeptMapper.selectById(deptId);
if (sysDept == null) {
throw new BusinessException(BaseResponseCode.DATA_ERROR);
}
LambdaQueryWrapper<SysDept> queryWrapper = Wrappers.<SysDept>lambdaQuery().likeRight(SysDept::getRelationCode, sysDept.getRelationCode());
List<Object> childIds = sysDeptMapper.selectObjs(queryWrapper);
list = sysDeptMapper.selectList(Wrappers.<SysDept>lambdaQuery().notIn(SysDept::getId, childIds));
}
// 默认加一个顶级方便新增顶级部门
DeptRespNodeVO respNodeVO = new DeptRespNodeVO();
respNodeVO.setTitle("默认顶级部门");
respNodeVO.setId("0");
respNodeVO.setSpread(true);
respNodeVO.setDisabled(disabled);
respNodeVO.setChildren(getTree(list));
List<DeptRespNodeVO> result = new ArrayList<>();
result.add(respNodeVO);
return result;
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class UserServiceImpl method updatePwd.
@Override
public void updatePwd(SysUser vo) {
SysUser sysUser = sysUserMapper.selectById(vo.getId());
if (sysUser == null) {
throw new BusinessException(BaseResponseCode.DATA_ERROR);
}
if ("test".equals(env) && "guest".equals(sysUser.getUsername())) {
throw new BusinessException("演示环境禁止修改演示账号密码");
}
if (!PasswordUtils.matches(sysUser.getSalt(), vo.getOldPwd(), sysUser.getPassword())) {
throw new BusinessException(BaseResponseCode.OLD_PASSWORD_ERROR);
}
if (sysUser.getPassword().equals(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()))) {
throw new BusinessException("新密码不能与旧密码相同");
}
sysUser.setPassword(PasswordUtils.encode(vo.getNewPwd(), sysUser.getSalt()));
sysUserMapper.updateById(sysUser);
// 退出用户
httpSessionService.abortAllUserByToken();
}
Aggregations