Exemplo n.º 1
0
  public SysApplication findById(long id) {
    String cacheKey = "sys_app_" + id;

    if (SystemConfig.getBoolean("use_query_cache") && CacheFactory.getString(cacheKey) != null) {
      String text = CacheFactory.getString(cacheKey);
      com.alibaba.fastjson.JSONObject json = JSON.parseObject(text);
      SysApplication app = SysApplicationJsonFactory.jsonToObject(json);
      if (app != null && app.getNodeId() > 0) {
        SysTree node = sysTreeService.findById(app.getNodeId());
        app.setNode(node);
      }
      return app;
    }

    SysApplication app = sysApplicationMapper.getSysApplicationById(id);
    if (app != null && app.getNodeId() > 0) {
      SysTree node = sysTreeService.findById(app.getNodeId());
      app.setNode(node);
    }

    if (app != null && SystemConfig.getBoolean("use_query_cache")) {
      com.alibaba.fastjson.JSONObject json = app.toJsonObject();
      CacheFactory.put(cacheKey, json.toJSONString());
    }

    return app;
  }
Exemplo n.º 2
0
  public JSONArray getUserMenu(long parent, String actorId) {
    JSONArray array = new JSONArray();
    SysUser user = authorizeService.login(actorId);
    if (user != null) {
      List<SysTree> treeList = null;
      SysApplication app = this.findById(parent);
      SysTreeQuery query = new SysTreeQuery();
      query.treeId(app.getNode().getTreeId());
      query.treeIdLike(app.getNode().getTreeId() + "%");
      if (!user.isSystemAdmin()) {
        List<String> actorIds = new java.util.ArrayList<String>();
        List<Object> rows = entityService.getList("getAgents", actorId);
        if (rows != null && !rows.isEmpty()) {
          for (Object object : rows) {
            if (object instanceof Agent) {
              Agent agent = (Agent) object;
              if (!agent.isValid()) {
                continue;
              }
              switch (agent.getAgentType()) {
                case 0: // 全局代理
                  actorIds.add(agent.getAssignFrom());
                  break;
                default:
                  break;
              }
            }
          }
        }
        if (!actorIds.isEmpty()) {
          actorIds.add(actorId);
          query.setActorIds(actorIds);
        } else {
          query.setActorId(actorId);
        }
        treeList = sysTreeMapper.getTreeListByUsers(query);
      } else {
        treeList = sysTreeMapper.getTreeList(query);
      }

      List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>();
      for (SysTree tree : treeList) {
        if (StringUtils.isNotEmpty(tree.getUrl())) {
          if (StringUtils.startsWith(tree.getUrl(), "/")) {
            if (StringUtils.isNotEmpty(SystemConfig.getServiceUrl())) {
              String link = SystemConfig.getServiceUrl() + tree.getUrl();
              tree.setUrl(link);
            } else {
              String link = ApplicationContext.getContextPath() + tree.getUrl();
              tree.setUrl(link);
            }
          }
        }
        treeModels.add(tree);
      }
      TreeHelper treeHelper = new TreeHelper();
      array = treeHelper.getTreeJSONArray(treeModels);
      // logger.debug(array.toString('\n'));
    }
    return array;
  }
Exemplo n.º 3
0
  @RequestMapping("/jump")
  public void jump(HttpServletRequest request, HttpServletResponse response) {
    logger.debug("---------------------------jump----------------------");
    LoginContext loginContext = RequestUtils.getLoginContext(request);
    if (loginContext == null) {
      try {
        response.sendRedirect(request.getContextPath() + ViewProperties.getString("loginUrl"));
        return;
      } catch (Exception ex) {
      }
    }
    String menuId = request.getParameter("menuId");
    if (menuId != null) {
      menuId = RequestUtils.decodeString(menuId);
    }
    logger.debug("menuId:" + menuId);
    if (menuId != null && StringUtils.isNumeric(menuId)) {
      SysApplication app = sysApplicationService.findById(Long.parseLong(menuId));
      if (app != null) {
        boolean accessable = false;
        if (loginContext.isSystemAdministrator()) {
          accessable = true;
        } else {
          AuthorizeBean bean = new AuthorizeBean();
          SysUser sysUser = bean.getUser(loginContext.getActorId());
          if (sysUser != null) {
            accessable = sysUser.hasApplicationAccess(app.getId());
          }
        }
        logger.debug("accessable:" + accessable);
        if (accessable) {
          try {
            String url = app.getUrl();
            if (url != null) {
              if (!(url.toLowerCase().startsWith("http://")
                  || url.toLowerCase().startsWith("https://"))) {
                if (url.startsWith("/")) {
                  url = request.getContextPath() + url;
                } else {
                  url = request.getContextPath() + "/" + url;
                }
              }
              if (url.indexOf("?") != -1) {
                url = url + "&time=" + System.currentTimeMillis();
              } else {
                url = url + "?time=" + System.currentTimeMillis();
              }

              String key = SystemProperties.getDefaultSecurityKey();

              String actorId = SecurityUtils.encode(key, loginContext.getActorId());

              if (StringUtils.endsWithIgnoreCase(app.getLinkFileName(), ".cpt")) {
                url = SystemConfig.getString("report_service_url");
                String cpt_path = "fileId=" + app.getLinkFileId();
                String dsJson = DBConfiguration.encodeJsonCurrentSystem();
                if (url.indexOf("?") == -1) {
                  url = url + "?q=1";
                }
                url = url + "&" + cpt_path + "&datasourceJson=" + dsJson;
                if (app.getRefId1() != null) {
                  url = url + "&refId1=" + app.getRefId1() + "&treedot_index_id=" + app.getRefId1();
                }
                if (app.getRefId2() != null) {
                  url =
                      url + "&refId2=" + app.getRefId2() + "&treepinfo_index_id=" + app.getRefId2();
                }

                if (StringUtils.isNotEmpty(app.getLinkParam())) {
                  url = url + "&" + app.getLinkParam();
                }
              }

              if (StringUtils.endsWithIgnoreCase(app.getPrintFileName(), ".cpt")) {
                url = url + "&printFileId=" + app.getPrintFileId();
                if (StringUtils.isNotEmpty(app.getPrintParam())) {
                  url = url + "&" + app.getPrintParam();
                }
              }

              url = url + "&security_actorId=" + actorId;
              logger.debug(url);
              response.sendRedirect(url);
            } else {
              return;
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      }
    }
    try {
      request.getRequestDispatcher("/WEB-INF/views/404.jsp").forward(request, response);
    } catch (Exception e) {
    }
  }