Esempio n. 1
0
  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filter)
      throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;

    String contextPath = req.getContextPath();
    String fullURL = req.getRequestURI();
    String targetURL = "";
    if (fullURL.length() > 0) {
      targetURL = fullURL.substring(contextPath.length() + 1);
    }
    UserDetails userDetails = SecurityUtils.getLoginedPrincipal();
    if (userDetails != null) {
      User user = (User) userDetails;
      List<Menu> menus = new ArrayList<Menu>();
      Map<Long, List<Menu>> menuMap = user.getMenuMap();
      for (Entry<Long, List<Menu>> entry : menuMap.entrySet()) {
        menus.addAll(entry.getValue());
      }
      Menu target = null;
      for (Menu menu : menus) {
        if (targetURL.contains(menu.getUrl()) && StringUtils.isNotBlank(menu.getUrl())) {
          target = menu;
          break;
        }
      }
      if (target != null) {

        // find top menus
        Menu top = null;
        Menu menu = target;
        for (; ; ) {
          if (menu.getParentId() == -1) {
            top = menu;
            break;
          }
          menu = menuCache.getById(menu.getParentId());
        }
        List<Menu> curMenus = getCurMenuMap(top, user);
        req.setAttribute(Constant.ADMIN_USER_TOP_MENU_LIST, curMenus);
        req.setAttribute(Constant.ADMIN_USER_VISIT_TOP_MENU, top);
        req.setAttribute(Constant.ADMIN_USER_VISIT_MENU, target);
      }
    }
    filter.doFilter(request, response);
  }
Esempio n. 2
0
 private List<Menu> getCurMenuMap(Menu menu, User user) {
   List<Menu> curMenus = new ArrayList<Menu>();
   getCurMenus(menu, user.getMenuMap(), curMenus);
   return curMenus;
 }