Example #1
0
  public static ObjectNode toObjectNode(SysUser user) {
    ObjectNode jsonObject = new ObjectMapper().createObjectNode();

    jsonObject.put("actorId", user.getAccount());
    jsonObject.put("actorId_enc", RequestUtils.encodeString(user.getAccount()));
    jsonObject.put("userId", user.getAccount());
    jsonObject.put("userId_enc", RequestUtils.encodeString(user.getAccount()));

    jsonObject.put("name", user.getName());
    jsonObject.put("locked", user.getStatus());
    jsonObject.put("status", user.getStatus());

    if (user.getDepartment() != null) {
      jsonObject.put("deptId", user.getDepartment().getId());
      jsonObject.put("deptName", user.getDepartment().getName());
    } else {
      jsonObject.put("deptId", user.getDeptId());
    }

    jsonObject.put("accountType", user.getAccountType());
    jsonObject.put("userType", user.getUserType());
    jsonObject.put("dumpFlag", user.getDumpFlag());
    jsonObject.put("gender", user.getGender());
    jsonObject.put("evection", user.getEvection());
    jsonObject.put("superiorIds", user.getSuperiorIds());

    jsonObject.put("fax", user.getFax());
    jsonObject.put("telephone", user.getTelephone());
    jsonObject.put("headship", user.getHeadship());
    jsonObject.put("adminFlag", user.getAdminFlag());

    if (user.getEmail() != null) {
      jsonObject.put("mail", user.getEmail());
      jsonObject.put("email", user.getEmail());
    }
    if (user.getMobile() != null) {
      jsonObject.put("mobile", user.getMobile());
    }
    if (user.getLastLoginTime() != null) {
      jsonObject.put("lastLoginDate", DateUtils.getDateTime(user.getLastLoginDate()));
      jsonObject.put("lastLoginTime", DateUtils.getDateTime(user.getLastLoginDate()));
    }
    if (user.getLastLoginIP() != null) {
      jsonObject.put("loginIP", user.getLastLoginIP());
    }

    if (user.getCreateBy() != null) {
      jsonObject.put("createBy", user.getCreateBy());
    }
    if (user.getUpdateBy() != null) {
      jsonObject.put("updateBy", user.getUpdateBy());
    }
    if (user.getUpdateDate() != null) {
      jsonObject.put("updateDate", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_date", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_datetime", DateUtils.getDateTime(user.getUpdateDate()));
    }

    if (user.getUserRoles() != null && !user.getUserRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysUserRole sysUserRole : user.getUserRoles()) {
        array.add(sysUserRole.toObjectNode());
      }
      jsonObject.set("userRoles", array);
    }

    if (user.getRoles() != null && !user.getRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysRole sysRole : user.getRoles()) {
        array.add(sysRole.toObjectNode());
      }
      jsonObject.set("roles", array);
    }

    if (user.getFunctions() != null && !user.getFunctions().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysFunction sysFunction : user.getFunctions()) {
        array.add(sysFunction.toObjectNode());
      }
      // jsonObject.set("functions", array);
    }

    if (user.getApps() != null && !user.getApps().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysApplication app : user.getApps()) {
        array.add(app.toObjectNode());
      }
      // jsonObject.set("apps", array);
    }

    return jsonObject;
  }
Example #2
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) {
    }
  }