use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class EvidenceSaveServiceApi method saveContract.
/**
* 存证接口 (合同原文)
* @param signature
* 签名值
* @param request
* @return
*/
@RequestMapping("/saveContract")
@ResponseBody
public Map<String, Object> saveContract(@RequestHeader("Content-Signature") String signature, @RequestParam(value = "appId", required = false) String appId, @RequestParam(value = "serviceCode", required = false) String serviceCode, @RequestParam(value = "evidenceSn", required = false) String evidenceSn, @RequestParam(value = "hashAlg", required = false) String hashAlg, @RequestParam(value = "signedBase64", required = false) String signedBase64, @RequestParam(value = "evidencePackage", required = false) String evidencePackage, HttpServletRequest request) {
// 返回值
Map<String, Object> result = new HashMap<String, Object>();
result.put("status", 1);
Long startTime = System.currentTimeMillis();
// 申请时间
Date date = new Date();
// 验证参数是否完整
if (StringUtils.isEmpty(signature) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(serviceCode) || StringUtils.isEmpty(evidencePackage) || StringUtils.isEmpty(hashAlg) || StringUtils.isEmpty(signedBase64)) {
result.put("status", 0);
result.put("message", "提交的参数信息不完整");
return result;
}
if (StringUtils.isNotEmpty(evidenceSn)) {
evidenceSn = null;
}
// 获取对应应用信息
ApplicationInfo applicationInfo = applicationInfoService.getApplicationInfo(appId);
if (applicationInfo == null) {
result.put("status", -11);
result.put("message", "应用标识不存在");
return result;
}
if (applicationInfo.getIsAppStatus() == 0) {
result.put("status", -12);
result.put("message", "应用状态已关闭");
return result;
}
// 核验ip限制
if (!applicationInfo.getAccessIp().contains(request.getRemoteAddr()) && "1".equals(applicationInfo.getIsIpStatus())) {
result.put("status", -1);
result.put("message", "没有此服务权限");
log.debug("EvidenceSaveSeriveceTest_AccsessIp : " + request.getRemoteAddr());
return result;
}
// 验证hmac有效性
try {
String macVal = Base64.encode(HMACSHA1.getHmacSHA1(appId + serviceCode + evidenceSn + hashAlg + signedBase64 + evidencePackage, applicationInfo.getSecretKey()), false);
if (!signature.equals("HMAC-SHA1 " + macVal)) {
result.put("status", -2);
result.put("message", "服务密钥错误");
return result;
}
} catch (Exception e) {
result.put("status", -3);
result.put("message", "Hmac验证错误");
e.printStackTrace();
return result;
}
// 获取对应应用信息
EvidenceSaveService evidenceSaveService = null;
AppService appService = appServiceExt.getAppService(serviceCode);
if (appService != null && "EvidenceSaveService".equals(appService.getServiceConfigName())) {
evidenceSaveService = saveServiceImpl.selectById(appService.getServiceConfigId());
} else {
result.put("status", -21);
result.put("message", "应用服务不存在");
return result;
}
if (evidenceSaveService == null) {
result.put("status", -21);
result.put("message", "应用服务不存在");
return result;
}
if (appService.getIsAppServiceStatus() == 0) {
result.put("status", -22);
result.put("message", "服务已关闭");
return result;
}
// 获取存证回执模版
if (evidenceSaveService.getAppServiceName() != null) {
AppService appServiceOut = appServiceExt.selectById(evidenceSaveService.getAppServiceName());
if (appServiceOut == null) {
result.put("status", -22);
result.put("message", "回执模版不存在");
return result;
}
}
if (StringUtils.isNotEmpty(evidenceSn)) {
EvidenceBasicInformation basicInformation = basicInformationService.getInformationBySn(evidenceSn, 1);
if (basicInformation != null) {
result.put("status", 0);
result.put("message", "该证据不可补交");
return result;
}
}
log.error("verifyConfig time is [" + (System.currentTimeMillis() - startTime) + "]");
RealNameAuthentication realNameAuthentication = null;
RealNameAuthentication realNameAuthenticationTime = null;
RealNameAuthentication realNameAuthenticationOss = null;
try {
Long getConfigTime = System.currentTimeMillis();
// 获取原子服务地址 1.实名认证 2.密码服务 3.时间戳 4.OSS
realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
}
if (realNameAuthentication == null) {
result.put("status", -6);
result.put("message", "缺少密码服务配置,请联系管理员");
return result;
}
// 获取原子服务地址 1.实名认证 2.密码服务 3.时间戳 4.OSS
realNameAuthenticationTime = CacheCustomer.getAUTH_CONFIG_MAP().get(3);
if (realNameAuthenticationTime == null) {
realNameAuthenticationTime = realNameAuthenticationSerivce.getRealNameAuthenticationByThree();
}
if (realNameAuthenticationTime == null) {
result.put("status", -6);
result.put("message", "缺少时间戳服务配置,请联系管理员");
return result;
}
// 获取原子服务地址 1.实名认证 2.密码服务 3.时间戳 4.OSS
realNameAuthenticationOss = CacheCustomer.getAUTH_CONFIG_MAP().get(4);
if (realNameAuthenticationOss == null) {
realNameAuthenticationOss = realNameAuthenticationSerivce.getRealNameAuthenticationByOss();
}
if (realNameAuthenticationOss == null) {
result.put("status", -6);
result.put("message", "缺少OSS配置,请联系管理员");
return result;
}
// 本次证据包大小
int fileSize = evidencePackage.getBytes("utf-8").length;
log.error("getConfig time is [" + (System.currentTimeMillis() - getConfigTime) + "]");
// 存证计费校验接口
Map<String, Object> mapCharging = storeChargingService.checkStoreCharging(StringUtils.isBlank(evidenceSn), applicationInfo, appService, evidenceSaveService.getBaseSpace(), getSize(fileSize));
if ((int) mapCharging.get("retCode") == 0) {
// result.put("status", -4);
if (mapCharging.get("retMsg") != null)
result.put("message", mapCharging.get("retMsg"));
else
result.put("message", "服务计费失败");
// return result;
}
// 证据包申请
String hashvalue = HMACSHA1.getDigest(hashAlg, evidencePackage);
// 1.验签之后返回
long verifySignTime = System.currentTimeMillis();
List<String> certs = verifySign(result, applicationInfo, evidenceSaveService, hashvalue, signedBase64, realNameAuthentication, 1);
log.error("verifySignTime time is [" + (System.currentTimeMillis() - verifySignTime) + "]");
Date dateVp = (Date) result.get("dateVp");
Date dateVc = (Date) result.get("dateVc");
result.remove("dateVp");
result.remove("dateVc");
if (null != certs) {
String genSn = null;
if (StringUtils.isEmpty(evidenceSn)) {
// 生成证据编码
genSn = UniqueIDUtils.genAppServiceUID(applicationInfo, appService.getAppServiceName(), sqlSession, 3);
}
// 存证处理核心方法
long saveBodyTime = System.currentTimeMillis();
result = saveContractService.saveBody(result, applicationInfo, appService, evidenceSaveService, date, evidenceSn, genSn, signedBase64, evidencePackage, hashAlg, hashvalue, dateVp, dateVc, certs, realNameAuthentication, realNameAuthenticationTime, realNameAuthenticationOss, mapCharging);
log.error("saveBodyTime time is [" + (System.currentTimeMillis() - saveBodyTime) + "]");
if ((int) result.get("status") == 1) {
result.put("message", "申请存证成功,请稍后通过查询存证接口查看存证结果!");
if (StringUtils.isNotEmpty(evidenceSn))
result.put("evidenceSn", evidenceSn);
else
result.put("evidenceSn", genSn);
}
} else {
result.put("status", -8);
result.put("message", "验证证书失败");
}
log.error("saveContract time is " + (System.currentTimeMillis() - startTime));
return result;
} catch (Exception e) {
e.printStackTrace();
if (e instanceof IllegalStateException) {
result.put("status", -100);
result.put("message", "当前系统忙,请稍后再尝试!");
return result;
}
StackTraceElement stackTraceElement = e.getStackTrace()[e.getStackTrace().length - 2];
String info = stackTraceElement.getClassName() + stackTraceElement.getLineNumber() + e.toString();
LogUtil.evidencelog(sqlSession, null, "存证接口", "申请存证失败,失败原因:" + info);
result = new HashMap<String, Object>();
result.put("status", -5);
result.put("message", "系统服务错误,请联系管理员");
return result;
} finally {
if (realNameAuthentication != null) {
realNameAuthentication = null;
}
if (realNameAuthenticationOss != null) {
realNameAuthenticationOss = null;
}
if (realNameAuthenticationTime != null) {
realNameAuthenticationTime = null;
}
}
}
use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class EvidenceCallbackTask method init.
public void init() {
try {
EvidenceCallbackExample callbackExample = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria = callbackExample.createCriteria();
criteria.andCounntLessThan(3);
List<EvidenceCallback> callbacks = callbackService.selectAll(callbackExample);
if (callbacks == null || callbacks.isEmpty()) {
log.error("暂无需系统存证回调");
return;
}
String url = null;
String app_id = null;
String secret_key = null;
// 需要回执报告
Map<Long, String> dataRet = new HashMap<Long, String>();
Map<Long, List<String>> data = new HashMap<Long, List<String>>();
Map<String, EvidenceCallback> cacheCallBackBySnMap = new HashMap<>();
for (int i = 0; i < callbacks.size() && i < 1000; i++) {
EvidenceCallback callback = callbacks.get(i);
cacheCallBackBySnMap.put(callback.getEvidenceSn(), callback);
if (callback.getAppServiceId() == null) {
if (data.containsKey(callback.getAppId())) {
data.get(callback.getAppId()).add(callback.getEvidenceSn());
} else {
List<String> sns = new ArrayList<String>();
sns.add(callback.getEvidenceSn());
data.put(callback.getAppId(), sns);
}
} else {
dataRet.put(callback.getAppId(), callback.getEvidenceSn());
}
}
// <---------------------------- 处理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) {
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);
if (retStr == null || ret_data.getInteger("status") != 1) {
log.error("EvidenceCallbackTask failure count [" + entry.getValue().size() + "]");
for (String sn : entry.getValue()) {
EvidenceCallback callback = null;
if (cacheCallBackBySnMap.get(sn) == null) {
EvidenceCallbackExample callbackExample0 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria0 = callbackExample.createCriteria();
criteria0.andEvidenceSnEqualTo(sn);
callback = callbackService.selectAll(callbackExample0).get(0);
} else {
callback = cacheCallBackBySnMap.get(sn);
}
int counnt = callback.getCounnt() + 1;
if (counnt == 3) {
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByPrimaryKey", callback.getId());
} else {
callback.setCounnt(counnt);
sqlSession.update("com.itrus.portal.db.EvidenceCallbackMapper.updateByPrimaryKeySelective", callback);
}
}
} else {
log.error("EvidenceCallbackTask success count [" + entry.getValue().size() + "]");
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", entry.getValue().toArray());
EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
criteria1.andEvidenceSnIn(entry.getValue());
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample", callbackExample1);
// for(String sn:entry.getValue()) {
// EvidenceBasicInformation basicInformation = informationService
// .getInformationBySn(sn, null);
// basicInformation.setIsCallback(1);
// sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKeySelective",
// basicInformation);
//
// EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
// EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
// criteria1.andEvidenceSnEqualTo(sn);
// sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample",
// callbackExample1);
//
// }
}
}
// <---------------------------- 处理dataRet start ------------------------------>
for (Entry<Long, String> entry : dataRet.entrySet()) {
ApplicationInfo applicationInfo = CacheCustomer.getAPP_INFO_MAP_BY_ID().get(entry.getKey());
if (applicationInfo == null) {
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;
}
}
EvidenceBasicInformation basicInformation = informationService.getInformationBySn(entry.getValue(), null);
// 得到证据回执base64
String reportBase64 = null;
// reportBase64 = EvidenceSaveServiceApi.cacheReportBySnMap.get(basicInformation.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(basicInformation.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 = null;
mapRet = reportTemplate.returnreceipt(basicInformation.getEvidenceSn(), applicationInfo, null);
if (mapRet.get("status") != null && (int) mapRet.get("status") == 0) {
// 修改证据基本信息回执状态为已出
reportBase64 = (String) mapRet.get("pdfBase64");
basicInformation.setReceiptStatus(1);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updateByPrimaryKey", basicInformation);
}
}
} else {
// EvidenceSaveServiceApi.cacheReportBySnMap.remove(basicInformation.getEvidenceSn());
}
Map<String, Object> param = new HashMap<String, Object>();
param.put("status", 1);
param.put("appId", app_id);
param.put("evidenceSn", basicInformation.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 + basicInformation.getEvidenceSn(), secret_key), false);
String retStr = OkHttpClientManagerCallback.post(url, header, param);
JSONObject ret_data = JSONObject.parseObject(retStr);
String dataSn = basicInformation.getEvidenceSn();
Long appId = entry.getKey();
// 判断是否成功 true ——> 失败
if (retStr == null || ret_data.getInteger("status") != 1) {
EvidenceCallback callback = null;
if (cacheCallBackBySnMap.get(dataSn) == null) {
EvidenceCallbackExample callbackExample0 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria0 = callbackExample.createCriteria();
criteria0.andEvidenceSnEqualTo(dataSn);
callback = callbackService.selectAll(callbackExample0).get(0);
} else {
callback = cacheCallBackBySnMap.get(dataSn);
}
int counnt = callback.getCounnt() + 1;
if (counnt == 3) {
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByPrimaryKey", callback.getId());
} else {
callback.setCounnt(counnt);
sqlSession.update("com.itrus.portal.db.EvidenceCallbackMapper.updateByPrimaryKeySelective", callback);
}
} else {
List<String> sns = new ArrayList<>();
sns.add(dataSn);
sqlSession.update("com.itrus.portal.db.EvidenceBasicInformationMapper.updates", sns.toArray());
EvidenceCallbackExample callbackExample1 = new EvidenceCallbackExample();
EvidenceCallbackExample.Criteria criteria1 = callbackExample.createCriteria();
criteria1.andEvidenceSnIn(sns);
sqlSession.delete("com.itrus.portal.db.EvidenceCallbackMapper.deleteByExample", callbackExample1);
}
}
// <---------------------------- 处理dataRet end ------------------------------>
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
LogUtil.evidencelog(sqlSession, null, "存证回调接口", "失败原因:" + e.toString());
}
}
use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class CertificateServiceImpl method setCertitifate.
/**
* 添加/更新证书属性
* @param alias
* @param cert
* @param certp7
* @return
*/
public boolean setCertitifate(String alias, String cert, String certp7) {
if (StringUtils.isEmpty(alias) && StringUtils.isEmpty(cert)) {
return false;
}
JSONObject ret_data = null;
try {
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
}
if (realNameAuthentication == null) {
return false;
}
String urlAgent = realNameAuthentication.getRealNameddress() + KEY_SETCERTITIFATE;
Map<String, Object> paramsAgent = new HashMap<String, Object>();
paramsAgent.put("alias", alias);
paramsAgent.put("cert", cert);
if (StringUtils.isNotEmpty(certp7)) {
paramsAgent.put("chain", certp7);
}
String repAgent = HttpClientUtil.postForm(urlAgent, AuthService.getHeader(), paramsAgent);
log.error("repAgent=" + repAgent);
ret_data = JSONObject.parseObject(repAgent);
log.error("ret_data=" + ret_data);
if (ret_data.getIntValue("code") != 0) {
String oper = "绑定证书失败";
String info = "错误原因:" + ret_data.getIntValue("message");
LogUtil.evidencelog(sqlSession, null, oper, info);
return false;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
String oper = "绑定证书失败";
String info = "错误原因:" + e.getMessage();
LogUtil.evidencelog(sqlSession, null, oper, info);
}
return true;
}
use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class CertificateServiceImpl method setSeal.
/**
* 绑定签章
* @param alias
* @param sealImg
* @return
*/
public boolean setSeal(String alias, String sealImg) {
if (StringUtils.isEmpty(alias) && StringUtils.isEmpty(sealImg)) {
return false;
}
JSONObject ret_data = null;
try {
RealNameAuthentication realNameAuthentication = CacheCustomer.getAUTH_CONFIG_MAP().get(2);
if (realNameAuthentication == null) {
realNameAuthentication = realNameAuthenticationSerivce.getRealNameAuthenticationByTwo();
}
if (realNameAuthentication == null) {
return false;
}
String urlAgent = realNameAuthentication.getRealNameddress() + KEY_SETSEAL;
Map<String, Object> paramsAgent = new HashMap<String, Object>();
paramsAgent.put("alias", alias);
paramsAgent.put("sealImg", sealImg);
String repAgent = HttpClientUtil.postForm(urlAgent, AuthService.getHeader(), paramsAgent);
ret_data = JSONObject.parseObject(repAgent);
log.error("ret_data=" + ret_data);
if (ret_data.getIntValue("code") != 0) {
String oper = "绑定签章失败";
String info = "错误原因:" + ret_data.getIntValue("message");
LogUtil.evidencelog(sqlSession, null, oper, info);
return false;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
use of com.itrus.portal.db.RealNameAuthentication in project portal by ixinportal.
the class RealNameAuthenticationController method create.
// 返回新建页面
@RequestMapping(params = "form", produces = "text/html")
public String create(@RequestParam(value = "id", required = false) Long id, @RequestParam(value = "status", required = false) Integer status, Model uiModel) {
uiModel.addAttribute("status", status);
if (status == null) {
status = 1;
}
String rt = null;
try {
List<RealNameAuthentication> realNameList = realnameauthent.getRealNameAuthenticationExample();
for (RealNameAuthentication realName : realNameList) {
switch(realName.getType()) {
case 1:
uiModel.addAttribute("realname1", realName);
break;
case 2:
uiModel.addAttribute("realname2", realName);
break;
case 3:
uiModel.addAttribute("realname3", realName);
break;
case 4:
uiModel.addAttribute("realname4", realName);
break;
default:
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
switch(status) {
case 1:
rt = "realnameauthentication/create";
break;
case 2:
rt = "realnameauthentication/create1";
break;
case 3:
rt = "realnameauthentication/create2";
break;
case 4:
rt = "realnameauthentication/create3";
break;
default:
rt = "realnameauthentication/create";
break;
}
return rt;
}
Aggregations