com.jeesuite.common.JeesuiteBaseException Java Examples
The following examples show how to use
com.jeesuite.common.JeesuiteBaseException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlobalExceptionHandler.java From jeesuite-config with Apache License 2.0 | 6 votes |
@ExceptionHandler(Exception.class) @ResponseBody public ResponseEntity<WrapperResponseEntity> exceptionHandler(Exception e, HttpServletResponse response) { WrapperResponseEntity resp = new WrapperResponseEntity(); while(e.getCause() != null){ e = (Exception) e.getCause(); } if (e instanceof JeesuiteBaseException) { JeesuiteBaseException e1 = (JeesuiteBaseException) e; resp.setCode(e1.getCode()); resp.setMsg(e1.getMessage()); } else if(e instanceof org.springframework.web.HttpRequestMethodNotSupportedException){ resp.setCode(HttpStatus.METHOD_NOT_ALLOWED.value()); resp.setMsg(e.getMessage()); }else if(e instanceof org.springframework.web.HttpMediaTypeException){ resp.setCode(HttpStatus.UNSUPPORTED_MEDIA_TYPE.value()); resp.setMsg(e.getMessage()); }else { resp.setCode(500); resp.setMsg("系统繁忙"); logger.error("",e); } return new ResponseEntity<WrapperResponseEntity>(resp,HttpStatus.OK); }
Example #2
Source File: ConfigAdminController.java From jeesuite-config with Apache License 2.0 | 6 votes |
@RequestMapping(value = "upload", method = RequestMethod.POST) public ResponseEntity<Object> uploadConfigFile(@RequestParam("file") MultipartFile file){ String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase(); if(!allow_upload_suffix.contains(suffix)){ throw new JeesuiteBaseException(9999, "支持上传文件类型:"+Arrays.toString(allow_upload_suffix.toArray())); } try { Map<String, String> result = new HashMap<>(); result.put("fileName", file.getOriginalFilename()); result.put("content", new String(file.getBytes(), StandardCharsets.UTF_8)); return new ResponseEntity<Object>(new WrapperResponseEntity(result),HttpStatus.OK); } catch (Exception e) { throw new JeesuiteBaseException(9999, "上传失败"); } }
Example #3
Source File: UserAdminController.java From jeesuite-config with Apache License 2.0 | 6 votes |
@RequestMapping(value = "update", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> modifyPassword(@RequestBody UpdateUserRequest param){ UserEntity entity = userMapper.selectByPrimaryKey(SecurityUtil.getLoginUserInfo().getId()); if(entity.getName().equals("test")){ throw new JeesuiteBaseException(1001, "测试账号不允许编辑"); } if(StringUtils.isNotBlank(param.getEmail()))entity.setEmail(param.getEmail()); if(StringUtils.isNotBlank(param.getMobile()))entity.setMobile(param.getMobile()); if(StringUtils.isNotBlank(param.getPassword())){ String oldPassword = UserEntity.encryptPassword(param.getOldPassword()); if(!StringUtils.equals(entity.getPassword(), oldPassword)){ throw new JeesuiteBaseException(1001, "原密码不正确"); } entity.setPassword(UserEntity.encryptPassword(param.getPassword())); } entity.setUpdatedAt(new Date()); userMapper.updateByPrimaryKeySelective(entity); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK); }
Example #4
Source File: UserAdminController.java From jeesuite-config with Apache License 2.0 | 6 votes |
@RequestMapping(value = "add", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> addUser(@RequestBody UserEntity param){ SecurityUtil.requireSuperAdmin(); if(StringUtils.isAnyBlank(param.getName(),param.getMobile())){ throw new JeesuiteBaseException(1001, "用户名/手机号不能为空"); } if(userMapper.findByName(param.getName()) != null){ throw new JeesuiteBaseException(1001, "用户名已存在"); } if(userMapper.findByMobile(param.getMobile()) != null){ throw new JeesuiteBaseException(1001, "手机号已存在"); } param.setPassword(UserEntity.encryptPassword(param.getMobile().substring(3))); param.setStatus((short)1); param.setType((short)2); param.setCreatedAt(new Date()); userMapper.insertSelective(param); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(param),HttpStatus.OK); }
Example #5
Source File: AppAdminController.java From jeesuite-config with Apache License 2.0 | 6 votes |
@RequestMapping(value = "update", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> updateApp(@RequestBody AddOrEditAppRequest addAppRequest){ SecurityUtil.requireSuperAdmin(); AppEntity app = appMapper.selectByPrimaryKey(addAppRequest.getId()); if(app == null){ throw new JeesuiteBaseException(1002, "应用不存在"); } AppEntity appEntity = BeanUtils.copy(addAppRequest, AppEntity.class); if(addAppRequest.getMasterUid() != null && addAppRequest.getMasterUid() > 0 && !addAppRequest.getMasterUid().equals(app.getMasterUid())){ UserEntity master = userMapper.selectByPrimaryKey(addAppRequest.getMasterUid()); appEntity.setMaster(master.getName()); } appMapper.updateByPrimaryKeySelective(appEntity); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK); }
Example #6
Source File: AppAdminController.java From jeesuite-config with Apache License 2.0 | 6 votes |
@RequestMapping(value = "add", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> addApp(@RequestBody AddOrEditAppRequest addAppRequest){ SecurityUtil.requireSuperAdmin(); if(addAppRequest.getMasterUid() == null || addAppRequest.getMasterUid() == 0){ throw new JeesuiteBaseException(1002, "请选择项目负责人"); } if(appMapper.findByName(addAppRequest.getName()) != null){ throw new JeesuiteBaseException(1002, "应用["+addAppRequest.getName()+"]已存在"); } AppEntity appEntity = BeanUtils.copy(addAppRequest, AppEntity.class); // UserEntity master = userMapper.selectByPrimaryKey(addAppRequest.getMasterUid()); appEntity.setMaster(master.getName()); appMapper.insertSelective(appEntity); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK); }
Example #7
Source File: PermissionController.java From oneplatform with Apache License 2.0 | 6 votes |
@RequestMapping(value = "perm/batch_create", method = RequestMethod.POST) public @ResponseBody WrapperResponse<String> batchCreatePermResources(HttpServletRequest request,@RequestBody BatchCreateResourceParam param){ String[] menuNames = StringUtils.splitByWholeSeparator(param.getMenuName(), ">"); if(param.getApis() == null)throw new JeesuiteBaseException(400,"请填写关联接口"); for (int i = 0; i < param.getApis().size(); i++) { ApiDefine apiDefine = param.getApis().get(i); if(StringUtils.isAnyBlank(apiDefine.getMethod(),apiDefine.getName(),apiDefine.getUri())){ param.getApis().remove(i); i--; } } if(param.getApis().isEmpty())throw new JeesuiteBaseException(400,"请完整填写关联接口"); permissionService.batchCreatePermResources(param.getPlatformType(), menuNames, param.getMenuUri(), param.getApis()); boolean jsonSubmit = Boolean.parseBoolean(request.getParameter("jsonSubmit")); return new WrapperResponse<>(jsonSubmit == false ? JsonUtils.toPrettyJson(param) : null); }
Example #8
Source File: CompanyService.java From oneplatform with Apache License 2.0 | 6 votes |
public void addCompany(CompanyEntity entity) { CompanyEntity headCompany = companyMapper.findHeadCompany(); if(headCompany == null){ entity.setIsBranch(false); }else{ entity.setIsBranch(true); CompanyEntity sameNameCompany = companyMapper.findByName(entity.getName()); if(sameNameCompany != null){ if(sameNameCompany.getInActive())throw new JeesuiteBaseException(ExceptionCode.RECORD_EXISTED.code,"该子公司已存在"); BeanUtils.copy(entity, sameNameCompany); sameNameCompany.setInActive(true); companyMapper.updateByPrimaryKeySelective(sameNameCompany); return ; } } companyMapper.insertSelective(entity); }
Example #9
Source File: DepartmentController.java From oneplatform with Apache License 2.0 | 6 votes |
@ApiOperation(value = "保存") @RequestMapping(value = "save", method = RequestMethod.POST) public @ResponseBody WrapperResponse<String> addDepartment(@RequestBody DepartmentParam param) { if(param.getCompanyId() == null || param.getCompanyId() == 0){ throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_REQUIRED.code, "请先选择公司"); } DepartmentEntity entity = BeanUtils.copy(param, DepartmentEntity.class); if (param.getId() == null || param.getId() == 0) { entity.setCreatedAt(new Date()); entity.setCreatedBy(LoginContext.getIntFormatUserId()); departmentService.addDepartment(entity); } else { entity.setUpdatedAt(new Date()); entity.setUpdatedBy(LoginContext.getIntFormatUserId()); departmentService.updateDepartment(entity); } return new WrapperResponse<>(); }
Example #10
Source File: EmployeeController.java From oneplatform with Apache License 2.0 | 6 votes |
@ApiOperation(value = "新增") @RequestMapping(value = "add", method = RequestMethod.POST) public @ResponseBody WrapperResponse<String> addEmployee(@RequestBody EmployeeParam param) { if(param.getDepartmentId() == null || param.getDepartmentId() == 0){ throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_REQUIRED.code, "请先选择所在部门"); } if(param.getPositionId() == null || param.getPositionId() == 0){ throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_REQUIRED.code, "请先选择职位"); } EmployeeEntity entity = BeanUtils.copy(param, EmployeeEntity.class); entity.setCreatedAt(new Date()); entity.setCreatedBy(LoginContext.getIntFormatUserId()); employeeService.addEmployee(entity,param.getDepartmentId(),param.getPositionId()); return new WrapperResponse<>(); }
Example #11
Source File: AuthController.java From jeesuite-config with Apache License 2.0 | 5 votes |
@RequestMapping(value = "login", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> login(HttpServletRequest request,@RequestBody Map<String, String> params){ String userName = StringUtils.trimToEmpty(params.get("userName")); String password = StringUtils.trimToEmpty(params.get("password")); UserEntity userEntity = FormatValidateUtils.isMobile(userName) ? userMapper.findByMobile(userName) : userMapper.findByName(userName); if(userEntity == null || !userEntity.getPassword().equals(UserEntity.encryptPassword(password))){ return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(4001, "账号或密码错误"),HttpStatus.OK); } LoginUserInfo loginUserInfo = new LoginUserInfo(userEntity.getName()); loginUserInfo.setSuperAdmin(userEntity.getType().intValue() == 1); loginUserInfo.setId(userEntity.getId()); if(!loginUserInfo.isSuperAdmin()){ if(userEntity.getStatus() != 1){ throw new JeesuiteBaseException(1001, "该账号已停用"); } //加载权限 List<UserPermissionEntity> userPermissions = userPermissionMapper.findByUserId(userEntity.getId()); List<String> permCodes; for (UserPermissionEntity entity : userPermissions) { permCodes = loginUserInfo.getPermissonData().get(entity.getEnv()); if(permCodes == null){ loginUserInfo.getPermissonData().put(entity.getEnv(), permCodes = new ArrayList<>()); } permCodes.add(entity.toPermissionCode()); // if(!loginUserInfo.getGrantAppIds().contains(entity.getAppId())){ loginUserInfo.getGrantAppIds().add(entity.getAppId()); } } } request.getSession().setAttribute(Constants.LOGIN_SESSION_KEY, loginUserInfo); logger.info(">>PermissonData:{}", JsonUtils.toJson(loginUserInfo.getPermissonData())); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(loginUserInfo),HttpStatus.OK); }
Example #12
Source File: SensitiveOperProtectHandler.java From jeesuite-libs with Apache License 2.0 | 5 votes |
@Override public Object onInterceptor(Invocation invocation) throws Throwable { Object[] objects = invocation.getArgs(); MappedStatement ms = (MappedStatement) objects[0]; if(ms.getSqlCommandType().equals(SqlCommandType.DELETE)){ throw new JeesuiteBaseException(4003, "当前已开启敏感操作保护"); } return null; }
Example #13
Source File: ConfigAdminController.java From jeesuite-config with Apache License 2.0 | 5 votes |
@RequestMapping(value = "add", method = RequestMethod.POST) @Transactional public ResponseEntity<WrapperResponseEntity> addConfig(@RequestBody AddOrEditConfigRequest addRequest){ if(!addRequest.getGlobal() && addRequest.getAppIds() == null){ throw new JeesuiteBaseException(4001,"非全局绑定应用不能为空"); } if(StringUtils.isBlank(addRequest.getEnv())){ throw new JeesuiteBaseException(4001,"绑定环境profile不能为空"); } if(addRequest.getType().intValue() == 2 && StringUtils.isBlank(addRequest.getName())){ throw new JeesuiteBaseException(4001,"配置项名称不能空"); } if(addRequest.getGlobal()){ SecurityUtil.requireSuperAdmin(); }else{ SecurityUtil.requireAllPermission(addRequest.getEnv(),addRequest.getAppIds(),GrantOperate.RW); } // if(StringUtils.isNotBlank(addRequest.getName()) // && appconfigMapper.findSameByName(addRequest.getEnv(), appId, addRequest.getName()) != null){ // throw new JeesuiteBaseException(4001,"配置名称已经存在"); // } AppconfigEntity entity = BeanUtils.copy(addRequest, AppconfigEntity.class); entity.setAppIds(StringUtils.join(addRequest.getAppIds(),",")); entity.setCreatedBy(SecurityUtil.getLoginUserInfo().getName()); entity.setCreatedAt(new Date()); entity.setUpdatedAt(entity.getCreatedAt()); entity.setUpdatedBy(entity.getCreatedBy()); encryptPropItemIfRequired(entity); // appconfigMapper.insertSelective(entity); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK); }
Example #14
Source File: CustomResponseErrorHandler.java From jeesuite-libs with Apache License 2.0 | 5 votes |
@Override public void handleError(ClientHttpResponse response) throws IOException { int code = response.getRawStatusCode(); String content = CharStreams.toString(new InputStreamReader(response.getBody(), StandardCharsets.UTF_8)); Map<?, ?> responseItmes = null; if(code == 404 && StringUtils.isNotBlank(content)){ responseItmes = JsonUtils.toObject(content, Map.class); throw new JeesuiteBaseException(404, "Page Not Found["+responseItmes.get("path")+"]"); } int errorCode = 500; String errorMsg = content; try {responseItmes = JsonUtils.toObject(content, Map.class);} catch (Exception e) {} if(responseItmes != null){ if(responseItmes.containsKey("code")){ errorCode = Integer.parseInt(responseItmes.get("code").toString()); } if(responseItmes.containsKey("msg")){ errorMsg = responseItmes.get("msg").toString(); }else if(responseItmes.containsKey("message")){ errorMsg = responseItmes.get("message").toString(); } } if(StringUtils.isBlank(errorMsg)){ errorMsg = DEFAULT_ERROR_MSG; } throw new JeesuiteBaseException(errorCode, errorMsg + "(Remote)"); }
Example #15
Source File: TokenGenerator.java From jeesuite-libs with Apache License 2.0 | 5 votes |
/** * 验证带签名信息的token */ public static void validate(String tokenType,String token,boolean validateExpire){ long timestamp = 0; Date date = new Date(); String cryptKey = getCryptKey(tokenType,date); try { timestamp = Long.parseLong(DES.decrypt(cryptKey,token).substring(6)); } catch (Exception e) { throw new JeesuiteBaseException(4005, "authToken错误"); } if(validateExpire && date.getTime() - timestamp > EXPIRE){ throw new JeesuiteBaseException(4005, "token已过期"); } }
Example #16
Source File: ConfigAdminController.java From jeesuite-config with Apache License 2.0 | 5 votes |
@Transactional @RequestMapping(value = "update", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> updateConfig(@RequestBody AddOrEditConfigRequest addRequest){ if(addRequest.getId() == null || addRequest.getId() == 0){ throw new JeesuiteBaseException(1003, "id参数缺失"); } AppconfigEntity entity = appconfigMapper.selectByPrimaryKey(addRequest.getId()); if(!entity.getGlobal() && addRequest.getAppIds() == null){ throw new JeesuiteBaseException(4001,"非全局绑定应用不能为空"); } if(entity.getGlobal()){ SecurityUtil.requireSuperAdmin(); }else{ SecurityUtil.requireAllPermission(entity.getEnv(),addRequest.getAppIds(),GrantOperate.RW); } // saveAppConfigHistory(entity); entity.setAppIds(StringUtils.join(addRequest.getAppIds(),",")); entity.setVersion(addRequest.getVersion()); String orignContents = entity.getContents(); entity.setContents(addRequest.getContents()); // encryptPropItemIfRequired(entity); entity.setUpdatedBy(SecurityUtil.getLoginUserInfo().getName()); entity.setUpdatedAt(new Date()); appconfigMapper.updateByPrimaryKeySelective(entity); // publishConfigChangeEvent(orignContents,entity); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK); }
Example #17
Source File: ProfileAdminController.java From jeesuite-config with Apache License 2.0 | 5 votes |
@RequestMapping(value = "add", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> addProfile(@RequestBody ProfileEntity param){ SecurityUtil.requireSuperAdmin(); ProfileEntity entity = profileMapper.findByName(param.getName()); if(entity != null)throw new JeesuiteBaseException(1002, "Profile["+param.getName()+"]已存在"); profileMapper.insertSelective(param); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK); }
Example #18
Source File: ProfileAdminController.java From jeesuite-config with Apache License 2.0 | 5 votes |
@RequestMapping(value = "update", method = RequestMethod.POST) public ResponseEntity<WrapperResponseEntity> updateProfile(@RequestBody ProfileEntity param){ SecurityUtil.requireSuperAdmin(); if(param.getId() == null || param.getId() == 0){ throw new JeesuiteBaseException(1003, "id参数缺失"); } ProfileEntity entity = profileMapper.selectByPrimaryKey(param.getId()); entity.setAlias(param.getAlias()); entity.setName(param.getName()); profileMapper.updateByPrimaryKey(entity); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK); }
Example #19
Source File: ProfileAdminController.java From jeesuite-config with Apache License 2.0 | 5 votes |
@RequestMapping(value = "delete/{id}", method = RequestMethod.GET) public ResponseEntity<WrapperResponseEntity> deleteProfile(@PathVariable("id") Integer id){ SecurityUtil.requireSuperAdmin(); ProfileEntity entity = profileMapper.selectByPrimaryKey(id); if(entity.getIsDefault())throw new JeesuiteBaseException(1003, "默认profile不能删除"); profileMapper.deleteByPrimaryKey(id); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(),HttpStatus.OK); }
Example #20
Source File: CryptComponent.java From jeesuite-config with Apache License 2.0 | 5 votes |
private static String decryptWithAES(String key, String data){ try { String secretKey = DigestUtils.md5(key).substring(16); byte[] bytes = AES.decrypt(Base64.decode(data.getBytes(StandardCharsets.UTF_8)), secretKey.getBytes(StandardCharsets.UTF_8)); return new String(bytes, StandardCharsets.UTF_8); } catch (Exception e) { throw new JeesuiteBaseException(9999, "解密失败"); } }
Example #21
Source File: SHA1.java From jeesuite-libs with Apache License 2.0 | 5 votes |
/** * <p> * 用SHA1算法生成安全签名 * </p> * * @param token * 票据 * @param timestamp * 时间戳 * @param nonce * 随机字符串 * @param encrypt * 密文 * @return 安全签名 * * @throws AESException {@link AESException} */ public static String getSHA1(String token, String timestamp, String nonce, String encrypt) { try { String[] array = new String[]{token, timestamp, nonce, encrypt}; StringBuffer sb = new StringBuffer(); /* 字符串排序 */ Arrays.sort(array); for (int i = 0; i < 4; i++) { sb.append(array[i]); } /* SHA1签名生成 */ MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(sb.toString().getBytes()); byte[] digest = md.digest(); StringBuffer hexstr = new StringBuffer(); String shaHex = ""; for (int i = 0; i < digest.length; i++) { shaHex = Integer.toHexString(digest[i] & 0xFF); if (shaHex.length() < 2) { hexstr.append(0); } hexstr.append(shaHex); } return hexstr.toString(); } catch (Exception e) { throw new JeesuiteBaseException(500, "error", e); } }
Example #22
Source File: AuthController.java From jeesuite-config with Apache License 2.0 | 5 votes |
@RequestMapping(value = "update_safe_ipaddr", method = RequestMethod.POST) public @ResponseBody ResponseEntity<WrapperResponseEntity> updateSafeIpaddr(HttpServletRequest request,@RequestParam("authcode") String authcode){ SecurityUtil.requireSuperAdmin(); // if(StringUtils.isBlank(authcode))throw new JeesuiteBaseException(411, "安全码不能为空"); if(!authcode.equals(EnvironmentHelper.getProperty("sensitive.operation.authcode")))throw new JeesuiteBaseException(411, "安全码错误"); String ipAddr = IpUtils.getIpAddr(request); SecurityInterceptor.setIpWhiteList(ipAddr); return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(ipAddr),HttpStatus.OK); }
Example #23
Source File: ReadOnlyForTestProtectHandler.java From jeesuite-config with Apache License 2.0 | 5 votes |
@Override public Object onInterceptor(Invocation invocation) throws Throwable { Object[] objects = invocation.getArgs(); MappedStatement ms = (MappedStatement) objects[0]; if(!ms.getSqlCommandType().equals(SqlCommandType.SELECT)){ if(SecurityUtil.getLoginUserInfo().getName().startsWith("test")){ throw new JeesuiteBaseException(4003, "测试账号已开启敏感操作保护"); } } return null; }
Example #24
Source File: WinxinUserSerivce.java From oneplatform with Apache License 2.0 | 5 votes |
public Integer findUserIdByWeAppCode(String group,String code){ final WxMaService wxService = weixinAppManager.getMaService(group); try { WxMaJscode2SessionResult wxsession = wxService.getUserService().getSessionInfo(code); Integer userId = findUserIdByOpenId(wxsession.getOpenid()); return userId; } catch (WxErrorException e) { throw new JeesuiteBaseException(500, e.getMessage()); } }
Example #25
Source File: ConfigParseUtils.java From jeesuite-config with Apache License 2.0 | 5 votes |
private static void parseDataFromXML(Map<String, Object> result, String xmlContents) { Document doc = null; try { //doc = DocumentHelper.parseText(xmlContents); SAXReader reader = new SAXReader(); //忽略dtd验证 reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); InputSource source = new InputSource(new StringReader(xmlContents)); source.setEncoding("UTF-8"); doc = reader.read(source); Element rootElt = doc.getRootElement(); Iterator<?> iter = rootElt.elementIterator("entry"); // 遍历head节点 while (iter.hasNext()) { Element elm = (Element) iter.next(); String stringValue = elm.getStringValue(); if(StringUtils.isNotBlank(stringValue)){ result.put(elm.attribute("key").getStringValue(), stringValue.trim()); } } } catch (Exception e) { if(e instanceof org.dom4j.DocumentException){ throw new JeesuiteBaseException(500, "xml文件内容格式错误"); } throw new RuntimeException(e); } }
Example #26
Source File: ConfigParseUtils.java From jeesuite-config with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private static void parseDataFromYaml(Map<String, Object> result, String yamlContents) { Yaml yaml = new Yaml(); try { Map map = yaml.load(yamlContents); parseYamlInnerMap(null, result, map); } catch (Exception e) { e.printStackTrace(); throw new JeesuiteBaseException(500, "文件内容格式错误"); } }
Example #27
Source File: SecurityUtil.java From jeesuite-config with Apache License 2.0 | 5 votes |
public static void requireAnyPermission(String env,List<String> appIds,GrantOperate operate){ if(StringUtils.isBlank(env))throw new JeesuiteBaseException(1001, "profile字段缺失"); LoginUserInfo userInfo = getLoginUserInfo(); if(userInfo.isSuperAdmin())return; List<String> permCodes = userInfo.getPermissonData().get(env); if(permCodes == null)throw new JeesuiteBaseException(403, "你没有该项目权限"); if (appIds != null) { for (String appId : appIds) { if(permCodes.contains(buildPermissionCode(env, appId, operate))){ return; } } throw new JeesuiteBaseException(403, "你没有该项目权限"); } }
Example #28
Source File: SecurityUtil.java From jeesuite-config with Apache License 2.0 | 5 votes |
public static void requireAllPermission(String env,List<String> appIds,GrantOperate operate){ if(StringUtils.isBlank(env))throw new JeesuiteBaseException(1001, "字段[env]必填"); LoginUserInfo userInfo = getLoginUserInfo(); if(userInfo.isSuperAdmin())return; List<String> permCodes = userInfo.getPermissonData().get(env); if(permCodes == null)throw new JeesuiteBaseException(403, "你没有该项目权限"); for (String appId : appIds) { if(!permCodes.contains(buildPermissionCode(env, appId, operate))){ throw new JeesuiteBaseException(403, "你没有appId["+appId+"]在环境["+env+"]权限"); } } }
Example #29
Source File: CryptComponent.java From jeesuite-config with Apache License 2.0 | 5 votes |
private static String encryptWithAES(String key, String data){ try { String secretKey = DigestUtils.md5(key).substring(16); byte[] bytes = AES.encrypt(data.getBytes(StandardCharsets.UTF_8), secretKey.getBytes(StandardCharsets.UTF_8)); return Base64.encodeToString(bytes, false); } catch (Exception e) { throw new JeesuiteBaseException(9999, "加密失败"); } }
Example #30
Source File: SecurityCryptUtils.java From oneplatform with Apache License 2.0 | 5 votes |
public static void validateAuthCode(String authCode,boolean validateExpire){ long timestamp = 0; try { timestamp = Long.parseLong(SecurityCryptUtils.decrypt(authCode).substring(6)); } catch (Exception e) { throw new JeesuiteBaseException(4005, "authToken格式不正确"); } if(validateExpire && System.currentTimeMillis() - timestamp > EXPIRE){ throw new JeesuiteBaseException(4005, "authToken过期"); } }