Search in sources :

Example 6 with EvidenceSecretKey

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) RealNameAuthentication(com.itrus.portal.db.RealNameAuthentication) EvidenceSecretKey(com.itrus.portal.db.EvidenceSecretKey) Date(java.util.Date) EvidenceSecretKeyExample(com.itrus.portal.db.EvidenceSecretKeyExample) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

EvidenceSecretKey (com.itrus.portal.db.EvidenceSecretKey)6 EvidenceCertificate (com.itrus.portal.db.EvidenceCertificate)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 JSONObject (com.alibaba.fastjson.JSONObject)3 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 RaAccount (com.itrus.portal.db.RaAccount)2 RealNameAuthentication (com.itrus.portal.db.RealNameAuthentication)2 File (java.io.File)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CertInfo (cn.topca.tca.ra.service.CertInfo)1 UserInfo (cn.topca.tca.ra.service.UserInfo)1 JSONArray (com.alibaba.fastjson.JSONArray)1 AppService (com.itrus.portal.db.AppService)1 EvidenceBasicInformation (com.itrus.portal.db.EvidenceBasicInformation)1 EvidenceCert (com.itrus.portal.db.EvidenceCert)1 EvidenceCertificateExample (com.itrus.portal.db.EvidenceCertificateExample)1