use of com.itrus.portal.utils.UIDInfoUtils in project portal by ixinportal.
the class DownLoadCertServiceImpl method downLoadCert.
/**
* 下载证书
*
* @param product
* @param ra
* @param bill
* @param digitalcert
* @param uidIdx
* @param csr
* @return
* @throws Exception
*/
public CertInfo downLoadCert(Product product, RaAccount ra, Bill bill, DigitalCert digitalcert, Integer uidIdx, String csr, String autoidType, Integer autoidValue) throws Exception {
CertInfo racertinfo = null;
// 解析项目产品中,certinfo配置信息
JSONArray certinfo = JSONArray.parseArray(product.getCertinfo());
// 解析订单中uid信息{"ADDTIONAL_FIELD1_1":"","ADDTIONAL_FIELD3_1":"","ADDTIONAL_FIELD4_1":"G2016071301","inputName":"inputValue"}
JSONObject uid = JSONObject.parseObject(bill.getUid());
com.itrus.portal.utils.CertUtlis certutil = new com.itrus.portal.utils.CertUtlis();
// 组织RA参数
cn.topca.tca.ra.service.UserInfo rauserinfo = new cn.topca.tca.ra.service.UserInfo();
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
for (int i = 0; i < certinfo.size(); i++) {
JSONObject obj = certinfo.getJSONObject(i);
String raParaName = obj.getString("raParaName");
if (raParaName == null)
continue;
// "autoid":"yes",
String autoid = obj.getString("autoid");
// "raParaName": "userName",
String constValue = obj.getString("constValue");
// "constValue": "test@itrus.com.cn"
String refName = obj.getString("refName");
String val = null;
if (constValue != null) {
val = constValue;
} else if (refName != null) {
if (refName.indexOf("?") == -1)
val = uidutils.getUidInfo(bill.getId(), refName);
else {
val = "";
String[] arr = refName.split("\\?", 2);
if (arr.length == 2) {
String condition = arr[0].trim();
String[] refarr = arr[1].split(":", 2);
if (refarr.length == 2) {
boolean bret = uidutils.checkCondition(bill.getId(), condition);
if (bret)
val = uidutils.getUidInfo(bill.getId(), refarr[0].trim());
else
val = uidutils.getUidInfo(bill.getId(), refarr[1].trim());
}
}
}
} else if (autoid != null) {
// "autoidPrev":"G",
String autoidPrev = obj.getString("autoidPrev");
// "autoidType":"mytestautoid",
autoidType = obj.getString("autoidType");
// "inputName": "ADDTIONAL_FIELD4",存在多个值
String uidval = uid.getString(obj.getString("inputName") + "_" + uidIdx.toString());
val = uidval;
if (StringUtils.isNotBlank(uidval) && uidval.indexOf(autoidPrev) == 0) {
// "autoidPrevDate":"yyyyMMdd",
String autoidPrevDate = obj.getString("autoidPrevDate");
try {
if (autoidPrevDate == null || autoidPrevDate.length() == 0)
autoidValue = Integer.parseInt(uidval.substring(autoidPrev.length()));
else
autoidValue = Integer.parseInt(uidval.substring(autoidPrev.length() + autoidPrevDate.length()));
} catch (Exception e) {
e.printStackTrace();
autoidValue = 0;
}
}
} else {
val = uid.getString(obj.getString("inputName") + "_" + uidIdx.toString());
}
certutil.setUserInfoVal(rauserinfo, raParaName, val);
}
// 证书有效期
// {"0":"1年","1":"2年","2":"3年","3":"5年","4":"10年"})
Integer certValidity = 5;
boolean hasProductSpec = false;
// 判断订单中是否配了产品规格且有期限
ProductSpec productSpec = null;
if (null != bill.getProductSpec() && 0 != bill.getProductSpec()) {
productSpec = productSpecService.getProductSpec(bill.getProductSpec());
if (StringUtils.isNotBlank(productSpec.getProductValid())) {
hasProductSpec = true;
}
}
if (hasProductSpec) {
Integer day = Integer.parseInt(productSpec.getProductValid());
if (day == 100) {
// TODO 测试时候,配置年限为100年,则有效期为10天
certValidity = 10;
} else {
certValidity = 365 * day + 1 + (day / 4);
}
} else {
if ("0".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 1 + 1;
} else if ("1".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 2 + 1;
} else if ("2".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 3 + 1;
} else if ("3".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 5 + 2;
} else if ("4".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 10 + 2;
}
}
if (ra.getAaPassword() != null)
ra.setAaPassword(AESencrp.decrypt(ra.getAaPassword(), dbEncKey));
racertinfo = certutil.enrollCertByWS(csr, ra, rauserinfo, certValidity);
return racertinfo;
}
use of com.itrus.portal.utils.UIDInfoUtils in project portal by ixinportal.
the class QueryBillController method makeSeal.
private void makeSeal(Long billId, Model uiModel) throws EncDecException, Exception {
// 获取签章模版
Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", billId);
// 查询项目产品
Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct());
if (null == product.getMakeSealServer() || product.getMakeSealServer() <= 0) {
// log.error("该产品未配置签章服务");
return;
}
MakeSealServer makeSealServer = sqlSession.selectOne("com.itrus.portal.db.MakeSealServerMapper.selectByPrimaryKey", product.getMakeSealServer());
// 签章服务配置
List<MakeSealConfig> makeSealConfigs = sqlSession.selectList("com.itrus.portal.db.MakeSealConfigMapper.selectByExample");
if (makeSealConfigs.isEmpty()) {
log.error("没有找到签章服务配置");
return;
}
MakeSealConfig makeSealConfig = makeSealConfigs.get(0);
makeSealConfig.setAddressKey(AESencrp.decrypt(makeSealConfig.getAddressKey(), dbEncKey));
uiModel.addAttribute("makeSealConfig", makeSealConfig);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
uiModel.addAttribute("makeSealServer", makeSealServer);
}
use of com.itrus.portal.utils.UIDInfoUtils in project portal by ixinportal.
the class BillClientController method makeSeal.
/**
* 获取签章模版信息
*
* @param billId
* @param uiModel
* @throws EncDecException
* @throws Exception
*/
private void makeSeal(Long billId, Model uiModel) throws EncDecException, Exception {
// 获取签章模版
Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", billId);
// 查询项目产品
Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct());
if (null == product.getMakeSealServer() || product.getMakeSealServer() <= 0) {
// log.error("该产品未配置签章服务");
return;
}
MakeSealServer makeSealServer = sqlSession.selectOne("com.itrus.portal.db.MakeSealServerMapper.selectByPrimaryKey", product.getMakeSealServer());
// 签章服务配置
List<MakeSealConfig> makeSealConfigs = sqlSession.selectList("com.itrus.portal.db.MakeSealConfigMapper.selectByExample");
if (makeSealConfigs.isEmpty()) {
log.error("没有找到签章服务配置");
return;
}
MakeSealConfig makeSealConfig = makeSealConfigs.get(0);
makeSealConfig.setAddressKey(AESencrp.decrypt(makeSealConfig.getAddressKey(), dbEncKey));
uiModel.addAttribute("makeSealConfig", makeSealConfig);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
uiModel.addAttribute("makeSealServer", makeSealServer);
}
use of com.itrus.portal.utils.UIDInfoUtils in project portal by ixinportal.
the class MakeCertController method makeSeal.
/**
* 获取签章模版
*
* @param billId
* @return
* @throws Exception
* @throws EncDecException
*/
@RequestMapping(value = "/makeSeal", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> makeSeal(@RequestParam(value = "billId", required = true) Long billId, @RequestParam(value = "productId", required = false) Long productId, HttpServletRequest request, HttpServletResponse response) throws EncDecException, Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put("retCode", 0);
// 获取签章模版
Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", billId);
// 查询项目产品
Product product = null;
// 如为组合产品productId不为空
if (null == productId) {
product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct());
} else {
product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", productId);
}
if (null == product.getMakeSealServer() || product.getMakeSealServer() <= 0) {
map.put("retMsg", "该产品未配置签章服务");
return map;
}
MakeSealServer makeSealServer = sqlSession.selectOne("com.itrus.portal.db.MakeSealServerMapper.selectByPrimaryKey", product.getMakeSealServer());
// 签章服务配置
List<MakeSealConfig> makeSealConfigs = sqlSession.selectList("com.itrus.portal.db.MakeSealConfigMapper.selectByExample");
if (makeSealConfigs.isEmpty()) {
map.put("retMsg", "没有找到签章服务配置");
return map;
}
/**
* 增加百润和以前的点聚
*/
if (makeSealServer.getFirm().contains("点聚")) {
// 新加if
if (makeSealConfigs.get(0).getName().equals(makeSealServer.getFirm())) {
MakeSealConfig makeSealConfig = makeSealConfigs.get(0);
makeSealConfig.setAddressKey(AESencrp.decrypt(makeSealConfig.getAddressKey(), dbEncKey));
map.put("retCode", 1);
map.put("makeSealConfig", makeSealConfig);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
} else {
MakeSealConfig makeSealConfig = makeSealConfigs.get(1);
makeSealConfig.setAddressKey(AESencrp.decrypt(makeSealConfig.getAddressKey(), dbEncKey));
map.put("retCode", 1);
map.put("makeSealConfig", makeSealConfig);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
}
}
// 新加百润
if (makeSealServer.getFirm().contains("百润")) {
// 第一条是点聚,第二条是百润
if (makeSealConfigs.get(0).getName().equals(makeSealServer.getFirm())) {
MakeSealConfig makeSealConfig = makeSealConfigs.get(0);
makeSealConfig.setAddressKey(AESencrp.decrypt(makeSealConfig.getAddressKey(), dbEncKey));
map.put("retCode", 1);
map.put("makeSealConfig", makeSealConfig);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
} else {
MakeSealConfig makeSealConfig = makeSealConfigs.get(1);
makeSealConfig.setAddressKey(AESencrp.decrypt(makeSealConfig.getAddressKey(), dbEncKey));
map.put("retCode", 1);
map.put("makeSealConfig", makeSealConfig);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
}
}
map.put("makeSealServer", makeSealServer);
return map;
}
use of com.itrus.portal.utils.UIDInfoUtils in project portal by ixinportal.
the class MakeCertController method makecert.
// 制作证书
@RequestMapping(value = "/make/{id}", produces = "text/html")
@ResponseBody
public Map<String, Object> makecert(@RequestParam(value = "uidIdx", required = true) Integer uidIdx, @RequestParam(value = "csr", required = true) String csr, @RequestParam(value = "pid", required = true) Long pid, @RequestParam(value = "index", required = false) Integer index, @RequestParam(value = "keySn", required = false) String keySn, @PathVariable("id") Long id) {
Map<String, Object> ret = new HashMap<String, Object>();
// 查询订单
Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", id);
// 查询项目产品
Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", pid);
// 解析项目产品中,certinfo配置信息
JSONArray certinfo = JSONArray.parseArray(product.getCertinfo());
// 解析订单中uid信息{"ADDTIONAL_FIELD1_1":"","ADDTIONAL_FIELD3_1":"","ADDTIONAL_FIELD4_1":"G2016071301","inputName":"inputValue"}
JSONObject uid = JSONObject.parseObject(bill.getUid());
if (null != index) {
if (index == 1) {
uid = JSONObject.parseObject(bill.getUid1());
}
if (index == 2) {
uid = JSONObject.parseObject(bill.getUid2());
}
if (index == 3) {
uid = JSONObject.parseObject(bill.getUid3());
}
}
// 获取产品、RA配置
RaAccount ra = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectByPrimaryKey", product.getRa());
com.itrus.portal.utils.CertUtlis certutil = new com.itrus.portal.utils.CertUtlis();
// 证书配置
DigitalCert digitalcert = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product.getCert());
// 组织RA参数
cn.topca.tca.ra.service.UserInfo rauserinfo = new cn.topca.tca.ra.service.UserInfo();
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
String autoidType = "";
Integer autoidValue = 0;
for (int i = 0; i < certinfo.size(); i++) {
JSONObject obj = certinfo.getJSONObject(i);
String raParaName = obj.getString("raParaName");
if (raParaName == null)
continue;
// "autoid":"yes",
String autoid = obj.getString("autoid");
// "raParaName": "userName",
String constValue = obj.getString("constValue");
// "constValue": "test@itrus.com.cn"
String refName = obj.getString("refName");
String val = null;
if (constValue != null) {
val = constValue;
} else if (refName != null) {
if (refName.indexOf("?") == -1)
val = uidutils.getUidInfo(bill.getId(), refName);
else {
val = "";
String[] arr = refName.split("\\?", 2);
if (arr.length == 2) {
String condition = arr[0].trim();
String[] refarr = arr[1].split(":", 2);
if (refarr.length == 2) {
boolean bret = uidutils.checkCondition(bill.getId(), condition);
if (bret)
val = uidutils.getUidInfo(bill.getId(), refarr[0].trim());
else
val = uidutils.getUidInfo(bill.getId(), refarr[1].trim());
}
}
}
} else if (autoid != null) {
// "autoidPrev":"G",
String autoidPrev = obj.getString("autoidPrev");
// "autoidType":"mytestautoid",
autoidType = obj.getString("autoidType");
// "inputName": "ADDTIONAL_FIELD4",存在多个值
String uidval = uid.getString(obj.getString("inputName") + "_" + uidIdx.toString());
val = uidval;
if (StringUtils.isNotBlank(uidval) && uidval.indexOf(autoidPrev) == 0) {
// "autoidPrevDate":"yyyyMMdd",
String autoidPrevDate = obj.getString("autoidPrevDate");
try {
if (autoidPrevDate == null || autoidPrevDate.length() == 0)
autoidValue = Integer.parseInt(uidval.substring(autoidPrev.length()));
else
autoidValue = Integer.parseInt(uidval.substring(autoidPrev.length() + autoidPrevDate.length()));
} catch (Exception e) {
e.printStackTrace();
autoidValue = 0;
}
}
} else {
val = uid.getString(obj.getString("inputName") + "_" + uidIdx.toString());
}
certutil.setUserInfoVal(rauserinfo, raParaName, val);
}
// 证书有效期
// {"0":"1年","1":"2年","2":"3年","3":"5年","4":"10年"})
Integer certValidity = 5;
boolean hasProductSpec = false;
// 判断订单中是否配了产品规格且有期限
ProductSpec productSpec = null;
if (null != bill.getProductSpec() && 0 != bill.getProductSpec()) {
productSpec = productSpecService.getProductSpec(bill.getProductSpec());
if (StringUtils.isNotBlank(productSpec.getProductValid())) {
hasProductSpec = true;
}
}
if (null != index) {
if (index == 1)
if (null != bill.getProductSpec1() && 0 != bill.getProductSpec1()) {
productSpec = productSpecService.getProductSpec(bill.getProductSpec1());
if (StringUtils.isNotBlank(productSpec.getProductValid())) {
hasProductSpec = true;
}
}
if (index == 2)
if (null != bill.getProductSpec2() && 0 != bill.getProductSpec2()) {
productSpec = productSpecService.getProductSpec(bill.getProductSpec2());
if (StringUtils.isNotBlank(productSpec.getProductValid())) {
hasProductSpec = true;
}
}
if (index == 3)
if (null != bill.getProductSpec3() && 0 != bill.getProductSpec3()) {
productSpec = productSpecService.getProductSpec(bill.getProductSpec3());
if (StringUtils.isNotBlank(productSpec.getProductValid())) {
hasProductSpec = true;
}
}
}
if (hasProductSpec) {
Integer day = Integer.parseInt(productSpec.getProductValid());
if (day == 100) {
// TODO 测试时候,配置年限为100年,则有效期为10天
certValidity = 1;
} else {
certValidity = 365 * day + 1 + (day / 4);
}
} else {
if ("0".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 1 + 1;
} else if ("1".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 2 + 1;
} else if ("2".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 3 + 1;
} else if ("3".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 5 + 2;
} else if ("4".compareTo(digitalcert.getCertDeadline()) == 0) {
certValidity = 365 * 10 + 2;
} else if ("-1".compareTo(digitalcert.getCertDeadline()) == 0) {
// 数字证书没有配置年限(-1),默认10天有效期
certValidity = 10;
}
}
log.error("证书期限*********" + certValidity);
// 调用RA
CertInfo racertinfo = null;
try {
if (ra.getAaPassword() != null)
ra.setAaPassword(AESencrp.decrypt(ra.getAaPassword(), dbEncKey));
racertinfo = certutil.enrollCertByWS(csr, ra, rauserinfo, certValidity);
} catch (RaServiceUnavailable_Exception e) {
e.printStackTrace();
ret.put("status", 1001);
ret.put("message", e.getMessage());
// 记录日志
String oper = "制作证书失败";
String info = "企业名称: " + uidutils.getUidInfo(bill.getId(), "enterprise.enterpriseName") + ",参数:" + ToStringBuilder.reflectionToString(rauserinfo) + ",异常信息: " + e.toString();
LogUtil.adminlog(sqlSession, oper, info);
return ret;
} catch (Exception e) {
e.printStackTrace();
ret.put("status", 1002);
ret.put("message", e.getMessage());
// 记录日志
String oper = "制作证书失败";
String info = "企业名称: " + uidutils.getUidInfo(bill.getId(), "enterprise.enterpriseName") + "参数:" + ToStringBuilder.reflectionToString(rauserinfo) + ",异常信息: " + e.toString();
LogUtil.adminlog(sqlSession, oper, info);
return ret;
}
// 解析数字证书信息
// 存储数字证书信息
CertBuf certbuf = new CertBuf();
certbuf.setCreateTime(new Date());
certbuf.setCertBuf(racertinfo.getCertSignBuf());
certbuf.setCertKmcRep1(racertinfo.getCertKmcRep1());
certbuf.setCertKmcRep2(racertinfo.getCertKmcRep2());
certbuf.setCertsignBuf(racertinfo.getCertSignBuf());
certbuf.setEncUserCert(racertinfo.getCertSignBufKmc());
sqlSession.insert("com.itrus.portal.db.CertBufMapper.insert", certbuf);
UserCert usercert = new UserCert();
usercert.setBill(bill.getId());
usercert.setRaAccount(ra.getId());
usercert.setCertBuf(certbuf.getId());
usercert.setUidIdx(uidIdx);
usercert.setCertDn(racertinfo.getCertSubjectDn());
usercert.setCertSn(racertinfo.getCertSerialNumber());
usercert.setIssuerDn(racertinfo.getCertIssuerDn());
usercert.setCertStatus("1");
usercert.setCertUid("certUid");
usercert.setProduct(pid);
if (StringUtils.isNotBlank(keySn))
// 设置证书keySn
usercert.setKeySn(keySn);
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
usercert.setCertStartTime(sdf.parse(racertinfo.getCertNotBefore()));
usercert.setCertEndTime(sdf.parse(racertinfo.getCertNotAfter()));
} catch (java.text.ParseException e) {
e.printStackTrace();
}
usercert.setSha1Fingerprint("setSha1Fingerprint");
// autoid 数据
if (!autoidType.equals("")) {
usercert.setAutoidType(autoidType);
usercert.setAutoidValue(autoidValue);
}
usercert.setEnterprise(bill.getEnterprise());
try {
sqlSession.insert("com.itrus.portal.db.UserCertMapper.insert", usercert);
} catch (Exception e) {
e.printStackTrace();
}
// 查询userCert中,该bill的记录数目,如果数据 大于等于 bill 里面的购买数量,则修改该bill为制证完成
updateBillStatus(bill, product);
// 记录日志
String oper = "制作证书";
String info = "数字证书: " + racertinfo.getCertSerialNumber() + ", " + racertinfo.getCertSubjectDn();
LogUtil.adminlog(sqlSession, oper, info);
// 返回数字证书
ret.put("certChain", racertinfo.getCertSignBufP7());
ret.put("certsignBuf", racertinfo.getCertSignBuf());
ret.put("certKmcRep1", racertinfo.getCertKmcRep1());
ret.put("certKmcRep2", racertinfo.getCertKmcRep2());
// 加密证书
ret.put("encUserCert", racertinfo.getCertSignBufKmc());
ret.put("status", 0);
return ret;
}
Aggregations