| | |
| | | package com.vci.frameworkcore.compatibility.impl; |
| | | |
| | | import com.vci.dto.SmPasswordStrategyDTO; |
| | | import com.vci.corba.common.PLException; |
| | | import com.vci.corba.common.data.UserEntityInfo; |
| | | import com.vci.corba.framework.data.PasswordStrategyInfo; |
| | | import com.vci.corba.omd.data.BusinessObject; |
| | | import com.vci.frameworkcore.compatibility.SmPwdStrategyQueryServiceI; |
| | | import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; |
| | | import com.vci.frameworkcore.constant.FrameWorkBtmTypeConstant; |
| | | import com.vci.frameworkcore.enumpck.RoleClassifyEnum; |
| | | import com.vci.frameworkcore.enumpck.RoleControlAreaEnum; |
| | | import com.vci.frameworkcore.model.SmPasswordStrategyDO; |
| | | import com.vci.frameworkcore.model.SmPasswordStrategyForPlatform1; |
| | | import com.vci.frameworkcore.model.SmRoleForPlatform1; |
| | | import com.vci.frameworkcore.pagemodel.SmPasswordStrategyVO; |
| | | import com.vci.frameworkcore.pagemodel.SmRoleVO; |
| | | import com.vci.frameworkcore.enumpck.CombinationEnum; |
| | | import com.vci.model.SmPasswordStrategyDO; |
| | | import com.vci.model.SmPasswordStrategyForPlatform1; |
| | | import com.vci.pagemodel.SmPasswordStrategyVO; |
| | | import com.vci.omd.utils.ObjectTool; |
| | | import com.vci.starter.web.constant.QueryOptionConstant; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | import com.vci.starter.web.pagemodel.DataGrid; |
| | | import com.vci.starter.web.pagemodel.PageHelper; |
| | |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import com.vci.web.util.WebUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; |
| | | |
| | | import static com.vci.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST; |
| | | |
| | | /** |
| | | * 密码策略查询服务 |
| | |
| | | */ |
| | | @Autowired |
| | | private PlatformClientUtil platformClientUtil; |
| | | |
| | | /** |
| | | * 日志 |
| | | */ |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | /** |
| | | * 获取默认密码策略 |
| | |
| | | pageHelper = new PageHelper(-1); |
| | | } |
| | | pageHelper.addDefaultAsc("pname"); |
| | | VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmPasswordStrategyDO.class,pageHelper); |
| | | //queryWrapper.eq("pltype","2"); |
| | | platformClientUtil.getFrameworkService().fetchAllPasswordStrategy(); |
| | | //platformClientUtil.getFrameworkService().fetchpassword(); |
| | | VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmPasswordStrategyForPlatform1.class,pageHelper); |
| | | //platformClientUtil.getFrameworkService().fetchAllPasswordStrategy(); |
| | | List<SmPasswordStrategyForPlatform1> smPasswordStrategyForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmPasswordStrategyForPlatform1.class); |
| | | DataGrid<SmPasswordStrategyVO> dataGrid = new DataGrid<>(); |
| | | if(!CollectionUtils.isEmpty(smPasswordStrategyForPlatform1s)){ |
| | |
| | | * @param smPasswordStrategyForPlatform1s 原平台的密码策略 |
| | | * @return |
| | | */ |
| | | private List<SmPasswordStrategyVO> pltPwdStrategy2SmPwdStrategyVOs(List<SmPasswordStrategyForPlatform1> smPasswordStrategyForPlatform1s){ |
| | | private List<SmPasswordStrategyVO> pltPwdStrategy2SmPwdStrategyVOs(List<SmPasswordStrategyForPlatform1> smPasswordStrategyForPlatform1s) throws PLException{ |
| | | List<SmPasswordStrategyVO> smPasswordStrategyVOList = new ArrayList<>(); |
| | | if(!CollectionUtils.isEmpty(smPasswordStrategyForPlatform1s)){ |
| | | smPasswordStrategyForPlatform1s.stream().forEach(s -> { |
| | | smPasswordStrategyVOList.add(pltPwdStrategy2SmPwdStrategyVO(s)); |
| | | try { |
| | | smPasswordStrategyVOList.add(pltPwdStrategy2SmPwdStrategyVO(s)); |
| | | } catch (PLException e) { |
| | | e.printStackTrace(); |
| | | String exceptionMessage = "Platform1对象转VO对象时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e); |
| | | logger.error(exceptionMessage); |
| | | throw new VciBaseException(exceptionMessage); |
| | | } |
| | | }); |
| | | } |
| | | return smPasswordStrategyVOList; |
| | |
| | | * @param strategyForPlatform1 原平台的密码策略 |
| | | * @return 新的密码策略对象 |
| | | */ |
| | | private SmPasswordStrategyVO pltPwdStrategy2SmPwdStrategyVO(SmPasswordStrategyForPlatform1 strategyForPlatform1){ |
| | | private SmPasswordStrategyVO pltPwdStrategy2SmPwdStrategyVO(SmPasswordStrategyForPlatform1 strategyForPlatform1) throws PLException { |
| | | SmPasswordStrategyVO strategyVO = new SmPasswordStrategyVO(); |
| | | strategyVO.setOid(strategyForPlatform1.getPluid()); |
| | | strategyVO.setId(""); |
| | | strategyVO.setName(strategyForPlatform1.getPname()); |
| | | strategyVO.setMaxLength(strategyForPlatform1.getPlmaxlength()); |
| | | strategyVO.setMinLength(strategyForPlatform1.getPlength()); |
| | | strategyVO.setValidDay(strategyForPlatform1.getPremindday()); |
| | | strategyVO.setValidDay(strategyForPlatform1.getPoverdueday()); |
| | | strategyVO.setRemindDay(strategyForPlatform1.getPremindday()); |
| | | strategyVO.setRetryTime(strategyForPlatform1.getPretrytime()); |
| | | strategyVO.setLockTime(strategyForPlatform1.getPlocktime()); |
| | | strategyVO.setDefaultFlag(strategyForPlatform1.getPlisdefault() == 1); |
| | | strategyVO.setDescription(strategyForPlatform1.getPldesc()); |
| | | strategyVO.setCreateTime(strategyForPlatform1.getPlcreatetime()); |
| | | strategyVO.setCreateTime(new Date(strategyForPlatform1.getPlcreatetime())); |
| | | strategyVO.setCreator(strategyForPlatform1.getPlcreateuser()); |
| | | strategyVO.setLastModifyTime(strategyForPlatform1.getPlupdatetime()); |
| | | strategyVO.setLastModifyTime(new Date(strategyForPlatform1.getPlupdatetime())); |
| | | strategyVO.setLastModifier(strategyForPlatform1.getPlupdateuser()); |
| | | strategyVO.getRequireCharType(strategyForPlatform1.getPcharspecies()); |
| | | strategyVO.setLicensors(strategyForPlatform1.getPllicensors()); |
| | | strategyVO.setRequireCharCount(strategyForPlatform1.getPlrequiredtype()); |
| | | //处理密码策略的组合方式 |
| | | Integer plchartypes = strategyForPlatform1.getPlchartypes(); |
| | | if(Func.isNotEmpty(plchartypes)){ |
| | | String combinations = plchartypes2Combinations(plchartypes); |
| | | strategyVO.setRequireCharType(combinations); |
| | | strategyVO.setRequireCharTypeText(CombinationEnum.getCombinationText(combinations)); |
| | | } |
| | | return strategyVO; |
| | | } |
| | | |
| | | /** |
| | | * plchartypes转换为Combinations(英文) |
| | | * @param plchartypes |
| | | * @return 进制数转换为组合方式的因为枚举多个之间用都好间隔 |
| | | */ |
| | | private String plchartypes2Combinations(Integer plchartypes){ |
| | | StringBuilder sb = new StringBuilder(); |
| | | if ((plchartypes & 0x01) == 0x01) |
| | | sb.append("number,"); |
| | | if ((plchartypes & 0x02) == 0x02) |
| | | sb.append("lower,"); |
| | | if ((plchartypes & 0x04) == 0x04) |
| | | sb.append("upper,"); |
| | | if ((plchartypes & 0x08) == 0x08) |
| | | sb.append("symbol,"); |
| | | return sb.deleteCharAt(sb.length() - 1).toString(); |
| | | } |
| | | |
| | | /** |
| | | * plchartypes转换为Combinations(英文) |
| | | * @param combinations |
| | | * @return 组合方式转换为实际要存储的整形数 |
| | | */ |
| | | private short combinations2Plchartypes(String combinations) { |
| | | short plchartypes = 0; |
| | | String[] combinationsArray = combinations.split(","); |
| | | for (String type : combinationsArray) { |
| | | switch (type) { |
| | | case "number": |
| | | plchartypes |= 0x01; |
| | | break; |
| | | case "lower": |
| | | plchartypes |= 0x02; |
| | | break; |
| | | case "upper": |
| | | plchartypes |= 0x04; |
| | | break; |
| | | case "symbol": |
| | | plchartypes |= 0x08; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return plchartypes; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public boolean saveUserPasswordStrateg(String[] userIds, String passwordStrategId) throws PLException { |
| | | VciBaseUtil.alertNotNull(userIds,"用户主键",passwordStrategId,"密码安全策略主键"); |
| | | //TODO:这里没有做查重处理,明天记得验证一下这儿是不是会自动做saveOrUpdate的处理 |
| | | return platformClientUtil.getFrameworkService().saveUserPasswordStrateg( |
| | | userIds, |
| | | passwordStrategId, |
| | |
| | | } |
| | | |
| | | /** |
| | | * 密码策略校验:是否合规校验 |
| | | * @param strategy |
| | | */ |
| | | private void checkPwdStrategy(SmPasswordStrategyDTO strategy){ |
| | | if(strategy.getRequireCharCount() > strategy.getCombinations().split(",").length){ |
| | | throw new VciBaseException("必填种类不能大于所选择的密码组合方式的个数!"); |
| | | } |
| | | if(strategy.getMaxLength() < strategy.getMinLength()){ |
| | | throw new VciBaseException("密码最大长度不能小于最小长度!"); |
| | | } |
| | | if(Func.isNotEmpty(strategy.getRequireCharCount()) && |
| | | (strategy.getMinLength() < strategy.getRequireCharCount() || |
| | | strategy.getMaxLength() < strategy.getRequireCharCount()) |
| | | ){ |
| | | throw new VciBaseException("密码最小长度不能小于必填种类的值!"); |
| | | } |
| | | if(strategy.getValidDay() <= strategy.getRemindDay()){ |
| | | throw new VciBaseException("过期时间不能小于提醒时间!"); |
| | | } |
| | | //判断前端是否未提交,是否默认字段 |
| | | if(Func.isEmpty(strategy.getDefaultFlag())){ |
| | | strategy.setDefaultFlag("false"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * dto对象转换为info对象 |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | private PasswordStrategyInfo changePasswordStrategyDTO2Info(SmPasswordStrategyDTO dto){ |
| | | PasswordStrategyInfo info = new PasswordStrategyInfo(); |
| | | info.id = dto.getOid() == null ? "" : dto.getOid(); |
| | | info.name = dto.getName(); |
| | | info.passwordLen = dto.getMinLength(); |
| | | info.passwordMaxLen = dto.getMaxLength(); |
| | | info.charTypes = dto.getRequireCharType(); |
| | | info.requiredType = dto.getRequireCharCount(); |
| | | //逾期日=有效天数 |
| | | info.overdueDay = dto.getValidDay(); |
| | | info.remideDay = dto.getRemindDay(); |
| | | info.retryTime = dto.getRetryTime(); |
| | | info.lockTime = dto.getLockTime(); |
| | | if(dto.getDefaultFlag().equals("1") || dto.getDefaultFlag().equals("true")){ |
| | | info.isDefault = true; |
| | | }else { |
| | | info.isDefault = false; |
| | | } |
| | | info.desc = dto.getDescription() == null ? "" : dto.getDescription(); |
| | | info.createTime = dto.getCreateTime() == null ? System.currentTimeMillis() : dto.getCreateTime().getTime(); |
| | | info.createUser = dto.getCreator() == null ? "" : dto.getCreator(); |
| | | info.updateTime = System.currentTimeMillis(); |
| | | info.updateUser = dto.getLastModifier() == null ? "" : dto.getLastModifier(); |
| | | return info; |
| | | } |
| | | |
| | | /** |
| | | * 根据map条件查询密码策略 |
| | | * @param conditionMap |
| | | * @return |
| | | */ |
| | | private List<SmPasswordStrategyVO> getPwdStrategyByCondition(Map<String,String> conditionMap) throws PLException { |
| | | if(Func.isEmpty(conditionMap)){ |
| | | conditionMap = new HashMap(); |
| | | } |
| | | VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmPasswordStrategyForPlatform1.class); |
| | | List<SmPasswordStrategyForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmPasswordStrategyForPlatform1.class); |
| | | if(Func.isEmpty(roleForPlatform1s)){ |
| | | return null; |
| | | } |
| | | return pltPwdStrategy2SmPwdStrategyVOs(roleForPlatform1s); |
| | | } |
| | | |
| | | /** |
| | | * 新增密码策略 |
| | | * @param spsDto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean addPasswordStrateg(SmPasswordStrategyDTO spsDto) throws PLException { |
| | | VciBaseUtil.alertNotNull( |
| | | spsDto,"新增的密码策略对象", |
| | | spsDto.getName(),"策略名称", |
| | | spsDto.getMinLength(),"密码最小长度", |
| | | spsDto.getMaxLength(),"密码最大长度", |
| | | spsDto.getCombinations(),"组合方式种类", |
| | | spsDto.getRequireCharCount(),"必填种类", |
| | | spsDto.getValidDay(),"过期时间", |
| | | spsDto.getRemindDay(),"提醒时间", |
| | | spsDto.getRetryTime(),"重试次数", |
| | | spsDto.getLockTime(),"锁定时间" |
| | | ); |
| | | //密码策略合规校验,不合规会抛出错误 |
| | | this.checkPwdStrategy(spsDto); |
| | | //根据策略名称查重 |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("pname",spsDto.getName()); |
| | | List<SmPasswordStrategyVO> dbVoList = this.getPwdStrategyByCondition(conditionMap); |
| | | if(Func.isNotEmpty(dbVoList)){ |
| | | throw new VciBaseException("策略名称已经存在,请进行修改!"); |
| | | } |
| | | //获取当前用户账号信息:平台保存方法中会将userEntityInfo中的用户信息用作当前策略的创建人和修改人 |
| | | String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | UserEntityInfo userEntityInfo = new UserEntityInfo(userId,null); |
| | | //组合方式转换为存储值 |
| | | spsDto.setRequireCharType(combinations2Plchartypes(spsDto.getCombinations())); |
| | | spsDto.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT)); |
| | | spsDto.setCreator(userId); |
| | | spsDto.setLastModifier(userId); |
| | | //转换为存储用对象 |
| | | PasswordStrategyInfo passwordStrategyInfo = changePasswordStrategyDTO2Info(spsDto); |
| | | //当设置为默认策略时,平台保存方法会自动处理掉已存在的默认策略,以保证只有一条默认策略 |
| | | return platformClientUtil.getFrameworkService().savePasswordStrategy(passwordStrategyInfo, userEntityInfo); |
| | | } |
| | | |
| | | /** |
| | | * 修改密码策略 |
| | | * @param spsDto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean updatePasswordStrateg(SmPasswordStrategyDTO spsDto) throws PLException { |
| | | VciBaseUtil.alertNotNull( |
| | | spsDto,"新增的密码策略对象", |
| | | spsDto.getOid(),"策略主键", |
| | | spsDto.getName(),"策略名称", |
| | | spsDto.getMinLength(),"密码最小长度", |
| | | spsDto.getMaxLength(),"密码最大长度", |
| | | spsDto.getCombinations(),"组合方式种类", |
| | | spsDto.getRequireCharCount(),"必填种类", |
| | | spsDto.getValidDay(),"过期时间", |
| | | spsDto.getRemindDay(),"提醒时间", |
| | | spsDto.getRetryTime(),"重试次数", |
| | | spsDto.getLockTime(),"锁定时间" |
| | | ); |
| | | //密码策略合规校验,不合规会抛出错误 |
| | | this.checkPwdStrategy(spsDto); |
| | | //查询修改的策略是否存在 |
| | | Map<String, String> conditionMap = new HashMap<>(); |
| | | conditionMap.put("pluid",spsDto.getOid()); |
| | | List<SmPasswordStrategyVO> dbVoList = this.getPwdStrategyByCondition(conditionMap); |
| | | if(Func.isEmpty(dbVoList)){ |
| | | throw new VciBaseException("当前修改的密码策略在系统中不存在,请刷新后重试!"); |
| | | } |
| | | //获取当前用户账号信息 |
| | | String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(); |
| | | UserEntityInfo userEntityInfo = new UserEntityInfo(userId,null); |
| | | //根据策略名称查重 |
| | | conditionMap.clear(); |
| | | conditionMap.put("pname",spsDto.getName()); |
| | | conditionMap.put("pluid", QueryOptionConstant.NOTEQUAL + spsDto.getOid()); |
| | | List<SmPasswordStrategyVO> repeatVoList = this.getPwdStrategyByCondition(conditionMap); |
| | | if(Func.isNotEmpty(repeatVoList)){ |
| | | throw new VciBaseException("策略名称已经存在,请进行修改!"); |
| | | } |
| | | SmPasswordStrategyVO smPasswordStrategyVO = dbVoList.get(0); |
| | | spsDto.setCreateTime(smPasswordStrategyVO.getCreateTime()); |
| | | spsDto.setCreator(smPasswordStrategyVO.getCreator()); |
| | | spsDto.setLastModifier(userId); |
| | | //组合方式转换为存储值 |
| | | spsDto.setRequireCharType(combinations2Plchartypes(spsDto.getCombinations())); |
| | | PasswordStrategyInfo passwordStrategyInfo = changePasswordStrategyDTO2Info(spsDto); |
| | | return platformClientUtil.getFrameworkService().editPasswordStrategy(passwordStrategyInfo,userEntityInfo); |
| | | } |
| | | |
| | | /** |
| | | * 删除密码策略 |
| | | * @param pwdIds |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean delPasswordStrateg(String[] pwdIds) throws PLException { |
| | | VciBaseUtil.alertNotNull(pwdIds,"要删除的密码策略主键"); |
| | | //TODO: 应该是不具备连带删除的功能,策略删除后用户关联的无用策略信息还在,考虑后期是否需要做,数据量不大可以不做连带删除 |
| | | return platformClientUtil.getFrameworkService().deletePasswordStrategy( |
| | | pwdIds, |
| | | new UserEntityInfo("developer"/*WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId()*/, null) |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * 根据主键查询密码策略map对象 |
| | | * @param oidList |
| | | * @return key为密码策略主键 value为密码策略 |