use of com.itrus.portal.db.CaPasscode in project portal by ixinportal.
the class CaPasscodeService method insertToDB.
/**
* 插入数据库<br>
* O , OU , AccountHash , 通行码 , 创建日期 , 截止日期 , 状态 , 描述 ,
*
* @param lists
*/
public void insertToDB(List<String[]> lists) {
SimpleDateFormat sim = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
// 将表头放入一个map集合
Map<String, Integer> titleMap = getColumnNum(lists.get(0));
for (int i = 1; i < lists.size(); i++) {
// 每一行的数据
String[] str = lists.get(i);
// 验证passcode是否已经存在数据库中
CaPasscodeExample caPasscodeExample = new CaPasscodeExample();
CaPasscodeExample.Criteria capaCriteria = caPasscodeExample.or();
capaCriteria.andPasscodeEqualTo(str[titleMap.get("通行码")]);
// capaCriteria.andStatusEqualTo(1);
CaPasscode caPa = sqlSession.selectOne("com.itrus.portal.db.CaPasscodeMapper.selectByExample", caPasscodeExample);
if (caPa == null) {
// passcode不存在数据库中,进行添加
// 获取RA账号的hash,根据hash值在RA账号信息表查询该RA账号是否存在,若不存在,则添加RA信息
RaAccountInfoExample raiExample = new RaAccountInfoExample();
RaAccountInfoExample.Criteria raiCriteria = raiExample.or();
raiCriteria.andHashValEqualTo(str[titleMap.get("AccountHash")]);
RaAccountInfo raAccountInfo = sqlSession.selectOne("com.itrus.portal.db.RaAccountInfoMapper.selectByExample", raiExample);
if (raAccountInfo == null) {
// 插入ra账户信息
raAccountInfo = new RaAccountInfo();
raAccountInfo.setCreateTime(new Date());
raAccountInfo.setHashVal(str[titleMap.get("AccountHash")]);
raAccountInfo.setOrganization(str[titleMap.get("O")]);
raAccountInfo.setOrgUnit(str[titleMap.get("OU")]);
sqlSession.insert("com.itrus.portal.db.RaAccountInfoMapper.insertSelective", raAccountInfo);
}
// 插入ca的passcode信息
CaPasscode caPasscode = new CaPasscode();
String start = str[titleMap.get("创建日期")] + " 23:59:59";
String end = str[titleMap.get("截止日期")] + " 00:00:00";
Date startTime;
try {
startTime = sim.parse(start);
Date endTime = sim.parse(end);
caPasscode.setStartTime(startTime);
caPasscode.setEndTime(endTime);
} catch (ParseException e) {
lists.clear();
e.printStackTrace();
}
caPasscode.setCreateTime(new Date());
// 通行码
caPasscode.setPasscode(str[titleMap.get("通行码")]);
// 假如不等于valid,则设置该passcode为无效,默认无效
int status = 3;
if ("VALID".equals(str[titleMap.get("状态")]))
// VALID用1代替:有效
status = 1;
// 设置passcode的状态
caPasscode.setStatus(status);
caPasscode.setRaAccountInfo(raAccountInfo.getId());
if (null != titleMap.get("IP地址")) {
// 描述
caPasscode.setIpAdd(str[titleMap.get("IP地址")]);
}
sqlSession.insert("com.itrus.portal.db.CaPasscodeMapper.insertSelective", caPasscode);
}
}
}
use of com.itrus.portal.db.CaPasscode in project portal by ixinportal.
the class CaPasscodeService method IssuedCode4Cert.
/**
* 获得有效passcode,并将其设置为已使用
*
* @param accountInfo
* @param cert
* @return
* @throws TerminalServiceException
*/
public CaPasscode IssuedCode4Cert(RaAccountInfo accountInfo) throws /*, UserCert cert*/
TerminalServiceException {
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
// 防止一个code赋给两个用户
def.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
TransactionStatus status = transactionManager.getTransaction(def);
CaPasscode code = null;
try {
CaPasscodeExample passcodeExample = new CaPasscodeExample();
CaPasscodeExample.Criteria codeCriteria = passcodeExample.createCriteria();
codeCriteria.andRaAccountInfoEqualTo(accountInfo.getId());
codeCriteria.andStatusEqualTo(CODE_STATUS_VALID);
codeCriteria.andUseTimeIsNull();
codeCriteria.andEndTimeGreaterThan(new Date());
passcodeExample.setOrderByClause("create_time desc");
passcodeExample.setLimit(1);
code = sqlSession.selectOne("com.itrus.portal.db.CaPasscodeMapper.selectByExample", passcodeExample);
// 设置为已使用
if (code != null) {
code.setStatus(CODE_STATUS_USED);
code.setUseTime(new Date());
// code.setCertId(cert.getId());
sqlSession.update("com.itrus.portal.db.CaPasscodeMapper.updateByPrimaryKeySelective", code);
} else {
LogUtil.adminlog(sqlSession, "获取授权码", "RA账号ID:" + accountInfo.getId() + ",O:" + accountInfo.getOrganization() + ",OU:" + accountInfo.getOrgUnit() + ",没有有效passcode");
}
if (!status.isCompleted())
transactionManager.commit(status);
} catch (Exception e) {
if (!status.isCompleted())
transactionManager.rollback(status);
logger.error("", e);
throw new TerminalServiceException("发生未知错误,请稍后重试");
}
return code;
}
use of com.itrus.portal.db.CaPasscode in project portal by ixinportal.
the class CertUtlis method enrollCertByWS.
public CertInfo enrollCertByWS(String csr, RaAccount raAccount, UserInfo userInfo, Integer certValidity) throws MalformedURLException, RaServiceUnavailable_Exception, TerminalServiceException {
String json = "{\"certValidity\":" + certValidity + "}";
CertInfo certInfo = null;
UserAPIService service = new UserAPIService(new URL(raAccount.getServiceUrl()));
UserAPIServicePortType client = service.getUserAPIServicePort();
// 用户信息
try {
logger.error("***判断是什么模式***" + raAccount.getCertSignType());
// 判断是什么模式
if (raAccount.getCertSignType() == null || (raAccount.getCertSignType() != null && raAccount.getCertSignType() == 1)) {
// AA模式
logger.error("*****userInfo=" + userInfo + "***csr***=" + csr + "***raAccount.getAccountHash()**=" + raAccount.getAccountHash() + "***raAccount.getAaPassword()**=" + raAccount.getAaPassword() + "**json**=" + json);
certInfo = client.enrollCertAA(userInfo, csr, raAccount.getAccountHash(), raAccount.getAaPassword(), "", json);
} else {
// passcord模式
logger.error("输出hash*****raAccount.getAccountHash()========" + raAccount.getAccountHash());
// 判断是否为passcord模式
CaPasscode passcode = new CaPasscode();
// 获取对应ra账号的passcode
RaAccountInfoExample raInfoExample = new RaAccountInfoExample();
RaAccountInfoExample.Criteria raInfoCriteria = raInfoExample.createCriteria();
raInfoCriteria.andHashValEqualTo(raAccount.getAccountHash());
raInfoExample.setOrderByClause("create_time desc");
raInfoExample.setLimit(1);
RaAccountInfo raAccountInfo = raAccountInfoService.getRaAccountInfo(raInfoExample);
// 获取对应passcode
try {
passcode = codeService.IssuedCode4Cert(raAccountInfo);
if (passcode == null) {
logger.error("******passcode为空***********");
throw new TerminalServiceException("passcode为空");
}
} catch (TerminalServiceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
throw e1;
}
logger.error("******passcode=" + passcode.getPasscode());
certInfo = client.enrollCertAA(userInfo, csr, raAccount.getAccountHash(), raAccount.getAaPassword(), passcode.getPasscode(), json);
}
} catch (RaServiceUnavailable_Exception e) {
logger.error("userInfo:" + ToStringBuilder.reflectionToString(userInfo));
logger.error("csr:" + csr);
logger.error("raAccount:" + ToStringBuilder.reflectionToString(raAccount));
logger.error("json:" + json);
throw e;
}
return certInfo;
}
Aggregations