use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class BasicInformationController method alertpdf.
/**
* 下载回执报告的错误信息
*
* @param evidenceSn
* @param uiModel
* @return
* @throws Exception
*/
@RequestMapping(value = "/{evidenceSn}", method = RequestMethod.POST, produces = "text/html")
@ResponseBody
public String alertpdf(@PathVariable("evidenceSn") String evidenceSn, Model uiModel) throws Exception {
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
}
try {
if (realNameAuthentication == null) {
String oper = "下载回执报告失败";
String info = "失败原因:服务器出错,请联系管理员";
LogUtil.evidencelog(sqlSession, null, oper, info);
return "服务器出错,请联系管理员";
}
// 得到接口路径
String urlAgent = realNameAuthentication.getRealNameddress();
EvidenceEnclosureExample enclo = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria enclosureEx = enclo.createCriteria();
enclosureEx.andEvidenceSnEqualTo(evidenceSn);
enclosureEx.andPdfTypeEqualTo("3");
EvidenceEnclosure enclosure = sqlSession.selectOne("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclo);
if (enclosure == null) {
return "未找到该证据编号的信息";
}
String base64 = EvidenceSaveServiceApi.decryptedAndDownload(sqlSession, enclosure.getBuid(), urlAgent);
if (base64 == null || base64.contains("exception")) {
String oper = "下载回执报告失败";
String info = "失败原因:base64为空";
LogUtil.evidencelog(sqlSession, null, oper, info);
return "base64为空";
}
} catch (Exception e) {
// TODO Auto-generated catch
e.printStackTrace();
String oper = "下载回执报告失败";
String info = "失败原因:" + e.getMessage();
LogUtil.evidencelog(sqlSession, null, oper, info);
}
return "0";
}
use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class CertificateServiceImpl method genCsr.
/**
* 产生CSR
* @param alias
* @param hashAlg
* @param subject
* @return
*/
public String genCsr(String alias, String hashAlg, String subject) {
String csr = null;
// 验证参数完整
if (StringUtils.isEmpty(alias)) {
return null;
}
JSONObject ret_data = null;
try {
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
}
if (realNameAuthentication == null) {
return null;
}
String urlAgent = realNameAuthentication.getRealNameddress() + KEY_GENCSR;
Map<String, Object> paramsAgent = new HashMap<String, Object>();
paramsAgent.put("alias", alias);
if (StringUtils.isNotEmpty(hashAlg) && !"0".equals(hashAlg)) {
paramsAgent.put("hashAlg", hashAlg);
}
if (StringUtils.isNotEmpty(subject)) {
paramsAgent.put("subject", subject);
}
String repAgent = HttpClientUtil.postForm(urlAgent, AuthService.getHeader(), paramsAgent);
log.error("****repAgent***" + repAgent);
ret_data = JSONObject.parseObject(repAgent);
if (ret_data.getIntValue("code") != 0) {
String oper = "产生CSR失败";
String info = "错误原因:" + ret_data.getString("message");
LogUtil.evidencelog(sqlSession, null, oper, info);
return null;
} else {
csr = ret_data.getString("csr");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
String oper = "产生CSR失败";
String info = "错误原因:" + e.getMessage();
LogUtil.evidencelog(sqlSession, null, oper, info);
}
return csr;
}
use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class EvidenceQueryQueue method run.
@Override
public void run() {
// 回调
while (true) {
if (OBJECT_QUEUE.isEmpty()) {
try {
// 若队列中没有信息则等待10秒
sleep(5 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
continue;
}
String url = null;
String app_id = null;
String secret_key = null;
// 需要回执报告 // TODO: 2018/3/15 有问题
Map<Long, EvidenceBasicInformation> dataRet = new HashMap<Long, EvidenceBasicInformation>();
// 不需要回执报告
Map<Long, List<String>> data = new HashMap<Long, List<String>>();
for (int i = 0; OBJECT_QUEUE != null && i < OBJECT_QUEUE.size() && i < 1000; i++) {
EvidenceBasicInformation obj = (EvidenceBasicInformation) OBJECT_QUEUE.poll();
if (obj.getOutAppService() == null || obj.getEvidenceType() == 1) {
if (data.containsKey(obj.getApplicationInfo())) {
data.get(obj.getApplicationInfo()).add(obj.getEvidenceSn());
} else {
List<String> sns = new ArrayList<String>();
sns.add(obj.getEvidenceSn());
data.put(obj.getApplicationInfo(), sns);
}
} else {
dataRet.put(obj.getApplicationInfo(), obj);
}
}
try {
// <---------------------------- 处理data start ------------------------------>
for (Map.Entry<Long, List<String>> entry : data.entrySet()) {
ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
if (applicationInfo == null) {
// TODO: 2018/3/15 从缓存取
applicationInfo = infoService.selectById(entry.getKey());
}
// 得到配置信息
if (applicationInfo.getAppId() != app_id || url == null || app_id == null || secret_key == null) {
if (StringUtils.isEmpty(applicationInfo.getCallback()) || StringUtils.isEmpty(applicationInfo.getAppId()) || StringUtils.isEmpty(applicationInfo.getSecretKey())) {
log.error("回调失败:缺少配置。");
return;
}
if (url == null) {
url = applicationInfo.getCallback().trim();
}
if (app_id == null) {
app_id = applicationInfo.getAppId();
}
if (secret_key == null) {
secret_key = applicationInfo.getSecretKey();
}
log.error("EvidenceQueryQueue : URL=" + url + ",APP_ID=" + app_id + ",SECRET_KEY=" + secret_key);
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(app_id) || StringUtils.isEmpty(secret_key)) {
log.error("回调失败:缺少配置。");
return;
}
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("status", 1);
param.put("message", "存证成功");
param.put("appId", app_id);
param.put("evidenceSns", JSONObject.toJSONString(entry.getValue()));
String header = "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(app_id + entry.getValue(), secret_key), false);
String retStr = OkHttpClientManagerCallback.post(url, header, param);
JSONObject ret_data = JSONObject.parseObject(retStr);
final List<String> dataSn = entry.getValue();
final Long appId = entry.getKey();
// 判断是否成功 true ——> 失败
if (retStr == null || ret_data.getInteger("status") != 1) {
log.error("EvidenceQueryQueue failure count [" + entry.getValue().size() + "]");
// 创建新线程 处理数据批量添加
List<String> sns = dataSn;
Long aId = appId;
List<EvidenceCallback> callbacks = new ArrayList<EvidenceCallback>();
;
for (String sn : sns) {
EvidenceCallback evidenceCallback = new EvidenceCallback();
evidenceCallback.setAppId(aId);
evidenceCallback.setCounnt(1);
evidenceCallback.setEvidenceSn(sn);
callbacks.add(evidenceCallback);
}
sqlSession.insert("com.itrus.portal.db.EvidenceCallbackMapper.insert", callbacks.toArray());
} else {
log.error("EvidenceQueryQueue success count [" + entry.getValue().size() + "]");
// 创建新线程 处理数据批量修改
List<String> sns = dataSn;
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", sns.toArray());
}
}
// <---------------------------- 处理dataRet start ------------------------------>
for (Entry<Long, EvidenceBasicInformation> entry : dataRet.entrySet()) {
ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
if (applicationInfo == null) {
// TODO: 2018/3/15 从缓存取
applicationInfo = infoService.selectById(entry.getKey());
}
if (applicationInfo.getAppId() != app_id || url == null || app_id == null || secret_key == null) {
if (StringUtils.isEmpty(applicationInfo.getCallback()) || StringUtils.isEmpty(applicationInfo.getAppId()) || StringUtils.isEmpty(applicationInfo.getSecretKey())) {
log.error("回调失败:缺少配置。");
return;
}
if (url == null) {
url = applicationInfo.getCallback().trim();
}
if (app_id == null) {
app_id = applicationInfo.getAppId();
}
if (secret_key == null) {
secret_key = applicationInfo.getSecretKey();
}
log.error("EvidenceQueryQueue : URL=" + url + ",APP_ID=" + app_id + ",SECRET_KEY=" + secret_key);
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(app_id) || StringUtils.isEmpty(secret_key)) {
log.error("回调失败:缺少配置。");
return;
}
}
// 得到证据回执base64
String reportBase64 = null;
// reportBase64 = EvidenceSaveServiceApi.cacheReportBySnMap.get(entry.getValue().getEvidenceSn());
if (StringUtils.isEmpty(reportBase64)) {
// 获取原子服务地址 1.实名认证 2.密码服务 3.时间戳
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
try {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
} catch (Exception e) {
e.printStackTrace();
}
}
// 获取回执报告附件表信息
EvidenceEnclosureExample enclosureExample = new EvidenceEnclosureExample();
EvidenceEnclosureExample.Criteria ec = enclosureExample.createCriteria();
ec.andEvidenceSnEqualTo(entry.getValue().getEvidenceSn());
ec.andPdfTypeEqualTo("3");
List<EvidenceEnclosure> enclosures = sqlSession.selectList("com.itrus.portal.db.EvidenceEnclosureMapper.selectByExample", enclosureExample);
if (enclosures != null && !enclosures.isEmpty()) {
EvidenceEnclosure enclosure = enclosures.get(0);
// 调解密下载接口从原子服务拿到回执报告base64
reportBase64 = EvidenceSaveServiceApi.decryptedAndDownload(sqlSession, enclosure.getBuid(), realNameAuthentication.getRealNameddress());
} else {
// 调用生成回执报告方法
Map<String, Object> mapRet = reportTemplate.returnreceipt(entry.getValue().getEvidenceSn(), applicationInfo, null);
log.error("EvidenceQueryQueue mapRet is " + mapRet.get("status"));
;
if (mapRet.get("status") != null && (int) mapRet.get("status") == 0) {
// 修改证据基本信息回执状态为已出
reportBase64 = (String) mapRet.get("pdfBase64");
EvidenceBasicInformation basicInformation = informationService.getInformationBySn(entry.getValue().getEvidenceSn(), null);
basicInformation.setReceiptStatus(1);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
}
}
} else {
// EvidenceSaveServiceApi.cacheReportBySnMap.remove(entry.getValue().getEvidenceSn());
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("status", 1);
param.put("appId", app_id);
param.put("evidenceSn", entry.getValue().getEvidenceSn());
log.error("EvidenceQueryQueue reportBase64 is " + (reportBase64 == null) + ", evidenceSn is " + entry.getValue().getEvidenceSn());
if (reportBase64 == null) {
param.put("message", "存证成功,回执报告生成失败!");
} else {
param.put("message", "存证成功");
param.put("reportBase64", reportBase64);
}
String header = "HMAC-SHA1 " + Base64.encode(HMACSHA1.getHmacSHA1(app_id + entry.getValue().getEvidenceSn(), secret_key), false);
String retStr = OkHttpClientManagerCallback.post(url, header, param);
JSONObject ret_data = JSONObject.parseObject(retStr);
String dataSn = entry.getValue().getEvidenceSn();
Long appId = entry.getKey();
// 判断是否成功 true ——> 失败
if (retStr == null || ret_data.getInteger("status") != 1) {
log.error("EvidenceQueryQueue failure sn is [" + entry.getValue().getEvidenceSn() + "]" + "retStr is [" + retStr + "]");
EvidenceCallback evidenceCallback = new EvidenceCallback();
evidenceCallback.setAppId(appId);
evidenceCallback.setCounnt(1);
evidenceCallback.setEvidenceSn(dataSn);
evidenceCallback.setAppServiceId(entry.getValue().getOutAppService());
sqlSession.insert("com.itrus.portal.db.EvidenceCallbackMapper.insert", evidenceCallback);
} else {
log.error("EvidenceQueryQueue success sn is [" + entry.getValue().getEvidenceSn() + "]" + "retStr is [" + retStr + "]");
List<String> sns = new ArrayList<>();
sns.add(dataSn);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", sns.toArray());
}
}
// <---------------------------- 处理dataRet end ------------------------------>
} catch (Exception e) {
e.printStackTrace();
LogUtil.evidencelog(sqlSession, null, "存证回调接口", "失败原因:" + e.toString());
}
}
}
use of com.itrus.portal.db.RealNameAuthentication 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;
}
use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class AuthService method getToken.
// @Autowired
// private static RealNameAuthenticationSerivceImpl authenticationSerivceImpl = new RealNameAuthenticationSerivceImpl();
/**
* 获得token
* 访问其他接口的时候 在头信息增加 Authorization :bear+token bear和token之间加个空格
*/
private static String getToken() {
// client_secret:43b484748d3a936330bc50da70d6ce69e1dfef90
try {
// RealNameAuthentication realNameAuthentication = authenticationSerivceImpl.getRealNameAuthenticationExample(new RealNameAuthenticationExample());
Long nowDate = System.currentTimeMillis();
if (ACCESS_TOKEN != null && new Date(nowDate + inDateTime).before(inDate)) {
return ACCESS_TOKEN;
}
List<RealNameAuthentication> list = sqlSession.selectList("com.itrus.portal.db.RealNameAuthenticationMapper.selectByExample", new RealNameAuthenticationExample());
if (list == null || list.isEmpty()) {
return null;
}
RealNameAuthentication realNameAuthentication = null;
for (RealNameAuthentication nameAuthentication : list) {
if (nameAuthentication.getType() == 1)
realNameAuthentication = nameAuthentication;
}
if (realNameAuthentication == null) {
return null;
}
Map params = new HashMap();
params.put("grant_type", "client_credentials");
params.put("client_id", realNameAuthentication.getIdCode());
params.put("client_secret", realNameAuthentication.getKeyCode());
String rep = HttpClientUtil.postForm(realNameAuthentication.getAccessTokenaddress() + TOKEN, null, params);
JSONObject data = JSON.parseObject(rep);
ACCESS_TOKEN = data.getString("access_token");
inDate = new Date(nowDate + data.getInteger("expires_in") * 1000);
return ACCESS_TOKEN;
} catch (RestClientException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (JsonParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations