Search in sources :

Example 1 with EvidenceSecretKeyExample

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

the class SecretKeyServiceImpl method selecttype.

/**
 * 得到密钥
 * @param keyType
 * @return
 */
public List<EvidenceSecretKey> selecttype(String keyType) {
    String keyage = keyType.substring(0, 3);
    String keyLen = keyType.substring(3);
    EvidenceSecretKeyExample secrtkey = new EvidenceSecretKeyExample();
    EvidenceSecretKeyExample.Criteria sercretkeyexam = secrtkey.createCriteria();
    sercretkeyexam.andKeyAlgEqualTo(keyage);
    if (StringUtils.isNotEmpty(keyLen)) {
        sercretkeyexam.andKeyLenEqualTo(keyLen);
    }
    return sqlSession.selectList("com.itrus.portal.db.EvidenceSecretKeyMapper.selectByExample", secrtkey);
}
Also used : EvidenceSecretKeyExample(com.itrus.portal.db.EvidenceSecretKeyExample)

Example 2 with EvidenceSecretKeyExample

use of com.itrus.portal.db.EvidenceSecretKeyExample 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

EvidenceSecretKeyExample (com.itrus.portal.db.EvidenceSecretKeyExample)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 EvidenceSecretKey (com.itrus.portal.db.EvidenceSecretKey)1 RealNameAuthentication (com.itrus.portal.db.RealNameAuthentication)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1