use of com.itrus.portal.db.RaAccount in project portal by ixinportal.
the class RaAccountController method delete.
// 删除
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("id") Long id, HttpServletRequest request, Model uiModel) throws Exception {
RaAccount raAccount = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectByPrimaryKey", id);
String message = null;
if (raAccount == null) {
// uiModel.addAttribute("message", "未找到要删除RA配置");
message = "未找到要删除RA配置";
} else {
try {
sqlSession.delete("com.itrus.portal.db.RaAccountMapper.deleteByPrimaryKey", id);
String oper = "删除RA";
String info = "RA名称: " + raAccount.getRaName();
LogUtil.adminlog(sqlSession, oper, info);
// uiModel.addAttribute("message", "要删除RA配置【" + raAccount.getRaName() + "】存在关联,无法删除");
} catch (Exception e) {
// uiModel.addAttribute("message", "要删除RA配置【" + raAccount.getRaName() + "】存在关联,无法删除");
message = "要删除RA配置【" + raAccount.getRaName() + "】存在关联,无法删除";
}
}
return getReferer(request, "redirect:/raaccount" + (message == null ? "" : "?message=1"), true);
}
use of com.itrus.portal.db.RaAccount in project portal by ixinportal.
the class RaAccountController method updateForm.
// 返回修改页面
@RequestMapping(value = "/{id}", params = "form", produces = "text/html")
public String updateForm(@PathVariable("id") Long id, Model uiModel) throws Exception {
RaAccount raAccount = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectByPrimaryKey", id);
// 对服务连接密码进行解密
/*if (StringUtils.isNotBlank(raAccount.getAaPassword())
&& Base64.isBase64(raAccount.getAaPassword().getBytes()))
raAccount.setAaPassword(AESencrp.decrypt(raAccount.getAaPassword(),dbEncKey));*/
uiModel.addAttribute("raAccount", raAccount);
return "raaccount/update";
}
use of com.itrus.portal.db.RaAccount 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;
}
use of com.itrus.portal.db.RaAccount in project portal by ixinportal.
the class CertificateController method update.
/**
* 修改处理
*
* @param configuration
* @param photoCodeImg
* @param type
* 新建类型 3是新建签章 2是新建证书1修改
* @param uiModel
* @return
*/
@RequestMapping(method = RequestMethod.POST, value = "/{type}", produces = "text/html")
public String update(@Valid EvidenceCertificate configuration, @RequestParam(value = "photoCodeImg", required = false) String photoCodeImg, @PathVariable("type") int type, Model uiModel) {
if (type == 1) {
// System.out.println("新建签章" + configuration.getSignatureType());
// 获取证书信息
EvidenceCertificate econfiguration = certificateService.selectById(configuration.getId());
EvidenceSecretKey secretkey = new EvidenceSecretKey();
try {
if (StringUtils.isNotEmpty(photoCodeImg)) {
// 获取密钥信息
secretkey = sqlSession.selectOne("com.itrus.portal.db.EvidenceSecretKeyMapper.selectByPrimaryKey", econfiguration.getEvidenceSecretKey());
File imgDir = filePathUtils.getEnterpriseFile(secretkey.getAlias());
File frontImg = filePathUtils.saveImg(imgDir, null, photoCodeImg, IMG_DEFAULT_TYPE, IMG_NAME_VERIFY);
if (frontImg != null && frontImg.isFile()) {
configuration.setPhotoCodeImg(frontImg.getName());
configuration.setPhotoCodeImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
}
}
if (configuration.getId() == null) {
certificateService.insert(configuration);
} else {
String s = String.valueOf(econfiguration.getEvidenceSecretKey());
Long keyid = Long.valueOf(s);
EvidenceSecretKey secret = secrtkey.selectById(keyid);
boolean is = certificateService.setSeal(secret.getAlias(), photoCodeImg);
if (is) {
certificateService.update(configuration);
}
}
} catch (Exception e) {
e.printStackTrace();
String oper = "修改签章失败";
String info = "错误原因:" + e.toString();
LogUtil.evidencelog(sqlSession, null, oper, info);
error = "修改签章失败";
return "redirect:/certificate/" + configuration.getId() + "/" + 3;
}
if (econfiguration.getIsCertificate() == null || econfiguration.getIsCertificate() != 1) {
JSONObject ret_data = null;
ret_data = JSONObject.parseObject(configuration.getSubject());
String cn = ret_data.getString("userName");
String ou = ret_data.getString("userOrgunit");
// String emali = ret_data.getString("EMAILADDRESS");
String O = ret_data.getString("userOrganization");
String dn = "CN=" + cn + "OU=" + ou + "O=" + O;
String csr = certificateService.genCsr(secretkey.getAlias(), configuration.getArithmetic(), dn);
if (csr != null) {
RaAccount ra = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectByPrimaryKey", configuration.getRaAccount());
CertUtlis certutil = new CertUtlis();
// UserInfo rauserinfo = new UserInfo();
// Weibo类在下边定义
UserInfo rauserinfo = JSON.parseObject(configuration.getSubject(), UserInfo.class);
// System.out.println(rauserinfo.getUserAdditionalField1()+rauserinfo.getUserName());
// UserInfo = (UserInfo)JSONObject.toBean(ret_data,UserInfo.class);//将建json对象转换为Person对象
// System.out.println(configuration.getSubject());
/* rauserinfo.setUserName(cn);
rauserinfo.setUserEmail(emali);
rauserinfo.setUserAdditionalField1(ou);
rauserinfo.setUserOrganization(O); */
// 证书有效期
Integer certValidity = 7;
if ("0".equals(configuration.getPeriod())) {
certValidity = null;
} else if (1 == configuration.getPeriod()) {
certValidity = 365 * 1 + 1;
} else if (3 == configuration.getPeriod()) {
certValidity = 365 * 3 + 1;
} else if (5 == configuration.getPeriod()) {
certValidity = 365 * 5 + 2;
} else if (10 == configuration.getPeriod()) {
certValidity = 365 * 10 + 2;
}
// 调用RA
CertInfo racertinfo = null;
try {
if (ra.getAaPassword() != null) {
ra.setAaPassword(AESencrp.decrypt(ra.getAaPassword(), dbEncKey));
}
racertinfo = certutil.enrollCertByWS(csr, ra, rauserinfo, certValidity);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
String oper = "RA调用失败";
String info = "错误原因:" + e.toString();
LogUtil.evidencelog(sqlSession, null, oper, info);
error = "RA调用失败";
return "redirect:/certificate/" + configuration.getId() + "/" + 3;
}
if (racertinfo != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
EvidenceCert cert = new EvidenceCert();
cert.setCertBase64(racertinfo.getCertSignBuf());
cert.setCreateTime(new Date());
cert.setCertSerialnumber(racertinfo.getCertSerialNumber());
cert.setIssuerdn(racertinfo.getCertIssuerDn());
cert.setSubjectdn(racertinfo.getCertSubjectDn());
try {
configuration.setStartTime(sdf.parse(racertinfo.getCertNotBefore()));
configuration.setEndTime(sdf.parse(racertinfo.getCertNotAfter()));
cert.setStartTime(sdf.parse(racertinfo.getCertNotBefore()));
cert.setEndTime(sdf.parse(racertinfo.getCertNotAfter()));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cert.setCreateTime(new Date());
sqlSession.insert("com.itrus.portal.db.EvidenceCertMapper.insert", cert);
configuration.setCert(cert.getId().toString());
configuration.setCertp7(racertinfo.getCertSignBufP7());
configuration.setCertSerialnumber(racertinfo.getCertSerialNumber());
boolean is = certificateService.setCertitifate(secretkey.getAlias(), racertinfo.getCertSignBuf(), racertinfo.getCertSignBufP7());
if (is) {
if ("0".equals(configuration.getArithmetic())) {
configuration.setArithmetic(null);
}
if (StringUtils.isNotEmpty(configuration.getSubject())) {
configuration.setSubject(configuration.getSubject());
}
String s = String.valueOf(secretkey.getId());
int keyid = Integer.parseInt(s);
configuration.setEvidenceSecretKey(keyid);
configuration.setCreateTime(new Date());
configuration.setCreator(getAdmin().getName());
certificateService.update(configuration);
configuration.setSignatureType(2);
String oper = "证书产生成功";
String info = "证书名称:" + configuration.getCertificateName();
LogUtil.evidencelog(sqlSession, null, oper, info);
}
}
} else {
error = "csr产生失败";
return "redirect:/certificate/" + configuration.getId() + "/" + 3;
}
}
} else if (type == 3) {
EvidenceCertificate econfiguration = certificateService.selectById(configuration.getId());
EvidenceSecretKey secretkey = new EvidenceSecretKey();
try {
if (StringUtils.isNotEmpty(photoCodeImg)) {
// 获取密钥信息
secretkey = sqlSession.selectOne("com.itrus.portal.db.EvidenceSecretKeyMapper.selectByPrimaryKey", econfiguration.getEvidenceSecretKey());
File imgDir = filePathUtils.getEnterpriseFile(secretkey.getAlias());
File frontImg = filePathUtils.saveImg(imgDir, null, photoCodeImg, IMG_DEFAULT_TYPE, IMG_NAME_VERIFY);
if (frontImg != null && frontImg.isFile()) {
configuration.setPhotoCodeImg(frontImg.getName());
configuration.setPhotoCodeImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
}
}
if (configuration.getId() == null) {
certificateService.insert(configuration);
} else {
String s = String.valueOf(econfiguration.getEvidenceSecretKey());
Long keyid = Long.valueOf(s);
EvidenceSecretKey secret = secrtkey.selectById(keyid);
boolean is = certificateService.setSeal(secret.getAlias(), photoCodeImg);
if (is) {
certificateService.update(configuration);
}
}
} catch (Exception e) {
e.printStackTrace();
String oper = "新建签章失败";
String info = "错误原因:" + e.toString();
LogUtil.evidencelog(sqlSession, null, oper, info);
error = "新建签章失败";
return "redirect:/certificate/" + configuration.getId() + "/" + 2;
}
} else {
// System.out.println("新建证书");
EvidenceSecretKey secret = new EvidenceSecretKey();
// List<EvidenceSecretKey> list = secrtkey.selecttype(configuration.getKeyType());
// log.error("list="+list.size());
// if(econfiguration.getIsCertificate()!=null && econfiguration.getIsCertificate()==1){
/*if (list != null && list.size() != 0) {
for (EvidenceSecretKey e : list) {
EvidenceCertificate certificate = certificateService.selectone(e.getId());
if (certificate == null) {
secret.setAlias(e.getAlias());
secret.setId(e.getId());
break;
}
}
if (StringUtils.isEmpty(secret.getAlias())) {
List<EvidenceSecretKey> secter = secrtkey.certufucateInterface(getAdmin().getName());
//List<EvidenceSecretKey> lists = secrtkey.selecttype(configuration.getKeyType());
if (secter != null) {
for (EvidenceSecretKey e : secter) {
EvidenceCertificate certificate = certificateService.selectone(e.getId());
if (certificate == null) {
secret.setAlias(e.getAlias());
secret.setId(e.getId());
break;
}
}
}
}
} else */
{
/*EvidenceSecretKey*/
secret = secrtkey.certufucateInterface(getAdmin().getName(), configuration.getKeyType());
// List<EvidenceSecretKey> lists = secrtkey.selecttype(configuration.getKeyType());
/*if (secter != null) {
for (EvidenceSecretKey e : secter) {
EvidenceCertificate certificate = certificateService.selectone(e.getId());
if (certificate == null) {
secret.setAlias(e.getAlias());
secret.setId(e.getId());
break;
}
}
}*/
}
/* }else{
secret = sqlSession.selectOne(
"com.itrus.portal.db.EvidenceSecretKeyMapper.selectByPrimaryKey",
econfiguration.getEvidenceSecretKey());
}*/
JSONObject ret_data = null;
ret_data = JSONObject.parseObject(configuration.getSubject());
String cn = ret_data.getString("userName");
String ou = ret_data.getString("userOrgunit");
// String emali = ret_data.getString("EMAILADDRESS");
String O = ret_data.getString("userOrganization");
String dn = "CN=" + cn + "OU=" + ou + "O=" + O;
log.error("Alias=" + secret.getAlias() + ",Arithmetic=" + configuration.getArithmetic());
String csr = certificateService.genCsr(secret.getAlias(), configuration.getArithmetic(), dn);
log.error("csr=" + csr);
if (csr != null) {
RaAccount ra = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectByPrimaryKey", configuration.getRaAccount());
CertUtlis certutil = new CertUtlis();
// UserInfo rauserinfo = new UserInfo();
// System.out.println(configuration.getSubject());
// Weibo类在下边定义
UserInfo rauserinfo = JSON.parseObject(configuration.getSubject(), UserInfo.class);
// System.out.println(rauserinfo.getUserAdditionalField1()+rauserinfo.getUserName());
/*rauserinfo.setUserName(cn);
rauserinfo.setUserEmail(emali);
rauserinfo.setUserAdditionalField1(ou);
rauserinfo.setUserOrganization(O);*/
// 证书有效期
Integer certValidity = 7;
if ("0".equals(configuration.getPeriod())) {
certValidity = null;
} else if (1 == configuration.getPeriod()) {
certValidity = 365 * 1 + 1;
} else if (3 == configuration.getPeriod()) {
certValidity = 365 * 3 + 1;
} else if (5 == configuration.getPeriod()) {
certValidity = 365 * 5 + 2;
} else if (10 == configuration.getPeriod()) {
certValidity = 365 * 10 + 2;
}
// 调用RA
CertInfo racertinfo = null;
try {
if (ra.getAaPassword() != null) {
ra.setAaPassword(AESencrp.decrypt(ra.getAaPassword(), dbEncKey));
}
racertinfo = certutil.enrollCertByWS(csr, ra, rauserinfo, certValidity);
log.error("racertinfo=" + racertinfo);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
String oper = "RA调用失败";
String info = "错误原因:" + e.toString();
LogUtil.evidencelog(sqlSession, null, oper, info);
uiModel.addAttribute("error", "RA调用失败");
return "certificate/create";
}
if (racertinfo != null) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
EvidenceCert cert = new EvidenceCert();
cert.setCertBase64(racertinfo.getCertSignBuf());
cert.setCreateTime(new Date());
cert.setCertSerialnumber(racertinfo.getCertSerialNumber());
cert.setIssuerdn(racertinfo.getCertIssuerDn());
cert.setSubjectdn(racertinfo.getCertSubjectDn());
cert.setCreateTime(new Date());
try {
configuration.setStartTime(sdf.parse(racertinfo.getCertNotBefore()));
configuration.setEndTime(sdf.parse(racertinfo.getCertNotAfter()));
cert.setStartTime(sdf.parse(racertinfo.getCertNotBefore()));
cert.setEndTime(sdf.parse(racertinfo.getCertNotAfter()));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sqlSession.insert("com.itrus.portal.db.EvidenceCertMapper.insert", cert);
configuration.setCert(cert.getId().toString());
// configuration.setCert(racertinfo.getCertSignBuf());
configuration.setCertp7(racertinfo.getCertSignBufP7());
configuration.setCertSerialnumber(racertinfo.getCertSerialNumber());
/*try {
configuration.setStartTime(sdf.parse(racertinfo.getCertNotBefore()));
configuration.setEndTime(sdf.parse(racertinfo.getCertNotAfter()));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
boolean is = certificateService.setCertitifate(secret.getAlias(), racertinfo.getCertSignBuf(), racertinfo.getCertSignBufP7());
if (is) {
if ("0".equals(configuration.getArithmetic())) {
configuration.setArithmetic(null);
}
if (StringUtils.isNotEmpty(configuration.getSubject())) {
configuration.setSubject(configuration.getSubject());
}
String s = String.valueOf(secret.getId());
int keyid = Integer.parseInt(s);
configuration.setEvidenceSecretKey(keyid);
configuration.setCreateTime(new Date());
configuration.setCreator(getAdmin().getName());
certificateService.insert(configuration);
String oper = "证书产生成功";
String info = "证书名称:" + configuration.getCertificateName();
LogUtil.evidencelog(sqlSession, null, oper, info);
EvidenceCertificateExample certE = new EvidenceCertificateExample();
EvidenceCertificateExample.Criteria tificate = certE.createCriteria();
tificate.andEvidenceSecretKeyEqualTo(keyid);
configuration = sqlSession.selectOne("com.itrus.portal.db.EvidenceCertificateMapper.selectByExample", certE);
}
}
} else {
uiModel.addAttribute("error", "csr产生失败");
return "certificate/create";
}
}
return "redirect:/certificate/" + configuration.getId() + "/" + 1;
// return "redirect:/certificate/show/"+configuration.getId()+"/"+1;
// return "redirect:/certificate";
}
use of com.itrus.portal.db.RaAccount in project portal by ixinportal.
the class CertificateController method show.
/**
* 跳转方法,查看详情和配置签章
*
* @param id
* @param type
* 区分跳转的页面
* @param uiModel
* @return
*/
@RequestMapping(value = "/{id}/{type}", produces = "text/html")
public String show(@PathVariable("id") Long id, @PathVariable("type") int type, Model uiModel) {
EvidenceCertificate configuration = certificateService.selectById(id);
if (configuration != null && configuration.getRaAccount() != null) {
RaAccount ra = raAccount.getRaAccount(Long.valueOf(configuration.getRaAccount()));
List<RaAccount> ras = sqlSession.selectList("com.itrus.portal.db.RaAccountMapper.selectByExample");
EvidenceSecretKey secretkey = sqlSession.selectOne("com.itrus.portal.db.EvidenceSecretKeyMapper.selectByPrimaryKey", configuration.getEvidenceSecretKey());
uiModel.addAttribute("ras", ras);
uiModel.addAttribute("ra", ra);
uiModel.addAttribute("secretkey", secretkey);
uiModel.addAttribute("error", error);
error = null;
}
uiModel.addAttribute("configuration", configuration);
if (type == 1) {
return "certificate/show";
} else if (type == 2) {
return "certificate/configure";
} else {
return "certificate/update";
}
}
Aggregations