Search in sources :

Example 1 with RaAccountInfoExample

use of com.itrus.portal.db.RaAccountInfoExample 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 RaAccountInfoExample

use of com.itrus.portal.db.RaAccountInfoExample 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 3 with RaAccountInfoExample

use of com.itrus.portal.db.RaAccountInfoExample 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;
}
Also used : CertInfo(cn.topca.tca.ra.service.CertInfo) RaAccountInfo(com.itrus.portal.db.RaAccountInfo) RaAccountInfoExample(com.itrus.portal.db.RaAccountInfoExample) TerminalServiceException(com.itrus.portal.exception.TerminalServiceException) RaServiceUnavailable_Exception(cn.topca.tca.ra.service.RaServiceUnavailable_Exception) UserAPIServicePortType(cn.topca.tca.ra.service.UserAPIServicePortType) CaPasscode(com.itrus.portal.db.CaPasscode) UserAPIService(cn.topca.tca.ra.service.UserAPIService) URL(java.net.URL)

Aggregations

RaAccountInfo (com.itrus.portal.db.RaAccountInfo)3 RaAccountInfoExample (com.itrus.portal.db.RaAccountInfoExample)3 CaPasscode (com.itrus.portal.db.CaPasscode)2 CaPasscodeExample (com.itrus.portal.db.CaPasscodeExample)2 CertInfo (cn.topca.tca.ra.service.CertInfo)1 RaServiceUnavailable_Exception (cn.topca.tca.ra.service.RaServiceUnavailable_Exception)1 UserAPIService (cn.topca.tca.ra.service.UserAPIService)1 UserAPIServicePortType (cn.topca.tca.ra.service.UserAPIServicePortType)1 RaCaPassCode (com.itrus.portal.entity.RaCaPassCode)1 TerminalServiceException (com.itrus.portal.exception.TerminalServiceException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1