Search in sources :

Example 1 with RaInfo

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

the class GetRaInfoTask method insertRaInfosIntoDB.

// 将多条数据插入到数据库中
private void insertRaInfosIntoDB(List<Map<String, Object>> list) {
    List<RaInfo> raInfos = new ArrayList<RaInfo>();
    // 将相应信息插入到数据库中,最后一条状态信息不插入
    for (int i = 0; i < list.size() - 1; i++) {
        Map<String, Object> remap = list.get(i);
        RaInfo raInfo = new RaInfo();
        raInfo.setId(null);
        raInfo.setCreateTime(new Date());
        // raInfo.setCreateTime(new Date());
        // 设置同步标识:0标识非同步来的数据,1标识同步来的数据
        raInfo.setSynchronization(1);
        raInfo.setCertId(Integer.parseInt((String) remap.get("CERT_ID")));
        raInfo.setCertNotbefore((String) remap.get("CERT_NOTBEFORE"));
        raInfo.setCertSerialnumber((String) remap.get("CERT_SERIALNUMBER"));
        raInfo.setCertStatus((String) remap.get("CERT_STATUS"));
        raInfo.setCertNotafter((String) remap.get("CERT_NOTAFTER"));
        raInfo.setAccountHash((String) remap.get("ACCOUNT_HASH"));
        if (null == raInfo.getAccountHash()) {
            if (0 != successNum.intValue())
                successNum.decrementAndGet();
            continue;
        }
        raInfos.add(raInfo);
    }
    sqlSession.insert("com.itrus.portal.db.RaInfoMapper.insertList", raInfos);
    successNum.addAndGet(raInfos.size());
// System.out.println("插入:"+successNum+"条");
}
Also used : ArrayList(java.util.ArrayList) RaInfo(com.itrus.portal.db.RaInfo) Date(java.util.Date)

Example 2 with RaInfo

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

the class GetRaInfoTask method insertOneRaInfoIntoDB.

// 将单条数据插入到数据库中
private RaInfo insertOneRaInfoIntoDB(Map<String, Object> remap, RaInfo raInfo) {
    raInfo = new RaInfo();
    raInfo.setId(null);
    raInfo.setCreateTime(new Date());
    raInfo.setCertId(Integer.parseInt((String) remap.get("CERT_ID")));
    // 设置同步标识:0标识非同步来的数据,1标识同步来的数据
    raInfo.setSynchronization(0);
    raInfo.setCertNotbefore((String) remap.get("CERT_NOTBEFORE"));
    raInfo.setCertSerialnumber((String) remap.get("CERT_SERIALNUMBER"));
    raInfo.setCertStatus((String) remap.get("CERT_STATUS"));
    raInfo.setCertNotafter((String) remap.get("CERT_NOTAFTER"));
    raInfo.setAccountHash((String) remap.get("ACCOUNT_HASH"));
    sqlSession.insert("com.itrus.portal.db.RaInfoMapper.insertone", raInfo);
    // System.out.println("****:"+jsonTool.writeValueAsString(raInfo));
    return raInfo;
}
Also used : RaInfo(com.itrus.portal.db.RaInfo) Date(java.util.Date)

Example 3 with RaInfo

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

the class GetRaInfoTask method getRaInfoByCertSerialNumber.

/**
 * 根据证书序列号,从本地数据库或者远程数据库获取证书对应的RA信息
 *
 * @param CertSerialNumber
 *            :证书序列号
 * @return
 * @throws UserInfoServiceException
 */
public String getRaInfoByCertSerialNumber(String CertSerialNumber) throws UserInfoServiceException {
    // 从本地数据库中查询是否存在该证书对应的ra哈希值
    RaInfoExample raInfoExample = new RaInfoExample();
    RaInfoExample.Criteria criteria = raInfoExample.or();
    criteria.andCertSerialnumberEqualTo(CertSerialNumber);
    RaInfo raInfo = sqlSession.selectOne("com.itrus.portal.db.RaInfoMapper.selectByExample", raInfoExample);
    Map<String, Object> retmMap = new HashMap<String, Object>();
    if (null != raInfo && !raInfo.getAccountHash().equals("")) {
        return raInfo.getAccountHash();
    } else {
        // 判断系统是否配置了RA信息同步地址
        SysConfig sysConfig = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoUrl");
        if (null == sysConfig) {
            throw new UserInfoServiceException("未配置RA信息同步地址");
        }
        // http://localhost:8080/raInfo/getRa.jsp
        String url = sysConfig.getConfig() + "/getRa.jsp";
        // 从远程数据库中获取证书对应的RA哈希值
        LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
        map.add("certSn", CertSerialNumber);
        try {
            String resStr = restTemplate.postForObject(url, map, String.class);
            Map<String, Object> remap = jsonTool.readValue(resStr, Map.class);
            Integer status = (Integer) remap.get("status");
            if (0 == status) {
                String type = "查询证书RA信息出错";
                String info = "查询出现错误的证书序列号:" + CertSerialNumber + ",错误信息:" + (String) remap.get("message");
                LogUtil.syslog(sqlSession, type, info);
                throw new UserInfoServiceException("查询RA信息出错,请联系管理员");
            } else {
                raInfo = insertOneRaInfoIntoDB(remap, raInfo);
                retmMap.put("accountHash", raInfo.getAccountHash());
                String type = "查询证书归属的RA信息成功";
                String info = "查询证书:" + CertSerialNumber + "的RA信息成功,归属RA:" + raInfo.getAccountHash();
                LogUtil.syslog(sqlSession, type, info);
                return raInfo.getAccountHash();
            }
        } catch (Exception e) {
            e.printStackTrace();
            String type = "查询证书RA信息出错";
            String info = "查询出现错误的证书序列号:" + CertSerialNumber + ",错误信息:" + e.getMessage();
            LogUtil.syslog(sqlSession, type, info);
            throw new UserInfoServiceException("查询证书RA信息出错,请联系管理员");
        }
    }
}
Also used : SysConfig(com.itrus.portal.db.SysConfig) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) UnknownHostException(java.net.UnknownHostException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RaInfo(com.itrus.portal.db.RaInfo) RaInfoExample(com.itrus.portal.db.RaInfoExample)

Aggregations

RaInfo (com.itrus.portal.db.RaInfo)3 Date (java.util.Date)2 RaInfoExample (com.itrus.portal.db.RaInfoExample)1 SysConfig (com.itrus.portal.db.SysConfig)1 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1