Search in sources :

Example 26 with UserCert

use of com.itrus.portal.db.UserCert in project portal by ixinportal.

the class DownLoadCertServiceImpl method savePfxCertInfo.

public void savePfxCertInfo(CertInfo racertinfo, Bill bill, Long raId, Integer uidIdx, String keySn, String autoidType, Integer autoidValue, String pfxCert) throws ParseException {
    CertBuf certbuf = new CertBuf();
    Date date = new Date();
    certbuf.setCreateTime(date);
    certbuf.setCertBuf(racertinfo.getCertSignBuf());
    certbuf.setCertKmcRep1(racertinfo.getCertKmcRep1());
    certbuf.setCertKmcRep2(racertinfo.getCertKmcRep2());
    certbuf.setCertsignBuf(racertinfo.getCertSignBuf());
    certbuf.setEncUserCert(racertinfo.getCertSignBufKmc());
    certbuf.setPfxCert(pfxCert);
    certbuf.setLastDownloadTime(date);
    certbuf.setCertDownloadNumber(1);
    sqlSession.insert("com.itrus.portal.db.CertBufMapper.insert", certbuf);
    UserCert usercert = new UserCert();
    usercert.setBill(bill.getId());
    usercert.setRaAccount(raId);
    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");
    if (StringUtils.isNotBlank(keySn))
        // 设置证书keySn
        usercert.setKeySn(keySn);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
    usercert.setCertStartTime(sdf.parse(racertinfo.getCertNotBefore()));
    usercert.setCertEndTime(sdf.parse(racertinfo.getCertNotAfter()));
    usercert.setSha1Fingerprint("setSha1Fingerprint");
    // autoid 数据
    if (!autoidType.equals("")) {
        usercert.setAutoidType(autoidType);
        usercert.setAutoidValue(autoidValue);
    }
    usercert.setEnterprise(bill.getEnterprise());
    sqlSession.insert("com.itrus.portal.db.UserCertMapper.insert", usercert);
    // 将设置订单状态
    bill.setBillStatus(ComNames.BILL_STATUS_6);
    if (null == bill.getDelivery()) {
        bill.setBillStatus(ComNames.BILL_STATUS_8);
    } else if (null != bill.getIsInvoiced() && bill.getIsInvoiced().equals(1)) {
        bill.setBillStatus(ComNames.BILL_STATUS_7);
    }
    // 当订单价格是0的时候,又不需要开票,设置为已开票代配送
    if (0 == bill.getBillSum() && null == bill.getInvoice() && null == bill.geteInvoice()) {
        bill.setBillStatus(ComNames.BILL_STATUS_7);
        if (null == bill.getDelivery()) {
            bill.setBillStatus(ComNames.BILL_STATUS_8);
        }
    }
    sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
}
Also used : CertBuf(com.itrus.portal.db.CertBuf) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) UserCert(com.itrus.portal.db.UserCert)

Example 27 with UserCert

use of com.itrus.portal.db.UserCert in project portal by ixinportal.

the class ActivityCollectService method isNeedUpdateCertInfo.

/**
 * 判断是否需要更新用户所需证书信息
 *
 * @param uid
 * @param endTime
 * @return 当且仅当存在用户信息,并且主证书时间小于UKEY当前证书时间时,返回true
 */
private boolean isNeedUpdateCertInfo(String uid, long endTime) {
    boolean ret = false;
    if (StringUtils.isBlank(uid) || endTime <= 0)
        return ret;
    UdcDomainExample udcdExample = new UdcDomainExample();
    UdcDomainExample.Criteria udcdCriteria = udcdExample.or();
    udcdCriteria.andCertEqualToUdcUserCert();
    udcdCriteria.andUserEqualToUdcUser();
    udcdCriteria.andUserUniqueEqualTo(uid);
    udcdCriteria.andIsMasterEqualTo(true);
    udcdCriteria.andIsRevokedEqualTo(false);
    UserCert userCert = sqlSession.selectOne("com.itrus.ukey.sql.UdcDomainMapper.selectCertByExample", udcdExample);
    if (userCert != null && userCert.getCertEndTime().getTime() < endTime)
        ret = true;
    return ret;
}
Also used : UdcDomainExample(com.itrus.portal.sql.UdcDomainExample) UserCert(com.itrus.portal.db.UserCert)

Example 28 with UserCert

use of com.itrus.portal.db.UserCert in project portal by ixinportal.

the class BindCertWebController method bindPage.

@RequestMapping("/bindCertPage")
public String bindPage(@RequestParam(value = "certSn", required = true) String certSn, HttpSession session, Model uiModel) throws UserInfoServiceException {
    // 是否登录
    UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
    Enterprise webenterprise = (Enterprise) session.getAttribute("webenterprise");
    if (null == webuserInfo || null == webenterprise) {
        // 登录状态失效,跳转到注册页面
        return "redirect:/userInfoWeb/denglu.html";
    }
    // 返回所有信任源所有
    List<String> allIssUerDn = new ArrayList<String>();
    allIssUerDn = sqlSession.selectList("com.itrus.portal.db.CrlContextMapper.selectAllIssUerDn");
    try {
        uiModel.addAttribute("allIssUerDn", jsonTool.writeValueAsString(allIssUerDn));
    } catch (JsonGenerationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    UserCert userCert = null;
    userCert = userCertService.getUserCertByCertSn(certSn);
    if (null == userCert)
        throw new UserInfoServiceException("未找到对应的证书信息");
    // DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
    UserCertPojo ucp = new UserCertPojo(userCert, userCert.getCertStartTime().getTime() + "", userCert.getCertEndTime().getTime() + "");
    CertBuf certBuf = sqlSession.selectOne("com.itrus.portal.db.CertBufMapper.selectByPrimaryKey", userCert.getCertBuf());
    uiModel.addAttribute("userCert", ucp);
    uiModel.addAttribute("certBase64", certBuf.getCertBuf().replaceAll("\n", ""));
    return "ixinweb/bangding";
}
Also used : UserCertPojo(com.itrus.portal.utils.UserCertPojo) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) Enterprise(com.itrus.portal.db.Enterprise) ArrayList(java.util.ArrayList) CertBuf(com.itrus.portal.db.CertBuf) UserInfo(com.itrus.portal.db.UserInfo) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with UserCert

use of com.itrus.portal.db.UserCert in project portal by ixinportal.

the class BindCertWebController method loginCertBind.

/**
 * 绑定登陆证书页面 szy 2016年8月18日 下午3:24:01
 *
 * @param mPhone
 *            手机号
 * @param password
 *            对应手机号的登陆密码
 * @param code
 *            验证码
 * @param productId
 *            产品id
 * @param projectId
 *            项目id
 * @param certBase64
 *            证书信息
 * @param enterprise
 *            企业信息包括,唯一表标识
 *            enterpriseSn,企业名称enterpriseName,企业类型enterpriseNature
 *            ,行业orgIndustry
 * @return Map<String,Object> retCode 返回状态码: -1默认错误,1验证码错误,2密码为空,3证书已经被绑定过,4
 *         企业信息不完整,0绑定成功 redirectCode 跳转标识码 -1默认错误,1购买产品页面,2安全服务页面 retMsg
 *         返回信息
 */
@RequestMapping("/loginCertBind")
@ResponseBody
public Map<String, Object> loginCertBind(@RequestParam(value = "mPhone", required = true) String mPhone, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "code", required = true) String code, @RequestParam(value = "certBase64", required = true) String certBase64, @RequestParam(value = "keySn", required = false) String keySn, @RequestParam(value = "productId", required = true) Long productId, @RequestParam(value = "projectId", required = true) Long projectId, @ModelAttribute("enterprise") Enterprise enterprise, HttpSession session) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    // 错误
    retMap.put("retCode", -1);
    // 错误
    retMap.put("redirectCode", -1);
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(def);
    try {
        if (null == enterprise || StringUtils.isBlank(enterprise.getEnterpriseSn()) || StringUtils.isBlank(enterprise.getEnterpriseName()) || null == enterprise.getEnterpriseNature() || null == enterprise.getOrgIndustry()) {
            retMap.put("retCode", 4);
            retMap.put("retMsg", "您提交的企业信息不完整");
            return retMap;
        }
        // 验证动态码,
        if (!dynamicCodeService.verifyCode(mPhone, code)) {
            // 验证码不通过,状态 1
            retMap.put("retCode", 1);
            retMap.put("retMsg", "动态码验证失败");
            return retMap;
        }
        // 绑定用户和证书
        UserInfo userInfo = userInfoService.getUserInfoByMphone(mPhone);
        enterprise = enterpriseService.addEnterPrise(enterprise);
        if (null == userInfo) {
            if (StringUtils.isBlank(password)) {
                retMap.put("retCode", 2);
                retMap.put("retMsg", "请先设置登录口令");
                return retMap;
            }
            if (projectId != null) {
                // 先自动创建用户
                userInfo = userInfoService.registerUserInfo(mPhone, password, projectId);
                // 记录系统日志
                String info = mPhone + "注册成功";
                LogUtil.syslog(sqlSession, "注册用户", info);
            }
        }
        // 添加企业-代理人关联关系
        userInfoEnterpriseServiceImpl.saveUserInfoEnterprise(userInfo.getId(), enterprise.getId());
        // 获取证书
        UserCert userCert = userCertService.getUserCert(certBase64);
        // 判断是否已和证书绑定
        if (userCertService.isBindCert(userInfo.getId(), certBase64)) {
            retMap.put("retCode", 3);
            retMap.put("retMsg", "该证书已绑定过用户");
            return retMap;
        }
        // key序列号
        if (StringUtils.isNotBlank(keySn))
            userCert.setKeySn(keySn);
        // 绑定证书与用户关系
        userCert.setUserinfo(userInfo.getId());
        userCert.setEnterprise(enterprise.getId());
        sqlSession.update("com.itrus.portal.db.UserCertMapper.updateByPrimaryKey", userCert);
        // 如果是从项目页面中链接过来,跳转到购买产品页面
        // 否则 跳转到安全服务页面
        Boolean webnoProduct = (Boolean) session.getAttribute("webnoProduct");
        if (webnoProduct != null && webnoProduct) {
            retMap.put("redirectCode", 1);
        } else {
            retMap.put("redirectCode", 2);
        }
        session.setAttribute("webuserInfo", userInfo);
        session.setAttribute("webenterprise", enterprise);
        session.setAttribute("webverifyCodeStatus", true);
        // 返回绑定成功
        retMap.put("retCode", 0);
        transactionManager.commit(status);
    } catch (CertificateException e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (UserInfoServiceException e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (SigningServerException e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (Exception e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", "服务端出现未知异常,请联系管理员");
        String info = mPhone + "绑定证书失败,原因:" + e.getMessage();
        LogUtil.syslog(sqlSession, "绑定证书", info);
        return retMap;
    } finally {
        if (!status.isCompleted())
            transactionManager.rollback(status);
    }
    return retMap;
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) CertificateException(java.security.cert.CertificateException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SigningServerException(com.itrus.cryptorole.SigningServerException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) SigningServerException(com.itrus.cryptorole.SigningServerException) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 30 with UserCert

use of com.itrus.portal.db.UserCert in project portal by ixinportal.

the class BindCertWebController method bindCert.

// 绑定用户和证书
@RequestMapping("/bindCert")
@ResponseBody
public Map<String, Object> bindCert(@RequestParam(value = "mPhone", required = true) String mPhone, @RequestParam(value = "code", required = true) String code, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "projectId", required = true) Long projectId, @RequestParam(value = "certBase64", required = true) String certBase64, @RequestParam(value = "keySn", required = false) String keySn, HttpSession session) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    // 0标识发送验证码失败,1标识成功
    retMap.put("retCode", 0);
    UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
    Enterprise webenterprise = (Enterprise) session.getAttribute("webenterprise");
    if (null == webuserInfo || null == webenterprise) {
        // 登录状态失效,跳转到注册页面
        // 2标识登录已经失效,需跳转到登录页面
        retMap.put("retCode", 2);
        retMap.put("retMsg", "登录已经失效");
        return retMap;
    }
    // 验证动态码,
    if (!dynamicCodeService.verifyCode(mPhone, code)) {
        // 验证码不通过
        retMap.put("retMsg", "动态码验证失败");
        return retMap;
    }
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(def);
    try {
        // 绑定用户和证书
        UserInfo userInfo = userInfoService.getUserInfoByMphone(mPhone);
        if (null == userInfo) {
            if (StringUtils.isBlank(password)) {
                retMap.put("retMsg", "请先设置登录口令");
                return retMap;
            }
            // 先自动创建用户
            userInfo = userInfoService.registerUserInfo(mPhone, password, projectId);
            // 记录系统日志
            String info = mPhone + "注册成功";
            LogUtil.syslog(sqlSession, "注册用户", info);
        }
        // 添加企业-代理人关联关系
        userInfoEnterpriseServiceImpl.saveUserInfoEnterprise(userInfo.getId(), webenterprise.getId());
        // 获取证书
        UserCert userCert = userCertService.getUserCert(certBase64);
        // 判断是否已和证书绑定
        if (userCertService.isBindCert(userInfo.getId(), certBase64)) {
            retMap.put("retMsg", "该证书已绑定过用户");
            return retMap;
        }
        // 绑定证书与用户关系
        if (StringUtils.isNotBlank(keySn))
            userCert.setKeySn(keySn);
        userCert.setUserinfo(userInfo.getId());
        userCert.setEnterprise(webenterprise.getId());
        sqlSession.update("com.itrus.portal.db.UserCertMapper.updateByPrimaryKey", userCert);
        retMap.put("retCode", 1);
        transactionManager.commit(status);
        return retMap;
    } catch (CertificateException e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (UserInfoServiceException e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (SigningServerException e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (Exception e) {
        if (!status.isCompleted())
            transactionManager.rollback(status);
        retMap.put("retMsg", "服务端出现未知异常,请联系管理员");
        String info = mPhone + "绑定证书失败,原因:" + e.getMessage();
        LogUtil.syslog(sqlSession, "绑定证书", info);
        return retMap;
    } finally {
        if (!status.isCompleted())
            transactionManager.rollback(status);
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) CertificateException(java.security.cert.CertificateException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SigningServerException(com.itrus.cryptorole.SigningServerException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Enterprise(com.itrus.portal.db.Enterprise) SigningServerException(com.itrus.cryptorole.SigningServerException) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

UserCert (com.itrus.portal.db.UserCert)54 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)39 UserInfo (com.itrus.portal.db.UserInfo)25 HashMap (java.util.HashMap)24 Bill (com.itrus.portal.db.Bill)22 IOException (java.io.IOException)21 Enterprise (com.itrus.portal.db.Enterprise)19 Product (com.itrus.portal.db.Product)19 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)15 Date (java.util.Date)15 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)14 JSONObject (com.alibaba.fastjson.JSONObject)13 ArrayList (java.util.ArrayList)11 UserCertExample (com.itrus.portal.db.UserCertExample)10 CertBuf (com.itrus.portal.db.CertBuf)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 SigningServerException (com.itrus.cryptorole.SigningServerException)7 Project (com.itrus.portal.db.Project)7 UserinfoEnterprise (com.itrus.portal.db.UserinfoEnterprise)7 CertificateException (java.security.cert.CertificateException)7