Search in sources :

Example 21 with UserCert

use of com.itrus.portal.db.UserCert 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;
}
Also used : UserCertExample(com.itrus.portal.db.UserCertExample) X509Certificate(com.itrus.cert.X509Certificate) UserCert(com.itrus.portal.db.UserCert)

Example 22 with UserCert

use of com.itrus.portal.db.UserCert 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;
}
Also used : UserCertExample(com.itrus.portal.db.UserCertExample) CertBuf(com.itrus.portal.db.CertBuf) Date(java.util.Date) UserCert(com.itrus.portal.db.UserCert)

Example 23 with UserCert

use of com.itrus.portal.db.UserCert 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;
}
Also used : UserCertExample(com.itrus.portal.db.UserCertExample) UserCert(com.itrus.portal.db.UserCert)

Example 24 with UserCert

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

the class EvidenceSaveContractService method saveFactor.

// 核验要素
private Map<String, Object> saveFactor(Map<String, Object> result, EvidenceSaveService evidenceSaveService, String evidenceSn, JSONObject jsonEvidenceContent, EvidenceBasicInformation basicInformation, RealNameAuthentication realNameAuthentication, RealNameAuthentication realNameAuthenticationOss, EvidenceServiceConfiguration serviceConfiguration, Boolean bl, Long sbtTime) throws Exception {
    List<Object> objs = new ArrayList<Object>();
    // 定义证据要素字段
    String saveFactor = null;
    // 证据存证的业务类型
    String type = null;
    // 得到业务基本信息要素配置
    String factorBusinessInfo = evidenceSaveService.getFactorBusinessInfo();
    JSONArray jsonBiArray = JSONArray.parseArray(factorBusinessInfo);
    try {
        // TODO : 核验身份认证
        if (jsonEvidenceContent.get("authId") != null && bl) {
            basicInformation.setEvidenceType(1);
            // 得到数据包身份认证数据
            JSONObject jsonAuthId = jsonEvidenceContent.getJSONObject("authId");
            for (int i = 0; i < jsonBiArray.size(); i++) {
                JSONObject object = jsonBiArray.getJSONObject(i);
                JSONObject jsonContent;
                // 事件发生平台
                if (i == 0) {
                    jsonContent = jsonAuthId.getJSONObject("eventHapPlatform");
                    // 判断是否接收
                    if (object.getBooleanValue("b_isReception")) {
                        // 判断是否必填
                        if (object.getBooleanValue("b_isRequired") && StringUtils.isEmpty(jsonContent.getString("hapPlatformDomain"))) {
                            result.put("status", 0);
                            result.put("message", "提交的参数信息不完整,缺少事件发生平台必要参数值");
                            return result;
                        }
                        basicInformation.setEventPlatformName(jsonContent.getString("hapPlatformName"));
                        basicInformation.setDomainName(jsonContent.getString("hapPlatformDomain"));
                        if (StringUtils.isEmpty(saveFactor) || !saveFactor.contains("基本信息"))
                            saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, "基本信息");
                    }
                }
            }
            EvidenceMainInformation mainInformation = null;
            // 得到身份认证要素配置
            String factorIdVerify = evidenceSaveService.getFactorIdVerify();
            JSONArray jsonIdArray = JSONArray.parseArray(factorIdVerify);
            // 得到证据包中的身份认证数据
            for (int i = 0; i < jsonIdArray.size(); i++) {
                // 得到对应认证配置
                JSONObject object = jsonIdArray.getJSONObject(i);
                JSONObject jsonContent = null;
                switch(i) {
                    // 主体身份
                    case 0:
                        jsonContent = jsonAuthId.getJSONObject("principalId");
                        // 判断是否接收
                        if (object.getBooleanValue("i_isReception")) {
                            // 判断是否必填
                            if (object.getBooleanValue("i_isRequired") && (StringUtils.isEmpty(jsonContent.getString("name")) || StringUtils.isEmpty(jsonContent.getString("dataId")) || StringUtils.isEmpty(jsonContent.getString("type")))) {
                                result.put("status", 0);
                                result.put("message", "提交的参数信息不完整,缺少主体身份参数值");
                                return result;
                            }
                            // 判断主体是否存在
                            String idCacheKey = jsonContent.getString("name") + jsonContent.getString("dataId");
                            if (cacheMainMap.get(idCacheKey) != null) {
                                mainInformation = cacheMainMap.get(idCacheKey);
                            } else {
                                EvidenceMainInformationExample mainInformationExample = new EvidenceMainInformationExample();
                                EvidenceMainInformationExample.Criteria mainExampleCriteria = mainInformationExample.createCriteria();
                                mainExampleCriteria.andSubjectNameEqualTo(jsonContent.getString("name").trim());
                                mainExampleCriteria.andIdentificationEqualTo(jsonContent.getString("dataId").trim());
                                mainExampleCriteria.andMainTypeEqualTo(jsonContent.getString("type"));
                                mainInformationExample.setOrderByClause("create_time DESC");
                                List<EvidenceMainInformation> mainInformationList = sqlSession.selectList("com.itrus.portal.db.EvidenceMainInformationMapper.selectByExample", mainInformationExample);
                                if (!mainInformationList.isEmpty()) {
                                    mainInformation = mainInformationList.get(0);
                                }
                                // 当主体为空时 添加主体信息
                                if (mainInformation == null) {
                                    mainInformation = new EvidenceMainInformation();
                                    mainInformation.setSubjectName(jsonContent.getString("name").trim());
                                    mainInformation.setIdentification(jsonContent.getString("dataId").trim());
                                    mainInformation.setMainType(jsonContent.getString("type"));
                                    mainInformation.setCreateTime(new Date());
                                    objs.add(mainInformation);
                                }
                                cacheMainMap.put(mainInformation.getSubjectName() + mainInformation.getIdentification(), mainInformation);
                            }
                            // 添加证据和主体关系表
                            EvidenceSubjectIdentity subjectIdentity1 = new EvidenceSubjectIdentity();
                            subjectIdentity1.setBasicInformation(evidenceSn);
                            subjectIdentity1.setMainInformation(jsonContent.getString("dataId").trim());
                            subjectIdentity1.setMainName(jsonContent.getString("name").trim());
                            subjectIdentity1.setMainType(jsonContent.getShort("type"));
                            subjectIdentity1.setCreateTime(new Date());
                            objs.add(subjectIdentity1);
                            saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("i_factor"));
                        }
                        break;
                    // 身份意愿鉴别
                    case 1:
                        jsonContent = jsonAuthId.getJSONObject("authIdWillSms");
                        // 判断是否接收
                        if (object.getBooleanValue("i_isReception")) {
                            // 判断是否必填
                            if (object.getBooleanValue("i_isRequired") && (StringUtils.isEmpty(jsonContent.getString("phone")) || StringUtils.isEmpty(jsonContent.getString("sendTime")) || StringUtils.isEmpty(jsonContent.getString("content")) || StringUtils.isEmpty(jsonContent.getString("verifyCode")) || StringUtils.isEmpty(jsonContent.getString("verifySmsTime")) || StringUtils.isEmpty(jsonContent.getString("verifierType")))) {
                                result.put("status", 0);
                                result.put("message", "提交的参数信息不完整,缺少身份意愿鉴别参数值");
                                return result;
                            }
                            // 获取验证方
                            String eventVerifier = getAuthenticator(Integer.parseInt(jsonContent.getString("verifierType")), basicInformation.getEventPlatformName());
                            // 存储身份意愿鉴别信息
                            EvidenceDesireIdentify desireIdentify = new EvidenceDesireIdentify();
                            desireIdentify.setVerifier(eventVerifier);
                            desireIdentify.setVerifierType(jsonContent.getString("verifierType"));
                            desireIdentify.setPhone(jsonContent.getString("phone"));
                            desireIdentify.setSendOutTime(jsonContent.getDate("sendTime"));
                            desireIdentify.setSmsContent(jsonContent.getString("content"));
                            desireIdentify.setVerificationCode(jsonContent.getString("verifyCode"));
                            desireIdentify.setVerificationTime(jsonContent.getDate("verifySmsTime"));
                            desireIdentify.setMainInformation(mainInformation.getSubjectName() + ";" + mainInformation.getIdentification());
                            desireIdentify.setCreateTime(new Date());
                            desireIdentify.setEvidenceSn(evidenceSn);
                            objs.add(desireIdentify);
                            // 整合提交要素
                            saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("i_factor"));
                        }
                        break;
                    // 身份实名认证
                    case 2:
                        JSONObject jsonContentPerson = jsonAuthId.getJSONObject("authIdInfoPerson");
                        JSONObject jsonContentBusiness = jsonAuthId.getJSONObject("authIdInfoBusiness");
                        // 判断是否接收
                        if (object.getBooleanValue("i_isReception")) {
                            // 核验个人身份认证和企业身份认证是否提交其一
                            if ((jsonContentPerson == null && jsonContentBusiness == null) || (jsonContentPerson != null && jsonContentBusiness != null)) {
                                result.put("status", 0);
                                result.put("message", "提交的参数信息错误,个人身份认证和企业身份认证只能提交其一");
                                return result;
                            }
                            // true 代表个人身份认证       false 代表企业身份认证
                            if (jsonContentPerson != null) {
                                // 判断是否必填
                                if (object.getBooleanValue("i_isRequired") && (StringUtils.isEmpty(jsonContentPerson.getString("authenticatorType")))) {
                                    result.put("status", 0);
                                    result.put("message", "提交的参数信息不完整,缺少身份实名认证参数值");
                                    return result;
                                }
                                String eventVerifier = getAuthenticator(Integer.parseInt(jsonContentPerson.getString("authenticatorType")), basicInformation.getEventPlatformName());
                                // 身份实名认证表
                                EvidenceRealName realName = new EvidenceRealName();
                                realName.setEventVerifierType(jsonContentPerson.getString("authenticatorType"));
                                realName.setEventVerifier(eventVerifier);
                                realName.setCertificationTime(jsonContentPerson.getDate("time"));
                                realName.setType(mainInformation.getMainType());
                                realName.setMainInformation(mainInformation.getSubjectName() + ";" + mainInformation.getIdentification());
                                realName.setEvidenceSn(evidenceSn);
                                String orderNumber = jsonContentPerson.getString("orderNumber");
                                if (jsonContentPerson.getInteger("authenticatorType") == 1) {
                                    // 认证方 为 1 时,orderNumber 为必填项
                                    if (StringUtils.isEmpty(orderNumber)) {
                                        result.put("status", 0);
                                        result.put("message", "提交的参数信息不完整,缺少身份实名认证参数值");
                                        return result;
                                    }
                                    realName.setSerialnumber(orderNumber);
                                    // 判断企业实名认证信息是否为可靠信息
                                    for (String o : orderNumber.split(",")) {
                                        PersonalNameExample personalNameExample = new PersonalNameExample();
                                        PersonalNameExample.Criteria pec = personalNameExample.createCriteria();
                                        pec.andSerialnumberEqualTo(o);
                                        PersonalName personalName = sqlSession.selectOne("com.itrus.portal.db.PersonalNameMapper.selectByExample", personalNameExample);
                                        if (personalName == null || personalName.getAuthenticationstatus() != 0) {
                                            result.put("status", 0);
                                            result.put("message", "流水号为:" + o + "的个人信息验证未通过");
                                            return result;
                                        }
                                    }
                                } else if (jsonContentPerson.getInteger("authenticatorType") == 2) {
                                    EvidenceIndividual individual = new EvidenceIndividual();
                                    individual.setName(mainInformation.getSubjectName());
                                    individual.setCreateTime(new Date());
                                    individual.setIdCode(UniqueIDUtils.getUID());
                                    // 必填判断
                                    if (object.getBooleanValue("i_isRequired") && (StringUtils.isEmpty(jsonContentPerson.getString("idType")) || StringUtils.isEmpty(jsonContentPerson.getString("idCode")) || StringUtils.isEmpty(jsonContentPerson.getString("idImg1")))) {
                                        result.put("status", 0);
                                        result.put("message", "提交的参数信息不完整,缺少身份实名认证参数值");
                                        return result;
                                    }
                                    individual.setType(jsonContentPerson.getString("idType"));
                                    individual.setCertificateid(jsonContentPerson.getString("idCode"));
                                    // 1.身份证 2.其他
                                    if (jsonContentPerson.getIntValue("idType") == 1) {
                                        if (StringUtils.isNotEmpty(jsonContentPerson.getString("idImg1")) && StringUtils.isNotEmpty(jsonContentPerson.getString("idImg2"))) {
                                            // 存储图片
                                            File frontImg = saveImg(evidenceSn, jsonContentPerson.getString("idImg1"), IMG_ID_IMG_FRONT);
                                            individual.setPhotoCodeImg(frontImg.getName());
                                            individual.setPhotoCodeImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                            File frontImg2 = saveImg(evidenceSn, jsonContentPerson.getString("idImg2"), IMG_ID_IMG_BACK);
                                            individual.setInformationImg(frontImg2.getName());
                                            individual.setInformationImgHash(HMACSHA1.genSha1HashOfFile(frontImg2));
                                        } else {
                                            result.put("status", 0);
                                            result.put("message", "提交的参数信息不完整,个人身份认证证据为身份证时 idImg2 为必选参数。");
                                            return result;
                                        }
                                    } else {
                                        // 存储图片
                                        File frontImg = saveImg(evidenceSn, jsonContentPerson.getString("idImg1"), IMG_ID_IMG_BACK);
                                        individual.setPhotoCodeImg(frontImg.getName());
                                        individual.setPhotoCodeImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                    }
                                    objs.add(individual);
                                    realName.setIndividual(individual.getIdCode());
                                }
                                objs.add(realName);
                            } else {
                                // 判断是否必填
                                if (object.getBooleanValue("i_isRequired") && (StringUtils.isEmpty(jsonContentBusiness.getString("authenticatorType")))) {
                                    result.put("status", 0);
                                    result.put("message", "提交的参数信息不完整,缺少身份实名认证参数值");
                                    return result;
                                }
                                String eventVerifier = getAuthenticator(Integer.parseInt(jsonContentBusiness.getString("authenticatorType")), basicInformation.getEventPlatformName());
                                // 身份实名认证表
                                EvidenceRealName realName = new EvidenceRealName();
                                realName.setEventVerifierType(jsonContentBusiness.getString("authenticatorType"));
                                realName.setEventVerifier(eventVerifier);
                                realName.setCertificationTime(jsonContentBusiness.getDate("time"));
                                realName.setType(mainInformation.getMainType());
                                realName.setMainInformation(mainInformation.getSubjectName() + ":" + mainInformation.getIdentification());
                                realName.setEvidenceSn(evidenceSn);
                                String orderNumber = jsonContentBusiness.getString("orderNumber");
                                if (jsonContentBusiness.getInteger("authenticatorType") == 1) {
                                    // 认证方 为 1 时,orderNumber 为必填项
                                    if (StringUtils.isEmpty(orderNumber)) {
                                        result.put("status", 0);
                                        result.put("message", "提交的参数信息不完整,缺少身份实名认证参数值");
                                        return result;
                                    }
                                    realName.setSerialnumber(orderNumber);
                                    // 判断企业实名认证信息是否为可靠信息
                                    for (String o : orderNumber.split(",")) {
                                        RealNameRecordExample recordExample = new RealNameRecordExample();
                                        RealNameRecordExample.Criteria rec = recordExample.createCriteria();
                                        rec.andSerialnumberEqualTo(o);
                                        RealNameRecord realNameRecord = sqlSession.selectOne("com.itrus.portal.db.RealNameRecordMapper.selectByExample", recordExample);
                                        if (realNameRecord == null || realNameRecord.getAuthenticationstatus() != 0) {
                                            result.put("status", 0);
                                            result.put("message", "流水号为:" + o + "的企业信息验证未通过");
                                            return result;
                                        }
                                    }
                                } else if (jsonContentBusiness.getInteger("authenticatorType") == 2) {
                                    if (object.getBooleanValue("i_isRequired") && ((StringUtils.isEmpty(jsonContentBusiness.getString("blCode")) && StringUtils.isEmpty(jsonContentBusiness.getString("blImg"))) && (StringUtils.isEmpty(jsonContentBusiness.getString("orgCode")) && StringUtils.isEmpty(jsonContentBusiness.getString("orgImg"))))) {
                                        result.put("status", 0);
                                        result.put("message", "提交的参数信息不完整,缺少身份实名认证参数值");
                                        return result;
                                    }
                                    // 法人
                                    EvidenceRepresentative representative = null;
                                    if (StringUtils.isNotEmpty(jsonContentBusiness.getString("legalIdName")) && StringUtils.isNotEmpty(jsonContentBusiness.getString("legalIdType")) && StringUtils.isNotEmpty(jsonContentBusiness.getString("legalIdCode"))) {
                                        representative = new EvidenceRepresentative();
                                        representative.setName(jsonContentBusiness.getString("legalIdName"));
                                        representative.setType(jsonContentBusiness.getString("legalIdType"));
                                        representative.setCertificateid(jsonContentBusiness.getString("legalIdCode"));
                                        representative.setCreateTime(new Date());
                                        representative.setIdCode(UniqueIDUtils.getUID());
                                        // 存储图片
                                        if (StringUtils.isNotEmpty(jsonContentBusiness.getString("idImg1"))) {
                                            File frontImg = saveImg(evidenceSn, jsonContentBusiness.getString("idImg1"), IMG_ID_IMG_FRONT);
                                            representative.setPhotoCodeImg(frontImg.getName());
                                            representative.setPhotoCodeImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                        }
                                        if (StringUtils.isNotEmpty(jsonContentBusiness.getString("idImg2"))) {
                                            File frontImg = saveImg(evidenceSn, jsonContentBusiness.getString("idImg2"), IMG_ID_IMG_BACK);
                                            representative.setInformationImg(frontImg.getName());
                                            representative.setInformationImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                        }
                                        // 存储法人信息
                                        objs.add(representative);
                                    }
                                    // 代理人
                                    EvidenceTheAgent theAgent = null;
                                    if (StringUtils.isNotEmpty(jsonContentBusiness.getString("agentIdName")) && StringUtils.isNotEmpty(jsonContentBusiness.getString("agentIdType")) && StringUtils.isNotEmpty(jsonContentBusiness.getString("agentIdCode"))) {
                                        theAgent = new EvidenceTheAgent();
                                        theAgent.setName(jsonContentBusiness.getString("agentIdName"));
                                        theAgent.setType(jsonContentBusiness.getString("agentIdType"));
                                        theAgent.setCertificateid(jsonContentBusiness.getString("agentIdCode"));
                                        theAgent.setCreateTime(new Date());
                                        theAgent.setIdCode(UniqueIDUtils.getUID());
                                        // 存储图片
                                        if (StringUtils.isNotEmpty(jsonContentBusiness.getString("agentIdImg1"))) {
                                            File frontImg = saveImg(evidenceSn, jsonContentBusiness.getString("agentIdImg1"), IMG_ID_IMG_FRONT);
                                            theAgent.setPhotoCodeImg(frontImg.getName());
                                            theAgent.setPhotoCodeImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                        }
                                        if (StringUtils.isNotEmpty(jsonContentBusiness.getString("agentIdImg2"))) {
                                            File frontImg = saveImg(evidenceSn, jsonContentBusiness.getString("agentIdImg2"), IMG_ID_IMG_BACK);
                                            theAgent.setInformationImg(frontImg.getName());
                                            theAgent.setInformationImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                        }
                                        // // 存储代理人信息
                                        objs.add(theAgent);
                                        // 营业执照
                                        EvidenceCompaniesSubmit companiesSubmit = new EvidenceCompaniesSubmit();
                                        companiesSubmit.setBusCertificateid(jsonContentBusiness.getString("blCode"));
                                        if (StringUtils.isNotEmpty(jsonContentBusiness.getString("blImg"))) {
                                            // 存储图片
                                            File frontImg = saveImg(evidenceSn, jsonContentBusiness.getString("blImg"), IMG_BL);
                                            companiesSubmit.setPhotoCodeImg(frontImg.getName());
                                            companiesSubmit.setPhotoCodeImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                        }
                                        // 组织机构代码
                                        companiesSubmit.setOrgCertificateid(jsonContentBusiness.getString("orgCode"));
                                        if (StringUtils.isNotEmpty(jsonContentBusiness.getString("orgImg"))) {
                                            // 存储图片
                                            File frontImg = saveImg(evidenceSn, jsonContentBusiness.getString("orgImg"), IMG_ORG);
                                            companiesSubmit.setInformationImg(frontImg.getName());
                                            companiesSubmit.setInformationImgHash(HMACSHA1.genSha1HashOfFile(frontImg));
                                        }
                                        if (theAgent != null)
                                            companiesSubmit.setTheAgent(theAgent.getIdCode());
                                        if (representative != null)
                                            companiesSubmit.setRepresentative(representative.getIdCode());
                                        companiesSubmit.setBusinessName(mainInformation.getSubjectName());
                                        companiesSubmit.setCreateTime(new Date());
                                        companiesSubmit.setIdCode(UniqueIDUtils.getUID());
                                        objs.add(companiesSubmit);
                                        realName.setCompaniesSubmit(companiesSubmit.getIdCode());
                                    }
                                }
                                objs.add(realName);
                            }
                            saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("i_factor"));
                        }
                        break;
                    default:
                        break;
                }
            }
        }
        // TODO : 核验事件认证
        if (jsonEvidenceContent.get("authEvent") != null) {
            basicInformation.setEvidenceType(2);
            JSONObject jsonAuthEvent = jsonEvidenceContent.getJSONObject("authEvent");
            // 可信身份缓存信息
            List<EvidenceTrustedIdentity> tiCacheList = new ArrayList<>();
            // 核验基础信息
            for (int i = 0; i < jsonBiArray.size(); i++) {
                JSONObject object = jsonBiArray.getJSONObject(i);
                JSONObject jsonContent;
                switch(i) {
                    // 事件发生平台
                    case 0:
                        jsonContent = jsonAuthEvent.getJSONObject("eventHapPlatform");
                        // 判断是否接收
                        if (object.getBooleanValue("b_isReception")) {
                            // 判断是否必填
                            if (object.getBooleanValue("b_isRequired") && StringUtils.isEmpty(jsonContent.getString("hapPlatformDomain"))) {
                                result.put("status", 0);
                                result.put("message", "提交的参数信息不完整,缺少事件发生平台必要参数值");
                                return result;
                            }
                            basicInformation.setEventPlatformName(jsonContent.getString("hapPlatformName"));
                            basicInformation.setDomainName(jsonContent.getString("hapPlatformDomain"));
                            saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, "基本信息");
                        }
                        break;
                    // 业务类型
                    case 1:
                        String eventType = jsonAuthEvent.getString("eventType");
                        // 判断是否接收
                        if (object.getBooleanValue("b_isReception")) {
                            // 判断是否必填
                            if (object.getBooleanValue("b_isRequired") && StringUtils.isEmpty(eventType)) {
                                result.put("status", 0);
                                result.put("message", "提交的参数信息不完整,缺少业务类型参数值");
                                return result;
                            }
                            basicInformation.setType(eventType);
                            type = object.getString("b_category");
                            saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, "基本信息");
                        }
                        break;
                    // 业务单号
                    case 3:
                        String eventSn = jsonAuthEvent.getString("eventSn");
                        // 判断是否接收
                        if (object.getBooleanValue("b_isReception")) {
                            basicInformation.setServiceNumber(eventSn);
                            saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, "基本信息");
                        }
                        break;
                    default:
                        break;
                }
            }
            // 得到身份认证要素配置
            JSONArray jsonIdArray = JSONArray.parseArray(evidenceSaveService.getFactorIdVerify());
            for (int i = 0; i < jsonIdArray.size(); i++) {
                JSONObject object = jsonIdArray.getJSONObject(i);
                if (i == 3 && object.getBooleanValue("i_isReception")) {
                    // 得到事件包信息数据
                    JSONArray jsonContentArray = jsonAuthEvent.getJSONArray("event");
                    for (int j = 0; j < jsonContentArray.size(); j++) {
                        JSONObject jsonContent = jsonContentArray.getJSONObject(j).getJSONObject("principalId");
                        // 判断是否必填
                        if (object.getBooleanValue("e_isRequired") && (StringUtils.isEmpty(jsonContent.getString("type")) || StringUtils.isEmpty(jsonContent.getString("certSn")) || StringUtils.isEmpty(jsonContent.getString("name")) || StringUtils.isEmpty(jsonContent.getString("dataId")))) {
                            result.put("status", 0);
                            result.put("message", "提交的参数信息不完整,缺少可信身份标识参数值");
                            return result;
                        }
                        // 判断主体是否存在
                        String idCacheKey = jsonContent.getString("name").trim() + jsonContent.getString("dataId").trim();
                        EvidenceMainInformation mainInformation = cacheMainMap.get(idCacheKey);
                        EvidenceBasicInformation basicInformation2 = null;
                        if (mainInformation == null) {
                            EvidenceMainInformationExample mainInformationExample = new EvidenceMainInformationExample();
                            EvidenceMainInformationExample.Criteria mainExampleCriteria = mainInformationExample.createCriteria();
                            mainExampleCriteria.andSubjectNameEqualTo(jsonContent.getString("name").trim());
                            mainExampleCriteria.andIdentificationEqualTo(jsonContent.getString("dataId").trim());
                            mainExampleCriteria.andMainTypeEqualTo(jsonContent.getString("type"));
                            mainInformationExample.setOrderByClause("create_time DESC");
                            List<EvidenceMainInformation> mainInformationList = sqlSession.selectList("com.itrus.portal.db.EvidenceMainInformationMapper.selectByExample", mainInformationExample);
                            if (!mainInformationList.isEmpty()) {
                                mainInformation = mainInformationList.get(0);
                            }
                        }
                        // 当主体为空时 添加主体信息
                        if (mainInformation == null) {
                            mainInformation = new EvidenceMainInformation();
                            mainInformation.setSubjectName(jsonContent.getString("name").trim());
                            mainInformation.setIdentification(jsonContent.getString("dataId").trim());
                            mainInformation.setMainType(jsonContent.getString("type"));
                            mainInformation.setCreateTime(new Date());
                            objs.add(mainInformation);
                        }
                        // 遍历 mapIdCache 的key值 判断是否存在   不存在则添加
                        // for(String key:mapIdCache.keySet()) {
                        // if(!idCacheKey.equals(key)) {
                        cacheMainMap.put(mainInformation.getSubjectName() + mainInformation.getIdentification(), mainInformation);
                        // }
                        // }
                        // 判断基础信息表 和 主体表是否存在关联
                        // EvidenceSubjectIdentityExample subjectIdentityExampleExist = new EvidenceSubjectIdentityExample();
                        // EvidenceSubjectIdentityExample.Criteria iece = subjectIdentityExampleExist.createCriteria();
                        // iece.andBasicInformationEqualTo(evidenceSn);
                        // iece.andMainInformationEqualTo(mainInformation.getIdentification());
                        // EvidenceSubjectIdentity subjectIdentityExist = sqlSession
                        // .selectOne("com.itrus.portal.db.EvidenceSubjectIdentityMapper.selectByExample", subjectIdentityExampleExist);
                        // if(subjectIdentityExist == null) {
                        // 
                        // }
                        // 基础信息表 和 主体表添加关联
                        EvidenceSubjectIdentity subjectIdentity1 = new EvidenceSubjectIdentity();
                        subjectIdentity1.setBasicInformation(evidenceSn);
                        subjectIdentity1.setMainInformation(mainInformation.getIdentification());
                        subjectIdentity1.setCreateTime(new Date());
                        subjectIdentity1.setMainName(mainInformation.getSubjectName());
                        subjectIdentity1.setMainType(Short.parseShort(mainInformation.getMainType()));
                        objs.add(subjectIdentity1);
                        // 判断是否需要关联身份证据
                        if (StringUtils.isNotEmpty(jsonContent.getString("evidenceSn"))) {
                            basicInformation2 = basicInformationService.getInformationBySn(jsonContent.getString("evidenceSn"), 1);
                            if (basicInformation2 != null) {
                                EvidenceSubjectIdentityExample subjectIdentityExample = new EvidenceSubjectIdentityExample();
                                EvidenceSubjectIdentityExample.Criteria iec = subjectIdentityExample.createCriteria();
                                iec.andBasicInformationEqualTo(jsonContent.getString("evidenceSn"));
                                iec.andMainInformationEqualTo(mainInformation.getIdentification());
                                EvidenceSubjectIdentity subjectIdentity = sqlSession.selectOne("com.itrus.portal.db.EvidenceSubjectIdentityMapper.selectByExample", subjectIdentityExample);
                                if (subjectIdentity == null) {
                                    result.put("status", 0);
                                    result.put("message", "证据编码:" + jsonContent.getString("evidenceSn") + "与主体:" + jsonContent.getString("name") + "," + jsonContent.getString("dataId") + "不存在关联");
                                    return result;
                                }
                            } else {
                                result.put("status", 0);
                                result.put("message", "证据编码:" + jsonContent.getString("evidenceSn") + "与主体:" + jsonContent.getString("name") + "," + jsonContent.getString("dataId") + "不存在关联");
                                return result;
                            }
                        }
                        EvidenceTrustedIdentity trustedIdentity = new EvidenceTrustedIdentity();
                        trustedIdentity.setCertSerialnumber(jsonContent.getString("certSn"));
                        trustedIdentity.setIdentiType(jsonContent.getString("type"));
                        trustedIdentity.setBasicInformation(basicInformation.getEvidenceSn());
                        // trustedIdentity.setEvidenceEnclosure(enclosure.getId());
                        if (StringUtils.isNotEmpty(jsonContent.getString("evidenceSn")))
                            trustedIdentity.setEvidenceSn(jsonContent.getString("evidenceSn"));
                        trustedIdentity.setCreateTime(new Date());
                        if (mainInformation != null && !"".equals(mainInformation))
                            trustedIdentity.setMainInformation(mainInformation.getSubjectName() + ";" + mainInformation.getIdentification());
                        // sqlSession.insert("com.itrus.portal.db.EvidenceTrustedIdentityMapper.insert", trustedIdentity);
                        // sqlSession.flushStatements();
                        tiCacheList.add(trustedIdentity);
                    }
                    saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("i_factor"));
                }
            }
            // 得到事件认证要素配置
            JSONArray jsonEvArray = JSONArray.parseArray(evidenceSaveService.getFactorEventVerify());
            EvidenceEventContent eventContent = new EvidenceEventContent();
            // 得到证据包中的事件数据
            for (int i = 0; i < jsonEvArray.size(); i++) {
                JSONObject object = jsonEvArray.getJSONObject(i);
                switch(i) {
                    // 事件认证
                    case 0:
                        log.equals("type is " + "电子合同PDF".equals(type));
                        // 判断合同类型
                        if ("电子合同PDF".equals(type)) {
                            // 电子合同
                            log.error("e_isReception is " + object.getBooleanValue("e_isReception"));
                            // 判断是否接收
                            if (object.getBooleanValue("e_isReception")) {
                                // 得到事件内容中的信息
                                JSONObject jsonEventContent = jsonAuthEvent.getJSONObject("eventContent");
                                // 判断必填
                                if (object.getBooleanValue("e_isRequired") && (StringUtils.isEmpty(jsonEventContent.getString("contCode")))) {
                                    result.put("status", 0);
                                    result.put("message", "提交的参数信息不完整,缺少事件内容认证参数值");
                                    return result;
                                }
                                String urlPdfVerify = realNameAuthentication.getRealNameddress() + PDF_VERIFY;
                                Map<String, Object> mapPdfVerify = new HashMap<String, Object>();
                                mapPdfVerify.put("pdfContent", jsonEventContent.get("contCode"));
                                eventContent.setIsPdf(true);
                                eventContent.setContractTitle(jsonEventContent.getString("title"));
                                eventContent.setValidStartTime(jsonEventContent.getDate("validStartTime"));
                                eventContent.setValidEndTime(jsonEventContent.getDate("validEndTime"));
                                eventContent.setCreateTime(new Date());
                                eventContent.setEvidenceSn(evidenceSn);
                                eventContent.setIdCode(UniqueIDUtils.getUID());
                                log.error("e_isVerify is " + object.getBooleanValue("e_isVerify"));
                                if (object.getBooleanValue("e_isVerify")) {
                                    Long pdfVerifyTimeAsync = System.currentTimeMillis();
                                    // 异步处理pdf验章
                                    // HttpAsyncClientUtil.getInstance().execute(
                                    // urlPdfVerify,
                                    // AuthService.getHeader(),
                                    // mapPdfVerify,
                                    // new EvidencePdfVerifyService(
                                    // urlPdfVerify,
                                    // jsonEventContent.getString("contCode"),
                                    // eventContent,
                                    // tiCacheList));
                                    OkHttpClientManagerPdfVerify.postAsyn(urlPdfVerify, AuthService.getHeader().get("Authorization").toString(), mapPdfVerify, new EvidencePdfVerifyService(urlPdfVerify, jsonEventContent.getString("contCode"), eventContent, tiCacheList));
                                    log.error("pdfVerifyTimeAsync time is [" + (System.currentTimeMillis() - pdfVerifyTimeAsync) + "]");
                                // 调用pdf验章接口
                                // Long pdfVerifyTime = System.currentTimeMillis();
                                // String rep_pdf_verify = OkHttpClientManagerPdfVerify.post(urlPdfVerify, AuthService.getHeader().get("Authorization").toString(), mapPdfVerify);
                                // log.error("pdfVerifyTime time is [" + (System.currentTimeMillis() - pdfVerifyTime) + "]");
                                // 
                                // JSONObject jsonPdfVerify = JSONObject.parseObject(rep_pdf_verify);
                                // if(jsonPdfVerify.getInteger("code") == 0){
                                // eventContent.setEventStatus(1);
                                // } else {
                                // eventContent.setEventStatus(0);
                                // eventContent.setFailureReason(jsonPdfVerify.getString("message"));
                                // basicInformation.setEvidenceStatus(0);
                                // if(StringUtils.isEmpty(basicInformation.getFailureReason())) {
                                // basicInformation.setFailureReason(jsonPdfVerify.getString("message"));
                                // } else {
                                // basicInformation.setFailureReason(basicInformation.getFailureReason() + "," + jsonPdfVerify.getString("message"));
                                // }
                                // }
                                // String retVerifyTi = null;
                                // String retVerifyBehavior = null;
                                // String retVerifyTime = null;
                                // if(StringUtils.isNotEmpty(rep_pdf_verify)
                                // && StringUtils.isNotEmpty(jsonPdfVerify.getString("signInfos"))) {
                                // // 解析pdf验章返回信息
                                // JSONArray jsonArraySignInfos = jsonPdfVerify.getJSONArray("signInfos");
                                // List<String> listStr = new ArrayList<>();
                                // int noId = 0;
                                // for(int k=0;k<jsonArraySignInfos.size();k++) {
                                // // 循环得到pdf验章返回数据
                                // JSONObject json = jsonArraySignInfos.getJSONObject(k);
                                // // 对应可信身份
                                // EvidenceTrustedIdentity trustedIdentity1 = null;
                                // 
                                // // 判断验章是否包含证书
                                // if(StringUtils.isNotEmpty(json.getString("signerCert"))) {
                                // // 解析签名者证书base64编码
                                // UserCert userCert1 = CertUtil.getCertFromBase64(json.getString("signerCert"));
                                // EvidenceCertUser certUser = certUserService.getCertBySn(userCert1.getCertSn());
                                // if(certUser == null) {
                                // certUser = new EvidenceCertUser();
                                // certUser.setCertBase64(json.getString("signerCert"));
                                // certUser.setCertSerialnumber(userCert1.getCertSn());
                                // certUser.setSubjectdn(userCert1.getCertDn());
                                // certUser.setIssuerdn(userCert1.getIssuerDn());
                                // certUser.setIssuer(EvidenceSaveServiceApi.getCertCn(userCert1.getIssuerDn()));
                                // if(userCert1.getCertBuf() != null){
                                // certUser.setEvidenceBuf(userCert1.getCertBuf().toString());
                                // }
                                // certUser.setStartTime(userCert1.getCertStartTime());
                                // certUser.setEndTime(userCert1.getCertEndTime());
                                // certUser.setCreateTime(new Date());
                                // certUser.setIdCode(UniqueIDUtils.getUID());
                                // objs.add(certUser);
                                // }
                                // 
                                // boolean blt = true;
                                // // 循环已经存在的证书序列号   判断证书序列号是否存在
                                // for(String strCertSn:listStr){
                                // if(userCert1 != null && strCertSn.equals(userCert1.getCertSn())){
                                // blt = false;
                                // }
                                // }
                                // // 循环可信身份list缓存  判断证书序列号是否相同
                                // if(!tiCacheList.isEmpty() && tiCacheList != null){
                                // for(EvidenceTrustedIdentity identity:tiCacheList) {
                                // if(identity.getCertSerialnumber().equals(userCert1.getCertSn())){
                                // trustedIdentity1 = identity;
                                // }
                                // }
                                // }
                                // if(trustedIdentity1 == null) {
                                // noId--;
                                // }
                                // if(blt) {
                                // // 事件对象定义
                                // EvidenceTrustedIdentity trustedIdentity = new EvidenceTrustedIdentity();
                                // trustedIdentity.setBasicInformation(basicInformation.getEvidenceSn());
                                // trustedIdentity.setEventContent(eventContent.getIdCode());
                                // if(trustedIdentity1 != null){
                                // trustedIdentity.setMainInformation(trustedIdentity1.getMainInformation());
                                // // 整合证书信息存储到对应可信身份表
                                // trustedIdentity1.setCertBase64(certUser.getIdCode());
                                // //                                    					  sqlSession.update("com.itrus.portal.db.EvidenceTrustedIdentityMapper.updateByPrimaryKey",
                                // //                                    							  trustedIdentity1);
                                // objs.add(trustedIdentity1);
                                // } else {
                                // trustedIdentity.setMainInformation(noId+"");
                                // }
                                // trustedIdentity.setCertBase64(certUser.getIdCode());
                                // trustedIdentity.setCreateTime(new Date());
                                // trustedIdentity.setIdentiType("1");
                                // if(userCert1.getCertBuf() != null){
                                // trustedIdentity.setEvidenceBuf(userCert1.getCertBuf().toString());
                                // }
                                // trustedIdentity.setStartTime(userCert1.getCertStartTime());
                                // trustedIdentity.setEndTime(userCert1.getCertEndTime());
                                // 
                                // // 事件对象核验结果
                                // trustedIdentity.setCheckTime(new Date());
                                // if(json.getIntValue("vcResult") == 0) {
                                // trustedIdentity.setCheckStatus("1");
                                // trustedIdentity.setCheckSuccessTime(new Date());
                                // } else {
                                // if(StringUtils.isEmpty(retVerifyTi))
                                // retVerifyTi = "事件对象核验失败";
                                // trustedIdentity.setCheckStatus("0");
                                // if(json.getIntValue("vcResult") == 30006)
                                // trustedIdentity.setUnreason("未找到对应的受信任CA证书");
                                // else if(json.getIntValue("vcResult") == 30007)
                                // trustedIdentity.setUnreason("证书已吊销");
                                // else if(json.getIntValue("vcResult") == 30008)
                                // trustedIdentity.setUnreason("证书不在有效期内");
                                // else if(json.getIntValue("vcResult") == 30009)
                                // trustedIdentity.setUnreason("无效的证书签名");
                                // else if(json.getIntValue("vcResult") == 300010)
                                // trustedIdentity.setUnreason("其他证书验证错误");
                                // else
                                // trustedIdentity.setUnreason("非正常其他证书验证错误");
                                // }
                                // trustedIdentity.setVewestCheckTime(new Date());
                                // //        											trustedIdentity.setCheckContent("1.验证证书有效期/n2.验证证书颁发者签名/n3.验证证书是否吊销");
                                // //        											sqlSession.insert("com.itrus.portal.db.EvidenceTrustedIdentityMapper.insert", trustedIdentity);
                                // objs.add(trustedIdentity);
                                // }
                                // listStr.add(userCert1.getCertSn());
                                // } else {
                                // retVerifyTi = "事件对象核验失败";
                                // }
                                // // 事件行为定义
                                // EvidenceEventBehavior eventBehavior = new EvidenceEventBehavior();
                                // // 判断时间戳是否存在
                                // if(StringUtils.isNotEmpty(json.getString("timeStamp"))
                                // && !json.getString("timeStamp").equals("{}")) {
                                // // 验证时间戳
                                // EvidenceEventTime eventTime = new EvidenceEventTime();
                                // if(trustedIdentity1 != null){
                                // eventTime.setMainInformation(trustedIdentity1.getMainInformation());
                                // } else {
                                // eventTime.setMainInformation(noId+"");
                                // }
                                // eventTime.setIdentiType("1");
                                // eventTime.setEventContent(eventContent.getIdCode());
                                // eventTime.setCertificate(json.getJSONObject("timeStamp").getString("signature"));
                                // eventTime.setHashAlgorithm(json.getJSONObject("timeStamp").getString("hashAlg"));
                                // eventTime.setHashvalue(json.getJSONObject("timeStamp").getString("hashData"));
                                // eventTime.setCertBase64(json.getJSONObject("timeStamp").getString("tsCert"));
                                // if(StringUtils.isNotEmpty(json.getJSONObject("timeStamp").getString("time"))) {
                                // eventTime.setSignatureTime(json.getJSONObject("timeStamp").getDate("time"));
                                // } else {
                                // eventTime.setSignatureTime(json.getDate("stampTime"));
                                // }
                                // eventTime.setCreateTime(new Date());
                                // // 解析时间戳证书 Base64
                                // if(json.getJSONObject("timeStamp").getString("tsCert") != null) {
                                // UserCert userCert = CertUtil.getCertFromBase64(json.getJSONObject("timeStamp").getString("tsCert"));
                                // eventTime.setCertificateDn(userCert.getCertDn());
                                // eventTime.setIssuerdn(userCert.getIssuerDn());
                                // }
                                // // 时间核验结果
                                // eventTime.setCheckTime(new Date());
                                // if(json.getIntValue("vtsResult") == 0) {
                                // eventTime.setCheckStatus("1");
                                // eventTime.setCheckSuccessTime(new Date());
                                // } else {
                                // if(StringUtils.isEmpty(retVerifyTime)) {
                                // retVerifyTime = "事件时间核验失败";
                                // }
                                // eventTime.setCheckStatus("0");
                                // if(json.getIntValue("vtsResult") == 60002) {
                                // eventTime.setUnreason("验证时戳失败");
                                // } else {
                                // eventTime.setUnreason("其他验证时戳错误");
                                // }
                                // }
                                // eventTime.setVewestCheckTime(new Date());
                                // //        										eventTime.setCheckContent("签名原文完整、真实、是否被篡改");
                                // objs.add(eventTime);
                                // } else {
                                // eventBehavior.setVerificationTime(json.getDate("stampTime"));
                                // }
                                // // 判断事件行为是否返回为空
                                // if(StringUtils.isNotEmpty(json.getString("signature"))) {
                                // eventBehavior.setHashAlgorithm(json.getString("hashAlg"));
                                // eventBehavior.setSignaturevalue(json.getString("signature"));
                                // eventBehavior.setHashBackSigning(json.getString("msgDigest"));
                                // eventBehavior.setEventContent(eventContent.getIdCode());
                                // eventBehavior.setIdentiType("1");
                                // eventBehavior.setCreateTime(new Date());
                                // if(trustedIdentity1 != null){
                                // eventBehavior.setMainInformation(trustedIdentity1.getMainInformation());
                                // } else {
                                // eventBehavior.setMainInformation(noId+"");
                                // }
                                // // 事件行为核验结果
                                // eventBehavior.setCheckTime(new Date());
                                // if(json.getIntValue("vdsResult") == 0) {
                                // eventBehavior.setCheckStatus("1");
                                // eventBehavior.setCheckSuccessTime(new Date());
                                // } else {
                                // if(StringUtils.isEmpty(retVerifyBehavior)) {
                                // retVerifyBehavior = "事件行为核验失败";
                                // }
                                // eventBehavior.setCheckStatus("0");
                                // if(json.getIntValue("vdsResult") == 40002) {
                                // eventBehavior.setUnreason("验证签名失败");
                                // } else {
                                // eventBehavior.setUnreason("其他验证签名错误");
                                // }
                                // }
                                // eventBehavior.setVewestCheckTime(new Date());
                                // //        										eventBehavior.setCheckContent("签名原文完整、真实、是否被篡改");
                                // objs.add(eventBehavior);
                                // } else {
                                // retVerifyBehavior = "事件行为核验失败";
                                // }
                                // }
                                // if(jsonArraySignInfos.size() == 0) {
                                // //        									eventContent.setEventStatus(0);
                                // //        									if(StringUtils.isNotEmpty(eventContent.getFailureReason())) {
                                // //        										eventContent.setFailureReason(eventContent.getFailureReason() + ",pdf签章失败:返回集合为空。");
                                // //        									} else {
                                // //        										eventContent.setFailureReason("pdf签章失败:返回集合为空。");
                                // //        									}
                                // 
                                // result.put("status", 0);
                                // result.put("message", "pdf签章失败:返回集合为空。");
                                // return result;
                                // }
                                // // 整合错误信息
                                // //       	if(StringUtils.isNotEmpty(eventContent.getFailureReason())) {
                                // //          	eventContent.setFailureReason(eventContent.getFailureReason());
                                // //       	}
                                // if(StringUtils.isNotEmpty(retVerifyTi)) {
                                // if(StringUtils.isNotEmpty(eventContent.getFailureReason()))
                                // eventContent.setFailureReason(eventContent.getFailureReason() + "," + retVerifyTi);
                                // else
                                // eventContent.setFailureReason(retVerifyTi);
                                // }
                                // if(StringUtils.isNotEmpty(retVerifyBehavior)) {
                                // if(StringUtils.isNotEmpty(eventContent.getFailureReason()))
                                // eventContent.setFailureReason(retVerifyBehavior);
                                // else
                                // eventContent.setFailureReason(eventContent.getFailureReason() + "," + retVerifyBehavior);
                                // }
                                // if(StringUtils.isNotEmpty(retVerifyTime)) {
                                // if(StringUtils.isNotEmpty(eventContent.getFailureReason()))
                                // eventContent.setFailureReason(retVerifyTime);
                                // else
                                // eventContent.setFailureReason(eventContent.getFailureReason() + "," + retVerifyTime);
                                // }
                                // if(eventContent.getEventStatus() == 0) {
                                // if(StringUtils.isNotEmpty(basicInformation.getFailureReason())) {
                                // basicInformation.setFailureReason(basicInformation.getFailureReason() + "," + eventContent.getFailureReason());
                                // } else {
                                // basicInformation.setEvidenceStatus(0);
                                // basicInformation.setFailureReason(eventContent.getFailureReason());
                                // }
                                // result.put("status", 0);
                                // result.put("message", eventContent.getFailureReason());
                                // return result;
                                // }
                                // }
                                } else {
                                    objs.add(eventContent);
                                    for (EvidenceTrustedIdentity identity : tiCacheList) {
                                        objs.add(identity);
                                    }
                                }
                                saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("e_factor"));
                            }
                        /**
                         ***********************************************     《电子合同PDF》 获取事件内容    end      *******************************************
                         */
                        }
                        break;
                    default:
                        break;
                }
            }
            JSONArray jsonContentArray = jsonAuthEvent.getJSONArray("event");
            for (int i = 0; i < jsonContentArray.size(); i++) {
                // 得到对应的主体信息
                JSONObject jsonContent = jsonContentArray.getJSONObject(i);
                JSONObject jsonIdIdentify = jsonContent.getJSONObject("principalId");
                // 判断主体是否存在
                String idCacheKey = jsonIdIdentify.getString("name") + jsonIdIdentify.getString("dataId");
                EvidenceMainInformation mainInformation = null;
                if (cacheMainMap.get(idCacheKey) == null || "".equals(cacheMainMap.get(idCacheKey))) {
                    EvidenceMainInformationExample mainInformationExample = new EvidenceMainInformationExample();
                    EvidenceMainInformationExample.Criteria mainExampleCriteria = mainInformationExample.createCriteria();
                    mainExampleCriteria.andSubjectNameEqualTo(jsonIdIdentify.getString("name"));
                    mainExampleCriteria.andIdentificationEqualTo(jsonIdIdentify.getString("dataId"));
                    List<EvidenceMainInformation> mainInformationList = sqlSession.selectList("com.itrus.portal.db.EvidenceMainInformationMapper.selectByExample", mainInformationExample);
                    if (!mainInformationList.isEmpty()) {
                        mainInformation = mainInformationList.get(0);
                        cacheMainMap.put(mainInformation.getSubjectName() + mainInformation.getIdentification(), mainInformation);
                    }
                } else {
                    mainInformation = cacheMainMap.get(idCacheKey);
                }
                if (mainInformation == null || "".equals(mainInformation)) {
                    result.put("status", 0);
                    result.put("message", "判断主体为空");
                    return result;
                }
                // 得到证据包中的事件数据
                for (int j = 0; j < jsonEvArray.size(); j++) {
                    JSONObject object = jsonEvArray.getJSONObject(j);
                    switch(j) {
                        // 事件意愿认证
                        case 2:
                            // <---------------------   提交证书授权    start  ------------------------->
                            JSONObject jsonWillCert = jsonContent.getJSONObject("authEventWillCert");
                            JSONObject jsonWillSms = jsonContent.getJSONObject("authEventWillSms");
                            if (jsonWillSms != null && jsonWillCert != null) {
                                result.put("status", 0);
                                result.put("message", "提交的参数信息错误,证据及短信授权信息只能填写其一");
                                return result;
                            }
                            if (jsonWillCert != null) {
                                // 判断是否接收
                                if (object.getJSONObject("e_isReception").getBooleanValue("e_isReception_1")) {
                                    EvidenceEventDesire eventDesire = new EvidenceEventDesire();
                                    if (object.getBooleanValue("e_isRequired") && (StringUtils.isEmpty(jsonWillCert.getString("certBase64")) || StringUtils.isEmpty(jsonWillCert.getString("challengeCode")) || StringUtils.isEmpty(jsonWillCert.getString("answerCode")) || StringUtils.isEmpty(jsonWillCert.getString("verifyTime")) || StringUtils.isEmpty(jsonWillCert.getString("authenticatorThenType")))) {
                                        result.put("status", 0);
                                        result.put("message", "提交的参数信息不完整,缺少事件意愿认证参数值");
                                        return result;
                                    }
                                    // 验证证书
                                    String urlCertVerify = realNameAuthentication.getRealNameddress() + CERT_VERIFY;
                                    Map<String, Object> mapCertVerify = new HashMap<String, Object>();
                                    mapCertVerify.put("cert", jsonWillCert.getString("certBase64"));
                                    mapCertVerify.put("verifyFlag", "7");
                                    String rep_cert_verify = HttpClientUtil.postForm(urlCertVerify, AuthService.getHeader(), mapCertVerify);
                                    JSONObject jsonCertVerify = JSONObject.parseObject(rep_cert_verify);
                                    if (StringUtils.isNotEmpty(rep_cert_verify) && jsonCertVerify.getIntValue("code") == 0) {
                                        // 解析证书Base64
                                        UserCert userCert = CertUtil.getCertFromBase64(jsonWillCert.getString("certBase64"));
                                        eventDesire.setCertSerialnumber(userCert.getCertSn());
                                        eventDesire.setSubjectdn(userCert.getCertDn());
                                        eventDesire.setIssuerdn(userCert.getIssuerDn());
                                        if (userCert.getCertBuf() != null) {
                                            eventDesire.setEvidenceBuf(userCert.getCertBuf().toString());
                                        }
                                        eventDesire.setStartTime(userCert.getCertStartTime());
                                        eventDesire.setEndTime(userCert.getCertEndTime());
                                    } else {
                                        result.put("status", 0);
                                        result.put("message", "验证证书失败");
                                        return result;
                                    }
                                    eventDesire.setChallengeCode(jsonWillCert.getString("challengeCode"));
                                    eventDesire.setAnswerCode(jsonWillCert.getString("answerCode"));
                                    eventDesire.setClientDevice(jsonWillCert.getString("clientFacility"));
                                    eventDesire.setVerificationTime(jsonWillCert.getDate("verifyTime"));
                                    eventDesire.setWaysExpression("1");
                                    String eventVerifier = getAuthenticator(Integer.parseInt(jsonWillCert.getString("authenticatorThenType")), basicInformation.getEventPlatformName());
                                    eventDesire.setMainInformation(mainInformation.getSubjectName() + ";" + mainInformation.getIdentification());
                                    eventDesire.setEventContente(eventContent.getIdCode());
                                    eventDesire.setCreateTime(new Date());
                                    eventDesire.setEventVerifierType(jsonWillCert.getString("authenticatorThenType"));
                                    eventDesire.setEventVerifier(eventVerifier);
                                    objs.add(eventDesire);
                                    saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("e_factor"));
                                }
                            }
                            // <---------------------   提交短信授权    start  ------------------------->
                            if (jsonWillSms != null) {
                                // 判断是否接收
                                if (object.getJSONObject("e_isReception").getBooleanValue("e_isReception_2")) {
                                    EvidenceEventDesire eventDesire = new EvidenceEventDesire();
                                    if (object.getBooleanValue("e_isRequired") && (StringUtils.isEmpty(jsonWillSms.getString("phone")) || StringUtils.isEmpty(jsonWillSms.getString("sendTime")) || StringUtils.isEmpty(jsonWillSms.getString("smsContent")) || StringUtils.isEmpty(jsonWillSms.getString("verifyCode")) || StringUtils.isEmpty(jsonWillSms.getString("verifyTime")) || StringUtils.isEmpty(jsonWillSms.getString("authenticatorThenType")))) {
                                        result.put("status", 0);
                                        result.put("message", "提交的参数信息不完整,缺少事件意愿认证参数值");
                                        return result;
                                    }
                                    eventDesire.setPhone(jsonWillSms.getString("phone"));
                                    eventDesire.setSmsContent(jsonWillSms.getString("smsContent"));
                                    eventDesire.setVerificationCode(jsonWillSms.getString("verifyCode"));
                                    eventDesire.setSendOutTime(jsonWillSms.getDate("sendTime"));
                                    eventDesire.setVerificationTime(jsonWillSms.getDate("verifyTime"));
                                    eventDesire.setWaysExpression("2");
                                    String eventVerifier = getAuthenticator(Integer.parseInt(jsonWillSms.getString("authenticatorThenType")), basicInformation.getEventPlatformName());
                                    eventDesire.setMainInformation(mainInformation.getSubjectName() + ";" + mainInformation.getIdentification());
                                    eventDesire.setEventContente(eventContent.getIdCode());
                                    eventDesire.setCreateTime(new Date());
                                    eventDesire.setEventVerifierType(jsonWillSms.getString("authenticatorThenType"));
                                    eventDesire.setEventVerifier(eventVerifier);
                                    objs.add(eventDesire);
                                    saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("e_factor"));
                                }
                            }
                            break;
                        // 事件地点认证
                        case 4:
                            // 判断是否接收
                            if (object.getBooleanValue("e_isReception")) {
                                JSONObject jsonAddress = jsonContent.getJSONObject("netAddress");
                                if (jsonAddress != null && !(jsonAddress.getString("appUid") == null && jsonAddress.getString("timeReg") == null && jsonAddress.getString("ipAddressReg") == null && jsonAddress.getString("ipAddressSign") == null)) {
                                    // 定义事件网络地址对象
                                    EvidenceEventNetworkAddress eventNetworkAddress = new EvidenceEventNetworkAddress();
                                    // 整合数据 存储
                                    eventNetworkAddress.setEventContent(eventContent.getIdCode());
                                    eventNetworkAddress.setMainInformation(mainInformation.getSubjectName() + ";" + mainInformation.getIdentification());
                                    eventNetworkAddress.setCreateTime(new Date());
                                    eventNetworkAddress.setAccountNumber(jsonAddress.getString("appUid"));
                                    eventNetworkAddress.setIpAddress(jsonAddress.getString("ipAddressReg"));
                                    eventNetworkAddress.setSigninTime(jsonAddress.getDate("timeReg"));
                                    eventNetworkAddress.setSigninNumber(jsonAddress.getString("appUid"));
                                    eventNetworkAddress.setSigninipAddress(jsonAddress.getString("ipAddressReg"));
                                    eventNetworkAddress.setSendOutTime(jsonAddress.getDate("timeReg"));
                                    objs.add(eventNetworkAddress);
                                }
                                saveFactor = EvidenceSaveServiceApi.mergeFactor(saveFactor, object.getString("e_factor"));
                            }
                            break;
                    }
                }
            }
        }
        log.error("saveFactor content is [" + saveFactor + "]");
        result.put("saveFactor", saveFactor);
        result.put("basicInformation", basicInformation);
        result.put("objs", objs);
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        StackTraceElement stackTraceElement = e.getStackTrace()[e.getStackTrace().length - 5];
        String info = stackTraceElement.getClassName() + stackTraceElement.getLineNumber() + e.toString();
        LogUtil.evidencelog(sqlSession, evidenceSn, "存证接口", "存证失败,证据编号:" + evidenceSn + ", 失败原因:" + info);
        result.put("status", -5);
        result.put("message", "系统服务错误,请联系管理员");
        return result;
    }
}
Also used : EvidenceIndividual(com.itrus.portal.db.EvidenceIndividual) EvidenceSubjectIdentityExample(com.itrus.portal.db.EvidenceSubjectIdentityExample) EvidenceBasicInformation(com.itrus.portal.db.EvidenceBasicInformation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PersonalNameExample(com.itrus.portal.db.PersonalNameExample) ArrayList(java.util.ArrayList) EvidenceMainInformation(com.itrus.portal.db.EvidenceMainInformation) EvidenceRealName(com.itrus.portal.db.EvidenceRealName) EvidenceTheAgent(com.itrus.portal.db.EvidenceTheAgent) PersonalName(com.itrus.portal.db.PersonalName) EvidenceEventDesire(com.itrus.portal.db.EvidenceEventDesire) EvidenceCompaniesSubmit(com.itrus.portal.db.EvidenceCompaniesSubmit) EvidenceEventContent(com.itrus.portal.db.EvidenceEventContent) UserCert(com.itrus.portal.db.UserCert) EvidenceDesireIdentify(com.itrus.portal.db.EvidenceDesireIdentify) JSONArray(com.alibaba.fastjson.JSONArray) EvidenceSubjectIdentity(com.itrus.portal.db.EvidenceSubjectIdentity) RealNameRecord(com.itrus.portal.db.RealNameRecord) Date(java.util.Date) JSONObject(com.alibaba.fastjson.JSONObject) EvidenceTrustedIdentity(com.itrus.portal.db.EvidenceTrustedIdentity) JSONObject(com.alibaba.fastjson.JSONObject) EvidenceMainInformationExample(com.itrus.portal.db.EvidenceMainInformationExample) RealNameRecordExample(com.itrus.portal.db.RealNameRecordExample) EvidenceRepresentative(com.itrus.portal.db.EvidenceRepresentative) File(java.io.File) EvidenceEventNetworkAddress(com.itrus.portal.db.EvidenceEventNetworkAddress)

Example 25 with UserCert

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

the class EvidenceSaveServiceApi method verifySign.

private List<String> verifySign(Map<String, Object> result, ApplicationInfo applicationInfo, EvidenceSaveService evidenceSaveService, String hashvalue, String signedBase64, RealNameAuthentication realNameAuthentication) throws Exception {
    // 得到证据申请对象认证要素配置
    String factorCertSave = evidenceSaveService.getFactorCertSave();
    JSONObject jsonCs = JSONArray.parseArray(factorCertSave).getJSONObject(0);
    List<String> certs = null;
    // 判断是否需要验证委托人的P7签名
    if (jsonCs.getBooleanValue("c_isVerify")) {
        certs = new ArrayList<>();
        /**
         ***********************************************     《p7验签》   start   *******************************************
         */
        // 验证委托人的P7签名 整合参数
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("contentType", "CT_HASH");
        param.put("signedData", signedBase64);
        param.put("content", hashvalue);
        // 整合url
        String url = realNameAuthentication.getRealNameddress() + SIGNATURE_VERIFY_P7;
        result.put("dateVp", new Date());
        // 验签得到第三方返回结果
        String rep_verify_p7 = OkHttpClientManager.post(url, AuthService.getHeader().get("Authorization").toString(), param);
        JSONObject jsonVerifyP7 = JSONObject.parseObject(rep_verify_p7);
        // 判断验签是否成功 // TODO: 2018/3/13
        if (jsonVerifyP7.getIntValue("code") != 0) {
            result.put("status", -8);
            result.put("message", "验证证书失败");
            LogUtil.evidencelog(sqlSession, null, "存证_p7验签接口", "p7验签失败,失败原因:" + jsonVerifyP7.getString("message"));
            return null;
        }
        // 得到证书集合
        if (jsonVerifyP7.get("signerCerts") != null) {
            certs = (List<String>) jsonVerifyP7.get("signerCerts");
        }
        // 核验证书并保存
        for (String cert : certs) {
            // 解析证书Base64
            UserCert userCert = CertUtil.getCertFromBase64(cert);
            if (userCert.getCertEndTime() != null && userCert.getCertEndTime().getTime() < System.currentTimeMillis()) {
                result.put("status", -8);
                result.put("message", "证书已过期");
                return null;
            }
            // 得到应用证书
            String certBase64 = CacheCustomer.getAPP_GET_CERT_MAP().get(applicationInfo.getId());
            if (StringUtils.isEmpty(certBase64)) {
                certBase64 = applicationInfoService.getCert(applicationInfo.getId());
            }
            // 验证证书,比对应用配置的证书
            if (!cert.equals(certBase64)) {
                result.put("status", -8);
                result.put("message", "验证证书失败");
                return null;
            }
            result.put("dateVc", new Date());
        }
    /**
     ***********************************************     《p7验签》   end   *******************************************
     */
    }
    return certs;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) Date(java.util.Date) UserCert(com.itrus.portal.db.UserCert)

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