Search in sources :

Example 6 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class RenewUserCertWebController method updateCert.

@RequestMapping(value = "/updateCert", method = RequestMethod.POST)
// TODO 更新证书
@ResponseBody
public Map<String, Object> updateCert(// 证书序列号
@RequestParam(value = "certSn", required = true) String certSn, // 旧的证书的请求,目前随便写:45564
@RequestParam(value = "csr", required = true) String csr, // 证书base64
@RequestParam(value = "crt", required = true) String crt, // 原证书所在容器生成的新的证书请求
@RequestParam(value = "newCSR", required = true) String newCSR, // 老证书对csr签名后的base64字符串
@RequestParam(value = "pkcs7", required = true) String pkcs7, // 订单id
@RequestParam(value = "billid", required = true) Long billId, // 证书所属的keysn,没有key则为""
@RequestParam(value = "keySn", required = false) String keySn, @RequestParam(value = "oldCertDn", required = false) String oldCertDn, Model uimModel, HttpSession session) {
    // TODO,参数有效性验证
    Map<String, Object> ret = new HashMap<String, Object>();
    ret.put("status", 1);
    UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
    Enterprise webenterprise = (Enterprise) session.getAttribute("webenterprise");
    if (null == webuserInfo || null == webenterprise) {
        // 2标识登录已经失效,需跳转到登录页面
        ret.put("retCode", 2);
        ret.put("retMsg", "登录状态失效");
        return ret;
    }
    Bill bill = billService.getBill(billId);
    if (null == bill) {
        ret.put("retMsg", "该订单不存在");
        return ret;
    }
    // 订单是否为当前用户当前企业
    if (!webuserInfo.getId().equals(bill.getUniqueId()) || !webenterprise.getId().equals(bill.getEnterprise())) {
        ret.put("retMsg", "您不能操作该订单");
        return ret;
    }
    // 判断是否是更新过了的订单,是的话直接从本地数据库获取证书的base64传递给页面
    if ((bill.getBillStatus() == ComNames.BILL_STATUS_8 || bill.getBillStatus() == ComNames.BILL_STATUS_7 || bill.getBillStatus() == ComNames.BILL_STATUS_6) && null != bill.getOldUserCert()) {
        // 根据订单号,找到订单更新后的证书信息
        CertBuf certBuf = sqlSession.selectOne("com.itrus.portal.db.CertBufMapper.selectNewCertBufByBillId", billId);
        // 证书更新信息发给浏览器,写入证书
        // 用户证书,Base64编码 (公钥证书),因为记录的时候,存的都是公钥证书,所以这个证书链也是个单证书而已
        ret.put("certChain", certBuf.getCertBuf());
        // 用户证书,Base64编码 (公钥证书)
        ret.put("certBase64", certBuf.getCertBuf());
        // 用户证书,Base64编码 (公钥证书)
        ret.put("certSignBuf", certBuf.getCertsignBuf());
        // KMC协议响应1
        ret.put("certKmcRep1", certBuf.getCertKmcRep1());
        // KMC协议响应2
        ret.put("certKmcRep2", certBuf.getCertKmcRep2());
        // //加密证书
        // 用户加密证书
        ret.put("encUserCert", certBuf.getEncUserCert());
        ret.put("status", 0);
        List<UserCert> userCert2 = userCertService.getUserCertByBill(bill.getId(), null);
        ret.put("certId", userCert2.get(0).getId());
        return ret;
    }
    String accountHash = "";
    // 根据订单ID从本地查找ra哈希值
    accountHash = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectRaHashByBillId", billId);
    if (!StringUtils.isNotBlank(accountHash)) {
        // 根据证书序列号查找RA哈希值
        try {
            accountHash = getRaInfo.getRaInfoByCertSerialNumber(certSn);
        } catch (UserInfoServiceException e) {
            ret.put("message", e.getMessage());
            return ret;
        }
    }
    // 查找raAccount
    RaAccountExample rae = new RaAccountExample();
    RaAccountExample.Criteria criteria = rae.or();
    criteria.andAccountHashEqualTo(accountHash);
    rae.setLimit(1);
    RaAccount raAccount = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectByExample", rae);
    CertUtlis certUtlis = new CertUtlis();
    CertInfo certInfo = new CertInfo();
    UserCert oldUsercert = null;
    try {
        if (!bill.getBillStatus().equals(ComNames.BILL_STATUS_12)) {
            ret.put("message", "该订单下的证书未处于可更新状态");
            ret.put("status", 1007);
            return ret;
        }
        // 解密ra密码
        if (null != raAccount.getAaPassword()) {
            raAccount.setAaPassword(AESencrp.decrypt(raAccount.getAaPassword(), dbEncKey));
        }
        // 判断证书是否过期并且处于90天内的有效期
        oldUsercert = userCertService.getUserCertByCertSn(certSn);
        Date certEndTime = oldUsercert.getCertEndTime();
        logger.error("************过期时间********certEndTime" + certEndTime);
        int result = compareDate(certEndTime, new Date());
        logger.error("************过期状态********result" + result);
        // 用户证书剩余的天数
        Integer surplusDay = 0;
        surplusDay = differenceDate(certEndTime, new Date());
        Integer certValidity = null;
        // 判断订单中是否配了产品规格且有期限
        if (null != bill.getProductSpec() && 0 != bill.getProductSpec()) {
            ProductSpec productSpec = productSpecService.getProductSpec(bill.getProductSpec());
            Integer day = Integer.parseInt(productSpec.getProductValid());
            certValidity = 365 * day + 1 + (day / 4);
        }
        logger.error("产品规格期限************certValidity" + certValidity);
        if (result == 2) {
            logger.error("************证书过期更新********result=" + result);
            // 证书已经过期了,直接进行新证书申请
            if (null != certValidity) {
                logger.error("****给走申请证书接口的用户补充上剩余天数****certValidity=" + certValidity);
                // 给走申请证书接口的用户补充上剩余天数,因为用户指定的更新期限,可能跟原证书的年限不一致
                certValidity = certValidity + surplusDay;
                certInfo = renewUserService.applyCert(newCSR, productService.getProductById(bill.getProduct()), oldCertDn, certValidity);
            } else {
                logger.error("****证书更新方法****certSn=" + certSn);
                certInfo = certUtlis.renewAA(certSn, crt, raAccount.getAaPassword(), accountHash, raAccount.getAaPassword(), "", newCSR, pkcs7, raAccount);
            }
        // certInfo = renewUserService.applyCert(newCSR,
        // productService.getProductById(bill.getProduct()),
        // oldCertDn, certValidity);
        } else if (result == 3) {
            // 当证书过期,且超过90天
            ret.put("status", 1008);
            ret.put("message", "该证书已经过期超过了90天,无法更新");
            return ret;
        } else if (result == 1) {
            logger.error("****证书更新方法2****result=" + result);
            if (null != certValidity) {
                // 给走申请证书接口的用户补充上剩余天数,因为用户指定的更新期限,可能跟原证书的年限不一致
                certValidity = certValidity + surplusDay;
                certInfo = renewUserService.applyCert(newCSR, productService.getProductById(bill.getProduct()), oldCertDn, certValidity);
            } else {
                // 判断是否为passcord模式
                CaPasscode passcode = new CaPasscode();
                if (raAccount.getCertSignType() == 2) {
                    // 获取对应ra账号的passcode
                    RaAccountInfoExample raInfoExample = new RaAccountInfoExample();
                    RaAccountInfoExample.Criteria raInfoCriteria = raInfoExample.createCriteria();
                    raInfoCriteria.andHashValEqualTo(raAccount.getAccountHash());
                    raInfoExample.setOrderByClause("create_time desc");
                    raInfoExample.setLimit(1);
                    RaAccountInfo raAccountInfo = sqlSession.selectOne("com.itrus.portal.db.RaAccountInfoMapper.selectByExample", raInfoExample);
                    if (raAccountInfo == null) {
                        LogUtil.syslog(sqlSession, "制作证书", "不存在指定RA帐号");
                    }
                    // 获取对应passcode
                    try {
                        passcode = codeService.IssuedCode4Cert(raAccountInfo);
                        if (passcode == null) {
                            LogUtil.syslog(sqlSession, "制作证书", "没有有效授权码,请联系管理员");
                        }
                    } catch (TerminalServiceException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    // 进行证书更新,直接在原证书的基础上,签发一张新证书,需要有
                    certInfo = certUtlis.renewAA(certSn, crt, raAccount.getAaPassword(), accountHash, raAccount.getAaPassword(), passcode.getPasscode(), newCSR, pkcs7, raAccount);
                } else {
                    // 进行证书更新,直接在原证书的基础上,签发一张新证书,需要有
                    certInfo = certUtlis.renewAA(certSn, crt, raAccount.getAaPassword(), accountHash, raAccount.getAaPassword(), "", newCSR, pkcs7, raAccount);
                }
            }
        }
        UserCert userCert = updateUserCertAndCertBuf(certSn, certInfo, billId, raAccount.getId());
        UserLog userLog = new UserLog();
        userLog.setType("更新证书成功");
        userLog.setInfo("成功更新证书:" + certSn);
        userLog.setHostId("未知");
        userLog.setProject(bill.getProject());
        LogUtil.userlog(sqlSession, userLog);
        // 证书更新信息发给浏览器,写入证书
        // 用户证书PKCS7格式(含证书链)
        ret.put("certChain", certInfo.getCertSignBufP7());
        // 用户证书,Base64编码 (公钥证书)
        ret.put("certBase64", certInfo.getCertSignBuf());
        ret.put("certId", userCert.getId());
        // 用户证书,Base64编码 (公钥证书)
        ret.put("certSignBuf", certInfo.getCertSignBuf());
        // KMC协议响应1
        ret.put("certKmcRep1", certInfo.getCertKmcRep1());
        // KMC协议响应2
        ret.put("certKmcRep2", certInfo.getCertKmcRep2());
        // 加密证书
        // 用户加密证书
        ret.put("encUserCert", certInfo.getCertSignBufKmc());
        ret.put("status", 0);
        // 更新usercert和cerbuf
        return ret;
    } catch (MalformedURLException | RaServiceUnavailable_Exception e) {
        logger.error("更新证书:" + certSn + "出现异常,异常信息:" + e.getMessage());
        UserLog userLog = new UserLog();
        userLog.setType("更新证书失败");
        userLog.setInfo("url:updateCert,出错的证书:" + certSn + ",详细错误:" + e.getMessage());
        userLog.setHostId("未知");
        userLog.setProject(bill.getProject());
        LogUtil.userlog(sqlSession, userLog);
        ret.put("status", 1004);
        ret.put("message", "出现未知异常,请联系管理员处理");
        return ret;
    } catch (EncDecException e) {
        // TODO Auto-generated catch block
        logger.error("更新证书:" + certSn + "出现异常,异常信息:" + e.getMessage());
        UserLog userLog = new UserLog();
        userLog.setType("更新证书失败");
        userLog.setInfo("url:updateCert,出错的证书:" + certSn + ",详细错误:" + e.getMessage());
        userLog.setHostId("未知");
        userLog.setProject(bill.getProject());
        LogUtil.userlog(sqlSession, userLog);
        ret.put("status", 1005);
        ret.put("message", "出现未知异常,请联系管理员处理");
        return ret;
    } catch (Exception e) {
        if (StringUtils.isNotBlank(certInfo.getCertSerialNumber())) {
            // 新证书已签发,但未保存到数据库时 需打印新证书序列号
            logger.error("旧证书序列号:" + oldUsercert.getCertSn() + ",异常的新证书序列号:" + certInfo.getCertSerialNumber());
        }
        logger.error("更新证书:" + certSn + "出现异常,异常信息:" + e.getMessage());
        UserLog userLog = new UserLog();
        userLog.setType("更新证书失败");
        userLog.setInfo("url:updateCert,出错的证书:" + certSn + ",详细错误:" + e.getMessage());
        userLog.setHostId("未知");
        userLog.setProject(bill.getProject());
        LogUtil.userlog(sqlSession, userLog);
        ret.put("status", 1006);
        ret.put("message", "出现未知异常,请联系管理员处理");
        return ret;
    }
}
Also used : CertInfo(cn.topca.tca.ra.service.CertInfo) TerminalServiceException(com.itrus.portal.exception.TerminalServiceException) MalformedURLException(java.net.MalformedURLException) RaServiceUnavailable_Exception(cn.topca.tca.ra.service.RaServiceUnavailable_Exception) HashMap(java.util.HashMap) EncDecException(com.itrus.portal.exception.EncDecException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Date(java.util.Date) MalformedURLException(java.net.MalformedURLException) TerminalServiceException(com.itrus.portal.exception.TerminalServiceException) CertificateException(java.security.cert.CertificateException) RaServiceUnavailable_Exception(cn.topca.tca.ra.service.RaServiceUnavailable_Exception) SigningServerException(com.itrus.cryptorole.SigningServerException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) EncDecException(com.itrus.portal.exception.EncDecException)

Example 7 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class UserInfoWebController method updateAccountInfo.

/**
 * 处理修改账户信息
 *
 * @param userInfo
 * @param request
 * @return
 */
@RequestMapping("/updateAccountInfo")
@ResponseBody
public Map<String, Object> updateAccountInfo(@ModelAttribute("userInfo") UserInfo userInfo, HttpServletRequest request) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    // 0标识失败,1标识成功
    retMap.put("retCode", 0);
    HttpSession session = request.getSession();
    Boolean verifyCodeStatus = (Boolean) session.getAttribute("webverifyCodeStatus");
    UserInfo currentUserInfo = (UserInfo) session.getAttribute("webuserInfo");
    if (null == verifyCodeStatus || !verifyCodeStatus || null == currentUserInfo) {
        // 登录状态失效,跳转到登录页面
        // 2表示登录失效
        retMap.put("retCode", 2);
        retMap.put("retMsg", "登录已经失效,请重新登录");
        return retMap;
    }
    userInfo.setId(currentUserInfo.getId());
    try {
        userInfo = userInfoService.updateUserInfo(userInfo);
        session.setAttribute("webuserInfo", userInfo);
        retMap.put("retCode", 1);
        // 记录日志
        UserLog userlog = new UserLog();
        userlog.setProject(userInfo.getProject());
        userlog.setType("修改帐号信息");
        userlog.setInfo(userInfo.getmPhone() + "修改成功");
        userlog.setHostId("未知");
        userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
        LogUtil.userlog(sqlSession, userlog);
    } catch (UserInfoServiceException e) {
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (Exception e) {
        UserLog userlog = new UserLog();
        userlog.setProject(userInfo.getProject());
        userlog.setType("修改账户信息");
        userlog.setInfo("url:updateAccountInfo,详细错误:" + e.getMessage());
        userlog.setHostId("未知");
        userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
        LogUtil.userlog(sqlSession, userlog);
        retMap.put("retMsg", "服务端出现未知错误,请联系管理员");
        return retMap;
    }
    return retMap;
}
Also used : HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) ParseException(java.text.ParseException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) BiffException(jxl.read.biff.BiffException) TerminalServiceException(com.itrus.portal.exception.TerminalServiceException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SigningServerException(com.itrus.cryptorole.SigningServerException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class FilePathUtils method saveImg.

/**
 * 保存图片信息
 *
 * @param imgDir
 * @param file
 * @param fileBase64
 * @param fileType
 * @param itemType
 * @return
 * @throws IOException
 * @throws UserInfoServiceException
 * @throws ServiceNullException
 */
public File saveImg(File imgDir, MultipartFile file, String fileBase64, String fileType, String itemType, Project project) throws IOException, UserInfoServiceException, ServiceNullException {
    String filename = System.currentTimeMillis() + itemType + getRandom() + fileType;
    // 判断项目是否需要1M的授权书
    Long projectId = systemConfigService.getMaxImageProject();
    boolean flag = false;
    flag = project.getId().equals(projectId);
    // 创建磁盘文件
    File imgFile = new File(imgDir, filename);
    if (file != null && !file.isEmpty())
        file.transferTo(imgFile);
    else if (StringUtils.isNotBlank(fileBase64) && StringUtils.isNotBlank(fileType)) {
        imageByBase64.saveImage(fileBase64, imgFile);
        if (flag) {
            if (imgFile.length() > IMG_MAX_SIZE_NEW) {
                throw new UserInfoServiceException("图片大小不能超过" + (IMG_MAX_SIZE_NEW / 1024) + "K");
            }
        } else {
            if (imgFile.length() > IMG_MAX_SIZE) {
                throw new UserInfoServiceException("图片大小不能超过" + (IMG_MAX_SIZE / 1024) + "K");
            }
        }
    } else
        return null;
    return imgFile;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) File(java.io.File) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException)

Example 9 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class FilePathUtils method saveImgByRealAuth.

/**
 * 实名认证保存图片信息
 *
 * @param imgDir
 * @param file
 * @param fileBase64
 * @param fileType
 * @param itemType
 * @return
 * @throws IOException
 * @throws UserInfoServiceException
 * @throws ServiceNullException
 */
public File saveImgByRealAuth(File imgDir, MultipartFile file, String fileBase64, String fileType, String itemType) throws IOException, UserInfoServiceException, ServiceNullException {
    String filename = System.currentTimeMillis() + itemType + getRandom() + fileType;
    // 创建磁盘文件
    File imgFile = new File(imgDir, filename);
    if (file != null && !file.isEmpty())
        file.transferTo(imgFile);
    else if (StringUtils.isNotBlank(fileBase64) && StringUtils.isNotBlank(fileType)) {
        imageByBase64.saveImage(fileBase64, imgFile);
        if (imgFile.length() > IMG_MAX_SIZE_NEW) {
            throw new UserInfoServiceException("图片大小不能超过" + (IMG_MAX_SIZE_NEW / 1024) + "K");
        }
    } else
        return null;
    return imgFile;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) File(java.io.File) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException)

Example 10 with UserInfoServiceException

use of com.itrus.portal.exception.UserInfoServiceException in project portal by ixinportal.

the class EnterpriseValidator method validator.

/**
 *  企业信息插入的时候,进行校验(条件:企业SN在数据库中有唯一索引,肯定是唯一值)
 *	 	1).根据企业名称和企业唯一标识,分别从数据库中查询。
 *		1.若两个都不存在,则通过,直接插入
 *		2.若两个都存在,且主键id相同,则通过
 *		3.若其中一个存在,另外一个不存在或者ID不相同,则抛出异常信息,提示xxxxx
 * @param enterprise
 * @return
 * @throws UserInfoServiceException
 */
public boolean validator(Enterprise enterprise) throws UserInfoServiceException {
    if (null == enterprise || StringUtils.isBlank(enterprise.getEnterpriseName()) || StringUtils.isBlank(enterprise.getEnterpriseSn())) {
        throw new UserInfoServiceException("企业信息不完整,请仔细检查");
    }
    Enterprise byName = enterpriseService.getEntByName(enterprise.getEnterpriseName());
    Enterprise ByEntSn = enterpriseService.getEntByEnterpriseSn(enterprise.getEnterpriseSn());
    if (validatorResult(enterprise, byName, ByEntSn)) {
        return true;
    } else {
        throw new UserInfoServiceException("当前证书信息已变更,请使用新证书或已注册的手机号登录");
    }
}
Also used : Enterprise(com.itrus.portal.db.Enterprise) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException)

Aggregations

UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)73 Date (java.util.Date)39 HashMap (java.util.HashMap)31 File (java.io.File)26 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)22 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 Enterprise (com.itrus.portal.db.Enterprise)19 IOException (java.io.IOException)19 UserInfo (com.itrus.portal.db.UserInfo)17 TransactionStatus (org.springframework.transaction.TransactionStatus)14 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)14 SigningServerException (com.itrus.cryptorole.SigningServerException)11 IdentityCard (com.itrus.portal.db.IdentityCard)11 CertificateException (java.security.cert.CertificateException)11 BusinessLicense (com.itrus.portal.db.BusinessLicense)10 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)10 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)10 Agent (com.itrus.portal.db.Agent)9 OrgCode (com.itrus.portal.db.OrgCode)9 TaxRegisterCert (com.itrus.portal.db.TaxRegisterCert)9