Search in sources :

Example 1 with CaPasscodeExample

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

the class PasscodeController method list.

// 2.统计passcode情况
@RequestMapping(produces = "text/html")
public String list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
    if (page == null || page < 1) {
        page = 1;
    }
    if (size == null || size < 1) {
        size = 10;
    }
    RaAccountInfoExample raiExample = new RaAccountInfoExample();
    // RaAccountInfoExample.Criteria raiCriteria = raiExample.or();
    Integer count = sqlSession.selectOne("com.itrus.portal.db.RaAccountInfoMapper.countByExample", raiExample);
    if (page > 1 && size * (page - 1) >= count) {
        page = (count + size - 1) / size;
    }
    uiModel.addAttribute("count", count);
    uiModel.addAttribute("pages", (count + size - 1) / size);
    uiModel.addAttribute("page", page);
    uiModel.addAttribute("size", size);
    Integer offset = size * (page - 1);
    raiExample.setOffset(offset);
    raiExample.setLimit(size);
    raiExample.setOrderByClause("create_time desc");
    List<RaAccountInfo> raAccountInfos = sqlSession.selectList("com.itrus.portal.db.RaAccountInfoMapper.selectByExample", raiExample);
    List<RaCaPassCode> racaPassCodes = new ArrayList<RaCaPassCode>();
    for (RaAccountInfo rai : raAccountInfos) {
        RaCaPassCode raca = new RaCaPassCode();
        // 设置部门
        raca.setOrganization(rai.getOrganization());
        // 设置单位
        raca.setOrgUnit(rai.getOrgUnit());
        // 设置ra部门id
        raca.setRaAccountInfoId(rai.getId());
        CaPasscodeExample cpExample = new CaPasscodeExample();
        CaPasscodeExample.Criteria caCriteria = cpExample.or();
        caCriteria.andRaAccountInfoEqualTo(rai.getId());
        Integer caPasscodeNum = sqlSession.selectOne("com.itrus.portal.db.CaPasscodeMapper.countByExample", cpExample);
        // 设置总数量
        raca.setCaPasscodeNum(caPasscodeNum);
        // 2表示已使用的passcode
        caCriteria.andStatusEqualTo(2);
        Integer usedCodeNum = sqlSession.selectOne("com.itrus.portal.db.CaPasscodeMapper.countByExample", cpExample);
        // 设置已使用的数量
        raca.setUsedCodeNum(usedCodeNum);
        // if (caPasscodeNum != 0)// 显示passcode总数不为0的记录
        racaPassCodes.add(raca);
    }
    uiModel.addAttribute("racaPassCodes", racaPassCodes);
    uiModel.addAttribute("itemcount", racaPassCodes.size());
    return "passcode/list";
}
Also used : RaAccountInfo(com.itrus.portal.db.RaAccountInfo) RaAccountInfoExample(com.itrus.portal.db.RaAccountInfoExample) ArrayList(java.util.ArrayList) CaPasscodeExample(com.itrus.portal.db.CaPasscodeExample) RaCaPassCode(com.itrus.portal.entity.RaCaPassCode) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CaPasscodeExample

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

the class PasscodeController method delete.

/**
 * 根据证书管理部删除未使用的passcode
 *
 * @return
 */
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("id") Long id, Model uiModel) {
    CaPasscodeExample caPasscodeExample = new CaPasscodeExample();
    CaPasscodeExample.Criteria criteria = caPasscodeExample.or();
    // 有效的passcode
    criteria.andStatusEqualTo(1);
    // 对应证书管理部id
    criteria.andRaAccountInfoEqualTo(id);
    Integer count = sqlSession.selectOne("com.itrus.portal.db.CaPasscodeMapper.countByExample", caPasscodeExample);
    sqlSession.delete("com.itrus.portal.db.CaPasscodeMapper.deleteByExample", caPasscodeExample);
    RaAccountInfo rainfo = sqlSession.selectOne("com.itrus.portal.db.RaAccountInfoMapper.selectByPrimaryKey", id);
    String oper = "删除passcode";
    String info = "删除了 【" + rainfo.getOrganization() + "】未使用的passcode" + count + "个";
    LogUtil.adminlog(sqlSession, oper, info);
    // 删除没有passcode的证书管理部
    caPasscodeExample.clear();
    CaPasscodeExample.Criteria criteria1 = caPasscodeExample.or();
    // 对应证书管理部id
    criteria1.andRaAccountInfoEqualTo(id);
    Integer passcodeCount = sqlSession.selectOne("com.itrus.portal.db.CaPasscodeMapper.countByExample", caPasscodeExample);
    if (0 == passcodeCount) {
        sqlSession.delete("com.itrus.portal.db.RaAccountInfoMapper.deleteByPrimaryKey", id);
    }
    return "redirect:/passcode";
}
Also used : RaAccountInfo(com.itrus.portal.db.RaAccountInfo) CaPasscodeExample(com.itrus.portal.db.CaPasscodeExample) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with CaPasscodeExample

use of com.itrus.portal.db.CaPasscodeExample 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);
        }
    }
}
Also used : RaAccountInfo(com.itrus.portal.db.RaAccountInfo) RaAccountInfoExample(com.itrus.portal.db.RaAccountInfoExample) Date(java.util.Date) CaPasscodeExample(com.itrus.portal.db.CaPasscodeExample) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) CaPasscode(com.itrus.portal.db.CaPasscode)

Example 4 with CaPasscodeExample

use of com.itrus.portal.db.CaPasscodeExample 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;
}
Also used : TerminalServiceException(com.itrus.portal.exception.TerminalServiceException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) CaPasscodeExample(com.itrus.portal.db.CaPasscodeExample) TransactionStatus(org.springframework.transaction.TransactionStatus) CaPasscode(com.itrus.portal.db.CaPasscode) Date(java.util.Date) ParseException(java.text.ParseException) TerminalServiceException(com.itrus.portal.exception.TerminalServiceException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

CaPasscodeExample (com.itrus.portal.db.CaPasscodeExample)4 RaAccountInfo (com.itrus.portal.db.RaAccountInfo)3 CaPasscode (com.itrus.portal.db.CaPasscode)2 RaAccountInfoExample (com.itrus.portal.db.RaAccountInfoExample)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RaCaPassCode (com.itrus.portal.entity.RaCaPassCode)1 TerminalServiceException (com.itrus.portal.exception.TerminalServiceException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1