use of com.itrus.portal.db.RaInfoExample 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信息出错,请联系管理员");
}
}
}
Aggregations