use of com.itrus.portal.db.EvidenceSecretKey in project portal by ixinportal.
the class SecretKeyServiceImpl method certufucateInterface.
/**
* 从接口得到所有密钥信息
* @param name
* @return
*/
public EvidenceSecretKey certufucateInterface(String name, String keyType) {
// 存储接口返回信息
JSONObject ret_data = null;
EvidenceSecretKey secrtkey = new EvidenceSecretKey();
List<EvidenceSecretKey> list = new ArrayList<EvidenceSecretKey>();
int count = 0;
// 解析密钥类型和长度
String keyage = keyType.substring(0, 3);
String keyLen = keyType.substring(3);
try {
// CacheCustomer.getAUTH_CONFIG_MAP().get(1);
RealNameAuthentication realNameAuthentication = null;
if (realNameAuthentication == null) {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
}
if (realNameAuthentication == null) {
return null;
}
String urlAgent = realNameAuthentication.getRealNameddress() + KEY_INTERFACE;
Map<String, Object> paramsAgent = new HashMap<String, Object>();
String repAgent = HttpClientUtil.postForm(urlAgent, AuthService.getHeader(), paramsAgent);
ret_data = JSONObject.parseObject(repAgent);
log.error("repAgent+" + repAgent);
log.error("ret_data=" + ret_data);
if (repAgent == null || ret_data.getInteger("code") != 0) {
String oper = "产生密钥失败";
String info = "错误原因:原子服务返回空值";
LogUtil.evidencelog(sqlSession, null, oper, info);
return null;
} else {
// 得到likes数组
JSONArray likes = ret_data.getJSONArray("keys");
log.error("likes=" + likes.toJSONString());
for (int i = 0; i < likes.size(); i++) {
if (keyage.equals(likes.getJSONObject(i).get("keyAlg").toString()) && keyLen.equals(likes.getJSONObject(i).get("keyLen").toString())) {
secrtkey.setKeyAlg(likes.getJSONObject(i).get("keyAlg").toString());
secrtkey.setPublicKeySha1hex(likes.getJSONObject(i).get("publicKeySha1Hex").toString());
secrtkey.setAlias(likes.getJSONObject(i).get("alias").toString());
secrtkey.setPublicKey(likes.getJSONObject(i).get("publicKey").toString());
secrtkey.setKeyLen(likes.getJSONObject(i).get("keyLen").toString());
secrtkey.setCreateTime(new Date());
secrtkey.setCreator(name);
EvidenceSecretKeyExample evidencesecrt = new EvidenceSecretKeyExample();
EvidenceSecretKeyExample.Criteria certificateex = evidencesecrt.createCriteria();
certificateex.andAliasEqualTo(likes.getJSONObject(i).get("alias").toString());
EvidenceSecretKey eviden = sqlSession.selectOne("com.itrus.portal.db.EvidenceSecretKeyMapper.selectByExample", evidencesecrt);
if (eviden == null) {
count++;
sqlSession.insert("com.itrus.portal.db.EvidenceSecretKeyMapper.insert", secrtkey);
String oper = "产生密钥成功";
String info = "密钥别名:" + secrtkey.getAlias();
LogUtil.evidencelog(sqlSession, null, oper, info);
return secrtkey;
}
/*else{
//count = sqlSession.update("com.itrus.portal.db.EvidenceSecretKeyMapper.updateByPrimaryKeySelective", secrtkey);
}*/
}
// list.add(secrtkey);
}
if (count == 0) {
String oper = "产生密钥失败";
String info = "错误原因:原子服务无可用密钥";
LogUtil.evidencelog(sqlSession, null, oper, info);
return null;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
String oper = "产生密钥失败";
String info = "错误原因:" + e.toString();
LogUtil.evidencelog(sqlSession, null, oper, info);
}
return secrtkey;
}
Aggregations