use of cn.topca.tca.ra.service.UserInfo in project portal by ixinportal.
the class CertService method sm2.
/**
* 制证
*/
@RequestMapping(value = "/make/sm2")
@ResponseBody
public Map<String, Object> sm2(@RequestParam("csr") String csr, @RequestParam("userName") String userName, @RequestParam("userEmail") String userEmail, @RequestParam(value = "period", required = false) Integer period) {
Map<String, Object> result = new HashMap<String, Object>(3);
result.put("status", 0);
try {
CertUtlis certutil = new CertUtlis();
UserInfo rauserinfo = new UserInfo();
rauserinfo.setUserName(userName);
rauserinfo.setUserEmail(userEmail);
// 证书有效期
Integer certValidity = 7;
if ("0".equals(period)) {
certValidity = null;
} else if (1 == period) {
certValidity = 365 * 1 + 1;
} else if (3 == period) {
certValidity = 365 * 3 + 1;
} else if (5 == period) {
certValidity = 365 * 5 + 2;
} else if (10 == period) {
certValidity = 365 * 10 + 2;
}
// 调用RA
CertInfo racertinfo = null;
RaAccount ra = new RaAccount();
ra.setAaPassword("password");
ra.setServiceUrl("http://topca-ra.itrus.com.cn/services/userAPI?wsdl");
ra.setAccountOrganization("i信部门SM2双证书的测试");
ra.setAccountOrgUnit("i信部门测试");
String accountHash = CipherUtils.md5((ra.getAccountOrganization() + ra.getAccountOrgUnit()).getBytes("GBK")).toUpperCase();
ra.setAccountHash(accountHash);
racertinfo = certutil.enrollCertByWS(csr, ra, rauserinfo, certValidity);
Map<String, Object> data = new HashMap<String, Object>(8);
data.put("certSignBuf", racertinfo.getCertSignBuf());
data.put("certChain", racertinfo.getCertSignBufP7());
data.put("certDn", racertinfo.getCertSubjectDn());
data.put("certSn", racertinfo.getCertSerialNumber());
data.put("issuerDn", racertinfo.getCertIssuerDn());
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
data.put("startTime", sdf.parse(racertinfo.getCertNotBefore()));
data.put("endTime", sdf.parse(racertinfo.getCertNotAfter()));
data.put("certKmcRep1", racertinfo.getCertKmcRep1());
data.put("certKmcRep2", racertinfo.getCertKmcRep2());
result.put("data", data);
result.put("status", 1);
result.put("message", "制作证书成功");
} catch (Exception e) {
e.printStackTrace();
result.put("message", e.toString());
// String oper = "RA调用失败";
// String info = "错误原因:" + e.toString();
// com.itrus.portal.evidence.utils.LogUtil.evidencelog(sqlSession, oper, info);
}
return result;
}
use of cn.topca.tca.ra.service.UserInfo in project portal by ixinportal.
the class CertUtlis method enrollCertByWS.
// @Autowired
// private CaPasscodeService codeService;
public CertInfo enrollCertByWS(String csr, RaAccount raAccount, String uid) throws MalformedURLException, RaServiceUnavailable_Exception {
String json = "{\"certValidity\":" + 60 + "}";
CertInfo certInfo = null;
UserAPIService service = new UserAPIService(new URL(raAccount.getServiceUrl()));
UserAPIServicePortType client = service.getUserAPIServicePort();
// 用户信息
UserInfo userInfo = new UserInfo();
userInfo.setUserEmail("test@itrus.com.cn");
userInfo.setUserName("cceshi");
userInfo.setUserOrgunit(raAccount.getAccountOrgUnit());
userInfo.setUserOrganization(raAccount.getAccountOrganization());
userInfo.setUserAdditionalField1("123");
certInfo = client.enrollCertAA(userInfo, csr, raAccount.getAccountHash(), "itrusyes", "", json);
return certInfo;
}
use of cn.topca.tca.ra.service.UserInfo in project portal by ixinportal.
the class EnrolCertTest method topcaCert.
public static void topcaCert(String accountOrgUnit, String accountOrganization, String serviceUrl, String accountHash, String csr) throws Exception {
String json = "{\"certValidity\":" + 60 + "}";
json = "{'certKmcReq2':'','certValidity':'12'}";
UserAPIService service = new UserAPIService(new URL(serviceUrl));
UserAPIServicePortType client = service.getUserAPIServicePort();
// 用户信息
UserInfo userInfo = new UserInfo();
userInfo.setUserEmail("test@itrus.com.cn");
userInfo.setUserName("cceshi");
userInfo.setUserOrgunit(accountOrgUnit);
userInfo.setUserOrganization(accountOrganization);
userInfo.setUserAdditionalField1("123");
CertInfo certInfo = client.enrollCertAA(userInfo, csr, accountHash, "itrusyes", "", json);
System.out.println(certInfo.getCertSerialNumber());
}
use of cn.topca.tca.ra.service.UserInfo in project portal by ixinportal.
the class CertUtilsTest method testSetUserInfoVal.
@Test
public void testSetUserInfoVal() {
CertUtlis cu = new CertUtlis();
UserInfo userInfo = new UserInfo();
cu.setUserInfoVal(userInfo, "userName", "test");
}
use of cn.topca.tca.ra.service.UserInfo in project portal by ixinportal.
the class MobileCertApplyService method execute.
/**
* service:certApply 申请证书移动端需要传过来的参数
* 1.设备信息 device
* equipmentCategory String 设备型号
* appId Long 应用的名称
* operatingSystem String 操作系统
* userId Long 和用户关联的字段
* createTime date 创建时间
* updateTime date 修改时间
* deviceSerialNumber string 设备序列号 唯一标识
* 2.用户信息 即 注册信息 user
* name String 用户姓名
* phone String 手机号
* idNumber String 身份证号
* appId Long 和应用关联的字段
* email String 电子邮件
* registrationTime date 注册时间
* createTime date 创建时间
* updateTime date 修改时间
* userCode String 用户编码
*
* 最后保存 用户信息 设备信息 证书信息 // TODO: 2017/12/8
* @param content
* @return
*/
@Override
public Map<String, Object> execute(String content) {
Map<String, Object> result = new HashMap<String, Object>(5);
// webSocket日志记录
// MobileWebSocketLogService webSocketLogService=new MobileWebSocketLogService();
// webSocketLogService.execute(content);
result.put(" status", 0);
try {
JSONObject param = JSON.parseObject(content);
// 通过appId获取 应用配置 // TODO: 2017/12/8
String appId = param.getString("appId");
String Alias = param.getString("alias");
// String p=param.getString("p2");
// System.out.println(p);
System.out.println(Alias);
MobileApplyConfigManage mobileApplyConfig = mobileApplyConfigService.selectByappId(appId);
ApplicationInfo applicationInfo = applicationInfoService.getApplicationInfo(appId);
CertUtlis certutil = new CertUtlis();
JSONObject jsonUser = param.getJSONObject("user");
// 根据证书信息项设置 rauserinfo对象 // TODO: 2017/12/8
UserInfo rauserinfo = new UserInfo();
rauserinfo.setUserName(jsonUser.getString("name"));
rauserinfo.setUserEmail(jsonUser.getString("email"));
rauserinfo.setUserAdditionalField1(applicationInfo.getName());
rauserinfo.setUserAdditionalField4(jsonUser.getString("userCode"));
JSONObject jsondevice = param.getJSONObject("device");
JSONObject jsonuser = param.getJSONObject("user");
MobileUser mobileUser = new MobileUser();
mobileUser.setName(jsonuser.getString("name"));
mobileUser.setPhone(jsonuser.getString("phone"));
mobileUser.setIdNumber(jsonuser.getString("idNumber"));
mobileUser.setAppId(applicationInfo.getId());
mobileUser.setUid(jsonuser.getString("userCode"));
mobileUser.setCreateTime(new Date());
mobileUser.setEmail(jsonuser.getString("email"));
mobileUser.setRegistrationTime(new Date());
sqlSession.insert("com.itrus.portal.db.MobileUserMapper.insertSelective", mobileUser);
String user_id = UniqueIDUtils.genMobileUserUID(mobileUser);
System.out.println("user_id :" + user_id);
mobileUser.setUserId(user_id);
// mobileUser.setUid(mobileUser.getId().toString());
mobileLogmanagementLogService.update(mobileUser);
MobileEquipment equipment = new MobileEquipment();
equipment.setAppId(param.getString("appId"));
equipment.setCreateTime(new Date());
equipment.setDeviceSerialNumber(jsondevice.getString("deviceSerialNumber"));
equipment.setEquipmentType(jsondevice.getString("equipmentCategory"));
equipment.setUpdateTime(jsondevice.getDate("updateTime"));
equipment.setUserId(mobileUser.getId());
equipment.setOperatingSystem(jsondevice.getString("operatingSystem"));
mobileEquipmentService.insert(equipment);
// 根据证书信息项设置 证书有效期 // TODO: 2017/12/8
Integer certValidity = 7;
if (mobileApplyConfig.getCertificatedeadline() == null || "0".equals(mobileApplyConfig.getCertificatedeadline())) {
certValidity = null;
} else if (1 == mobileApplyConfig.getCertificatedeadline()) {
certValidity = 365 * 1 + 1;
} else if (2 == mobileApplyConfig.getCertificatedeadline()) {
certValidity = 365 * 2 + 1;
} else if (3 == mobileApplyConfig.getCertificatedeadline()) {
certValidity = 365 * 3 + 1;
} else if (4 == mobileApplyConfig.getCertificatedeadline()) {
certValidity = 365 * 5 + 2;
} else if (5 == mobileApplyConfig.getCertificatedeadline()) {
certValidity = 365 * 10 + 2;
}
RaAccount ra = raAccountService.getRaAccount(mobileApplyConfig.getRaaccountId());
// ra.setAccountHash(accountHash);
if (ra.getAaPassword() != null) {
ra.setAaPassword(AESencrp.decrypt(ra.getAaPassword(), dbEncKey));
}
CertInfo racertinfo = certutil.enrollCertByWS(param.getString("csr"), ra, rauserinfo, certValidity);
Map<String, Object> data = new HashMap<String, Object>(8);
data.put("certSignBuf", racertinfo.getCertSignBuf());
data.put("certChain", racertinfo.getCertSignBufP7());
data.put("certDn", racertinfo.getCertSubjectDn());
data.put("certSn", racertinfo.getCertSerialNumber());
data.put("issuerDn", racertinfo.getCertIssuerDn());
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
data.put("startTime", sdf.parse(racertinfo.getCertNotBefore()));
data.put("endTime", sdf.parse(racertinfo.getCertNotAfter()));
data.put("certKmcRep1", racertinfo.getCertKmcRep1());
data.put("certKmcRep2", racertinfo.getCertKmcRep2());
result.put("data", data);
result.put("status", 1);
result.put("message", "制作证书成功");
MobileCertificate certificate = new MobileCertificate();
certificate.setAppId(appId);
certificate.setApplyConfigId(mobileApplyConfig.getId());
certificate.setUserId(mobileUser.getId());
certificate.setCertificateStatus(0);
certificate.setCreateTime(new Date());
// certificate.setEquipmentId(equipment.getId());
certificate.setEquipmentNumber(equipment.getDeviceSerialNumber());
certificate.setIssueTime((Date) data.get("startTime"));
certificate.setLoseefficacyTime((Date) data.get("endTime"));
certificate.setCertificateCn(EvidenceSaveServiceApi.getCertCn(data.get("certDn").toString()));
certificate.setLockStatus(0);
certificate.setSequenceNumber(data.get("certSn").toString());
certificate.setSubject(data.get("certDn").toString());
certificate.setCertSignBuf(data.get("certSignBuf").toString());
System.out.println(Alias);
certificate.setAlias(Alias);
// System.out.println("certSignBuf: " + data.get("certSignBuf").toString());
System.out.println("certSignBuf: " + data.get("certSignBuf").toString());
certificateService.insert(certificate);
// 更新设备信息
equipment.setCertificate(certificate.getId());
mobileEquipmentService.update(equipment);
// 业务记录日志
// System.out.println("certSignBuf: " + data.get("certSignBuf").toString());
MobileLogmanagementLog log = new MobileLogmanagementLog();
ApplicationInfo info = applicationInfoService.getApplicationInfo(appId);
result.put("infoName", info.getName());
result.put("userId", mobileUser.getUserId());
log.setAppName(info.getName());
log.setContenu("注册成功");
log.setCreateTime(new Date());
log.setServiceType("注册");
log.setUserName(mobileUser.getUserId());
mobileLogmanagementLogService.insertMobileLogmanagementLog(log);
} catch (Exception e) {
e.printStackTrace();
result.put("message", e.toString());
MobileLogmanagementLog log = new MobileLogmanagementLog();
// ApplicationInfo info=applicationInfoService.getApplicationInfo(appId);
log.setAppName(result.get("infoName").toString());
log.setContenu("注册失败");
log.setCreateTime(new Date());
log.setServiceType("注册");
log.setUserName(result.get("userId").toString());
mobileLogmanagementLogService.insertMobileLogmanagementLog(log);
// String oper = "RA调用失败";
// String info = "错误原因:" + e.toString();
// com.itrus.portal.evidence.utils.LogUtil.evidencelog(sqlSession, oper, info);
}
return result;
}
Aggregations