use of com.itrus.portal.db.UserCertExample in project portal by ixinportal.
the class RenewUserCertClientController method toPages.
/**
* 跳转到更新成功页面或是更新失败页面 certs为新证书,若不为空则更新成功,若为空则更新失败 szy 2016年9月7日 上午9:49:15
*
* @param id
* 订单编号
*/
@RequestMapping(value = "/toPages/{id}", produces = "text/html")
public String toPages(@PathVariable("id") Long id, @RequestParam(value = "ret", required = false) int ret, HttpServletRequest request, Model uiModel) {
HttpSession session = request.getSession();
UserInfo userInfo = (UserInfo) session.getAttribute(ComNames.WEB_USER_INFO);
Enterprise enterprise = (Enterprise) session.getAttribute(ComNames.WEB_ENTERPRISE);
if (null == userInfo || null == enterprise) {
return ComNames.DENG_LU_CLIENT;
}
Map<String, Object> param = new HashMap<String, Object>();
// 设置查询条件,选择属于当前用户,当前企业的订单
param.put("id", id);
List<Map<String, Object>> billAll = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectProductBillCertById", param);
if (0 == billAll.size()) {
uiModel.addAttribute("errorMsg", "更新订单不存在");
return ComNames.CLIENTFW_ERRORPAGE;
}
// 审核记录
ReviewLog reviewLog = reviewLogService.getReviewLog(id);
if (reviewLog != null) {
uiModel.addAttribute("reviewLog", reviewLog);
}
uiModel.addAttribute("bills", billAll.get(0));
if (billAll.get(0).get("on_pay_info") != null) {
Map<Long, OnPayInfo> opiMap = sqlSession.selectMap("com.itrus.portal.db.OnPayInfoMapper.selectByExample", "id");
uiModel.addAttribute("opiMap", opiMap);
}
PayInfoExample payInfoex = new PayInfoExample();
Map<Long, PayInfo> payinfoMap = sqlSession.selectMap("com.itrus.portal.db.PayInfoMapper.selectByExample", payInfoex, "id");
uiModel.addAttribute("payinfomap", payinfoMap);
UserCertExample uce = new UserCertExample();
UserCertExample.Criteria ucec = uce.or();
ucec.andBillEqualTo(id);
List<UserCert> certs = sqlSession.selectList("com.itrus.portal.db.UserCertMapper.selectByExample", uce);
if (ret == 1) {
// 更新成功页面
UserCert userCert = certs.get(0);
uiModel.addAttribute("doneTime", userCert.getCertStartTime());
try {
// 将客户端更新后的证书绑定给当前用户
userCert.setUserinfo(userInfo.getId());
userCertService.updateByPrimaryKeySelective(userCert);
} catch (Exception e) {
// TODO: handle exception
}
// 刷新session中的当前证书
session.setAttribute(ComNames.WEB_USER_CERT_SN, userCert.getCertSn());
return "clientFW/dingdanxiangqing_gengxinchenggong";
} else {
// 更新失败页面
return "clientFW/dingdanxiangqing_gengxinshibai";
}
}
use of com.itrus.portal.db.UserCertExample in project portal by ixinportal.
the class MakeCertController method makeSealBaiRun.
/**
* 百润制章
*
* @param billId
* 订单id
* @param csr
* 证书base64编码
* @param request
* @param response
* @return
* @throws EncDecException
* @throws Exception
*/
@RequestMapping(value = "/makeSealBaiRun", method = RequestMethod.POST)
public void makeSealBaiRun(@RequestParam(value = "billId", required = true) Long billId, @RequestParam(value = "sealpic", required = true) String sealpic, @RequestParam(value = "csr", required = true) String csr, @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; }
*/
Map<String, Object> param = new HashMap<>();
param.put("id", bill.getId());
UserCertExample userc = new UserCertExample();
UserCertExample.Criteria us = userc.createCriteria();
us.andIdNotEqualTo(bill.getId());
userc.setOrderByClause("cert_start_time desc");
userc.setLimit(1);
UserCert usercert = sqlSession.selectOne("com.itrus.portal.db.UserCertMapper.selectByExample", userc);
CertBufExample certbuf = new CertBufExample();
CertBufExample.Criteria cert = certbuf.createCriteria();
cert.andIdEqualTo(usercert.getCertBuf());
CertBuf organ = sqlSession.selectOne("com.itrus.portal.db.CertBufMapper.selectByExample", certbuf);
if (makeSealConfigs.get(1).getName().contains(makeSealServer.getFirm())) {
MakeSealConfig makeSealConfig = makeSealConfigs.get(0);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
try {
log.error("request.getLocalAddr : " + request.getLocalAddr() + ",CSR:" + organ.getCertBuf());
boolean userbool = true;
if (usercert.getIsRegister() == null || !usercert.getIsRegister().equals(1)) {
usercert.setIsRegister(1);
sqlSession.update("com.itrus.portal.db.UserCertMapper.updateByPrimaryKeySelective", usercert);
// 注册用户
userbool = UserSDK.addUser(null, makeSealConfig.getAddressKey(), organ.getCertBuf(), makeSealServer.getAccount(), Constant.APP, Constant.Token);
log.error("makeCertController userbool : " + userbool);
// log.info(makeSealConfig.getAddressKey());
// log.info(String.valueOf(userbool));
}
// 制作印章
Map<String, Object> result = SealSDK.makeSeal(makeSealServer.getSealName(), organ.getCertBuf(), sealpic, "公章", Constant.APP, Constant.Token);
if (userbool && (Boolean) result.get("state")) {
// 制章完成后的印章数据,返回到前台用作导章
log.error("SealSDK : context");
} else {
log.error("SealSDK : ");
// map.put("retMsg", "制章异常");
}
response.setCharacterEncoding("GBK");
response.setContentType("text/html");
OutputStream out = response.getOutputStream();
out.write(result.get("data").toString().getBytes("GBK"));
// map.put("bairun_ret",
// result.get("data").toString().getBytes("GBK"));
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
// map.put("retMsg", e.getMessage());
}
} else {
MakeSealConfig makeSealConfig = makeSealConfigs.get(1);
// 替换-印章名称
if (StringUtils.isNotBlank(makeSealServer.getSealName())) {
UIDInfoUtils uidutils = new UIDInfoUtils();
uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
makeSealServer.setSealName(uidutils.getUidInfo(billId, makeSealServer.getSealName()));
}
try {
log.error("request.getLocalAddr : " + request.getLocalAddr() + ",CSR:" + organ.getCertBuf());
boolean userbool = true;
if (usercert.getIsRegister() != null && !usercert.getIsRegister().equals(1)) {
usercert.setIsRegister(1);
sqlSession.update("com.itrus.portal.db.UserCertMapper.updateByPrimaryKeySelective", usercert);
// 注册用户
userbool = UserSDK.addUser(null, makeSealConfig.getAddressKey(), organ.getCertBuf(), Constant.TianWeiChenXin, Constant.APP, Constant.Token);
}
// 制作印章
Map<String, Object> result = SealSDK.makeSeal(makeSealServer.getSealName(), organ.getCertBuf(), sealpic, "公章", Constant.APP, Constant.Token);
String s = Constant.IP;
if (userbool && (Boolean) result.get("state")) {
// 制章完成后的印章数据,返回到前台用作导章
log.error("SealSDK : " + result.get("data").toString());
} else {
log.error("SealSDK : ");
// map.put("retMsg", "制章异常");
}
response.setCharacterEncoding("GBK");
response.setContentType("text/html");
OutputStream out = response.getOutputStream();
out.write(result.get("data").toString().getBytes("GBK"));
// map.put("bairun_ret",
// result.get("data").toString().getBytes("GBK"));
out.flush();
out.close();
System.out.println(result.get("data").toString().getBytes("GBK").toString() + ":JS");
} catch (Exception e) {
e.printStackTrace();
// map.put("retMsg", e.getMessage());
}
}
// map.put("retCode", 1);
// return map;
}
use of com.itrus.portal.db.UserCertExample in project portal by ixinportal.
the class UserCertService method isBindCert.
/**
* 判断证书是否已经关联了用户 <br>
* false表示未关联用户<br>
* true标识关联了用户
*
* @param userInfoId
* @param certBase64
* @return
* @throws CertificateException
* @throws SigningServerException
*/
public boolean isBindCert(Long userInfoId, String certBase64) throws CertificateException, SigningServerException {
X509Certificate cert = X509Certificate.getInstance(certBase64);
// trustService.verifyCertificate(cert);
String certSn = CertUtilsOfUkey.getValidSerialNumber(cert.getHexSerialNumber());
// 判断是否和证书绑定
UserCertExample example = new UserCertExample();
UserCertExample.Criteria criteria = example.or();
criteria.andCertSnEqualTo(certSn);
criteria.andUserinfoEqualTo(userInfoId);
example.setLimit(1);
UserCert userCert = sqlSession.selectOne("com.itrus.portal.db.UserCertMapper.selectByExample", example);
if (null == userCert) {
return false;
}
return true;
}
use of com.itrus.portal.db.UserCertExample in project portal by ixinportal.
the class UserCertService method getUserCert.
public synchronized UserCert getUserCert(X509Certificate cert) throws CertificateException, SigningServerException {
// trustService.verifyCertificate(cert); //检查证书状态
// 检查证书信息是否在数据库中
String certHexSN = CertUtilsOfUkey.getValidSerialNumber(cert.getHexSerialNumber());
String issuerDN = cert.getIssuerDNString();
UserCertExample ucExample = new UserCertExample();
UserCertExample.Criteria ucCriteria = ucExample.or();
// ucCriteria.andIssuerDnEqualTo(issuerDN);
ucCriteria.andCertSnEqualTo(certHexSN);
UserCert userCert = sqlSession.selectOne("com.itrus.portal.db.UserCertMapper.selectByExample", ucExample);
if (userCert == null) {
// 若不存在证书则添加证书信息
CertBuf certBuf = new CertBuf();
certBuf.setCreateTime(new Date());
certBuf.setCertBuf(Base64.encode(cert.getEncoded()).replaceAll("\n", ""));
// 将公钥证书存入数据库
sqlSession.insert("com.itrus.portal.db.CertBufMapper.insert", certBuf);
userCert = new UserCert();
userCert.setCertDn(cert.getSubjectDNString());
userCert.setIssuerDn(issuerDN);
userCert.setCertSn(certHexSN);
userCert.setCertStartTime(cert.getNotBefore());
userCert.setCertEndTime(cert.getNotAfter());
// 证书验证不通过,则直接抛出异常,不会进行到此处
userCert.setCertStatus(ComNames.CERT_STATUS_1);
userCert.setSha1Fingerprint(CipherUtils.sha1(cert.getEncoded()));
userCert.setCertBuf(certBuf.getId());
// 0标识非门户申请的证书(因为非门户下载的证书才会不存在我们数据库中)
userCert.setCertSource(ComNames.CERT_SOURCE_0);
sqlSession.insert("com.itrus.portal.db.UserCertMapper.insertSelective", userCert);
}
return userCert;
}
use of com.itrus.portal.db.UserCertExample in project portal by ixinportal.
the class UserCertService method getUserCertByCertSn.
public UserCert getUserCertByCertSn(String certSn) {
UserCertExample ucExample = new UserCertExample();
UserCertExample.Criteria ucCriteria = ucExample.or();
ucCriteria.andCertSnEqualTo(certSn);
UserCert userCert = sqlSession.selectOne("com.itrus.portal.db.UserCertMapper.selectByExample", ucExample);
return userCert;
}
Aggregations