private void renderSubMenus( Module module, StringBuffer datas, String contextpath, String target, AccessControl control, String selectedID, String framepath, int current_level, String tokenurl) { // String tokenurl = request.getContextPath() + "/token/getParameterToken.freepage"; if (!module.isUsed()) { return; } if (!module.isShowleftmenu()) { if (module.getUrl() == null) { datas .append("<li><a href=\"#\"><span></span><div>") .append(module.getName(request)) .append("</div></a>"); } else // 如果配置了链接,就必须要能够将链接显示出来 { String mname = module.getName(request); String url = MenuHelper.getModuleUrl(module, contextpath, control); datas .append("<li><a href=\"#\" ") .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(selectedID) .append("','") .append(url) .append("','") .append(target) .append("',") .append(module.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a>"); } } else { if (target.equals("mainFrame")) { boolean hasson = module.hasSonOfModule(); String mname = module.getName(request); if (hasson) { datas .append("<li><a href=\"#\" ") .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(selectedID) .append("','") .append(framepath) .append("?") .append(MenuHelper.sanymenupath) .append("=") .append(module.getPath()) .append("','") .append(target) .append("',") .append(module.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a>"); } else // 没有儿子的情况处理 { if (module.getUrl() == null) { datas .append("<li><a href=\"#\"><span></span><div>") .append(mname) .append("</div></a>"); } else // 如果配置了链接,就必须要能够将链接显示出来 { String url = MenuHelper.getModuleUrl(module, contextpath, control); datas .append("<li><a href=\"#\" ") .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(selectedID) .append("','") .append(url) .append("','") .append(target) .append("',") .append(module.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a>"); } } } else { datas .append("<li><a href=\"#\" ") .append("\" onClick=\"navto_sany_MenuItem_window('") .append(tokenurl) .append("','") .append(module.getName(request)) .append("','") .append(selectedID) .append("','") .append(module.getPath()) .append("','") .append(contextpath) .append("','") .append(target) .append("')\">") .append(module.getName(request)) .append("</a>"); } } if (current_level < level) { datas.append("<ul>"); // class=\"third\" current_level++; ModuleQueue submodules = module.getSubModules() != null ? module.getSubModules() : null; for (int j = 0; submodules != null && j < submodules.size(); j++) { Module submodule = submodules.getModule(j); String target_ = submodule.getTarget() == null ? "mainFrame" : submodule.getTarget(); renderSubMenus( submodule, datas, contextpath, target_, control, selectedID, framepath, current_level, tokenurl); } ItemQueue subitems = module.getItems() != null ? module.getItems() : null; for (int j = 0; subitems != null && j < subitems.size(); j++) { Item subitem = subitems.getItem(j); String area = subitem.getArea(); String target_ = subitem.getTarget() == null ? "mainFrame" : subitem.getTarget(); if (target.equals("mainFrame")) { String mname = subitem.getName(request); String url = MenuHelper.getItemUrl(subitem, contextpath, framepath, control); datas .append("<li><a href=\"#\" id=\"anchor_") .append(subitem.getId()) .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(selectedID) .append("','") .append(url) .append("','") .append(target_) .append("',") .append(subitem.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a></li>"); } else { datas .append("<li><a href=\"#\" id=\"anchor_") .append(subitem.getId()) .append("\" onClick=\"navto_sany_MenuItem_window('") .append(tokenurl) .append("','") .append(subitem.getName(request)) .append("','") .append(selectedID) .append("','") .append(subitem.getPath()) .append("','") .append(contextpath) .append("','") .append(target_) .append("')\">") .append(subitem.getName(request)) .append("</a></li>"); } } datas.append("</ul>"); } datas.append("</li>"); }
@Override public int doStartTag() throws JspException { int ret = super.doStartTag(); AccessControl control = AccessControl.getAccessControl(); MenuHelper menuHelper = MenuHelper.getMenuHelper(request); String tokenurl = request.getContextPath() + "/token/getParameterToken.freepage"; String personcenter = Framework.getInstance(control.getCurrentSystemID()) .getMessage( "sany.pdp.module.personcenter", RequestContextUtils.getRequestContextLocal(request)); StringBuffer datas = new StringBuffer(); String selectedmenuid = request.getParameter(MenuHelper.sanyselectedmodule); // 查找选择的菜单项path datas.append(header); String contextpath = request.getContextPath(); ItemQueue itemQueue = menuHelper.getItems(); ModuleQueue moduleQueue = menuHelper.getModules(); Item publicitem = menuHelper.getPublicItem(); String framepath = web != null && web.equals("true") ? contextpath + "/sanydesktop/webframe.page" : contextpath + "/sanydesktop/frame.page"; if (publicitem != null && publicitem.isMain()) { String target = publicitem.getTarget() == null ? "mainFrame" : publicitem.getTarget(); String url = MenuHelper.getRealUrl( contextpath, publicitem.getWorkspacecontentExtendAttribute("isany")); String selectedclass = ""; if (selectedmenuid == null || selectedmenuid.equals("publicitem")) { selectedclass = "class=\"select\""; } String mname = publicitem.getName(request); if (target.equals("mainFrame")) { // tokenurl datas .append("<li><a href=\"#\" id=\"anchor_") .append("publicitem") .append("\" ") .append(selectedclass) .append(" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append("publicitem") .append("','") .append(url) .append("','") .append(target) .append("',") .append(publicitem.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a></li>"); } else { datas .append("<li><a href=\"#\" id=\"anchor_") .append("publicitem") .append("\" ") .append(selectedclass) .append(" onClick=\"navto_sany_MenuItem_window('") .append(tokenurl) .append("','") .append(publicitem.getName(request)) .append("','") .append("publicitem") .append("','','") .append(contextpath) .append("','") .append(target) .append("')\">") .append(mname) .append("</a></li>"); } } for (int i = 0; moduleQueue != null && i < moduleQueue.size(); i++) { Module module = moduleQueue.getModule(i); if (!module.isUsed()) { continue; } String selectedclass = ""; if (selectedmenuid != null && selectedmenuid.startsWith(module.getId())) { selectedclass = "class=\"select\""; } if (!module.isShowleftmenu()) { if (module.getUrl() == null) { datas .append("<li><a id=\"anchor_") .append(module.getId()) .append("\" ") .append(selectedclass) .append(" href=\"#\">") .append(module.getName(request)) .append("</a>"); } else { String target = module.getTarget() == null ? "mainFrame" : module.getTarget(); String url = MenuHelper.getModuleUrl(module, contextpath, control); { String mname = module.getName(request); datas .append("<li><a href=\"#\" ") .append(selectedclass) .append(" id=\"anchor_") .append(module.getId()) .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(module.getId()) .append("','") .append(url) .append("','") .append(target) .append("',") .append(module.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a>"); } } } else { String target = module.getTarget() == null ? "mainFrame" : module.getTarget(); if (target.equals("mainFrame")) { boolean hasson = module.hasSonOfModule(); String mname = module.getName(request); if (hasson) { datas .append("<li><a href=\"#\" ") .append(selectedclass) .append(" id=\"anchor_") .append(module.getId()) .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(module.getId()) .append("','") .append(framepath) .append("?") .append(MenuHelper.sanymenupath) .append("=") .append(module.getPath()) .append("','") .append(target) .append("',") .append(module.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a>"); } else { if (module.getUrl() == null) { datas .append("<li><a id=\"anchor_") .append(module.getId()) .append("\" ") .append(selectedclass) .append(" href=\"#\">") .append(module.getName(request)) .append("</a>"); } else { String url = MenuHelper.getModuleUrl(module, contextpath, control); { datas .append("<li><a href=\"#\" ") .append(selectedclass) .append(" id=\"anchor_") .append(module.getId()) .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(module.getId()) .append("','") .append(url) .append("','") .append(target) .append("',") .append(module.getOption()) .append(",'") .append(mname) .append("')\">") .append(mname) .append("</a>"); } } } } else { datas .append("<li><a href=\"#\" ") .append(selectedclass) .append(" id=\"anchor_") .append(module.getId()) .append("\" onClick=\"navto_sany_MenuItem_window('") .append(tokenurl) .append("','") .append(module.getName(request)) .append("','") .append(module.getId()) .append("','") .append(module.getPath()) .append("','") .append(contextpath) .append("','") .append(target) .append("')\">") .append(module.getName(request)) .append("</a>"); } } datas.append("<ul >"); // class=\"second\" ItemQueue subitems = module.getItems() != null ? module.getItems() : null; for (int j = 0; subitems != null && j < subitems.size(); j++) { Item subitem = subitems.getItem(j); String target = subitem.getTarget() == null ? "mainFrame" : subitem.getTarget(); if (target.equals("mainFrame")) { String mname = subitem.getName(request); String url = MenuHelper.getItemUrl(subitem, contextpath, framepath, control); datas .append("<li><a id=\"anchor_") .append(subitem.getId()) .append("\" href=\"#\" onclick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append(module.getId()) .append("','") .append(url) .append("','") .append(target) .append("',") .append(subitem.getOption()) .append(",'") .append(mname) .append("')\"><span></span>") .append("<div>") .append(mname) .append("</div>") .append("</a></li>"); } else { datas .append("<li><a id=\"anchor_") .append(subitem.getId()) .append("\" href=\"#\" onclick=\"navto_sany_MenuItem_window('") .append(tokenurl) .append("','") .append(subitem.getName(request)) .append("','") .append(module.getId()) .append("','") .append(subitem.getPath()) .append("','") .append(contextpath) .append("','") .append(target) .append("')\"><span></span>") .append("<div>") .append(subitem.getName(request)) .append("</div>") .append("</a></li>"); } } ModuleQueue submodules = module.getSubModules() != null ? module.getSubModules() : null; for (int j = 0; submodules != null && j < submodules.size(); j++) { Module submodule = submodules.getModule(j); String target = submodule.getTarget() == null ? "mainFrame" : submodule.getTarget(); renderSubMenus( submodule, datas, contextpath, target, control, module.getId(), framepath, 2, tokenurl); } datas.append("</ul></li>"); } /** 个人中心 */ if (itemQueue != null && itemQueue.size() > 0) { String selectedclass = ""; if (selectedmenuid != null && selectedmenuid.equals("isany_personcenter")) { selectedclass = "class=\"select\""; } if (!menuHelper.isShowrootmenuleft()) { datas .append("<li><a id=\"anchor_") .append("isany_personcenter") .append("\" ") .append(selectedclass) .append(" href=\"#\">") .append(personcenter) .append("</a>"); } else { String target = "mainFrame"; datas .append("<li><a href=\"#\" id=\"anchor_") .append("isany_personcenter") .append("\" ") .append(selectedclass) .append(" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append("isany_personcenter") .append("','") .append(framepath) .append("?") .append(MenuHelper.sanymenupath) .append("=") .append("isany_personcenter") .append("','") .append(target) .append("',{})\">") .append(personcenter) .append("</a>"); } datas.append("<ul class=\"second\">"); Item item = null; for (int i = 0; i < itemQueue.size(); i++) { item = itemQueue.getItem(i); String target = item.getTarget() == null ? "mainFrame" : item.getTarget(); if (target.equals("mainFrame")) { String mname = item.getName(request); String url = MenuHelper.getItemUrl(item, contextpath, framepath, control); datas .append("<li><a href=\"#\" id=\"anchor_") .append(item.getId()) .append("\" onClick=\"navto_sany_MenuItem('") .append(tokenurl) .append("','") .append("isany_personcenter") .append("','") .append(url) .append("','") .append(target) .append("',") .append(item.getOption()) .append(",'") .append(mname) .append("')\"><span></span>") .append("<div>") .append(mname) .append("</div>") .append("</a></li>"); } else { datas .append("<li><a href=\"#\" id=\"anchor_") .append(item.getId()) .append("\" onClick=\"navto_sany_MenuItem_window('") .append(tokenurl) .append("','") .append("isany_personcenter") .append("','") .append(item.getPath()) .append("','") .append(contextpath) .append("','") .append(target) .append("')\"><span></span>") .append("<div>") .append(item.getName(request)) .append("</div>") .append("</a></li>"); } } datas.append("</ul></li>"); } datas.append(rooter); try { // System.out.println(datas.toString()); this.out.write(datas.toString()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { datas = null; } return ret; }
/** * 强制要求系统必须携带令牌 * * @return */ @AssertDToken public void ssowithtoken(HttpServletRequest request, HttpServletResponse response) { // return "path:sso"; String u = "", p = "", ck = ""; String successRedirect = request.getParameter("successRedirect"); if (!StringUtil.isEmpty(successRedirect)) { successRedirect = StringUtil.getRealPath(request, successRedirect, true); } String userName = (String) request.getAttribute(TokenStore.token_request_account_key); String worknumber = (String) request.getAttribute(TokenStore.token_request_worknumber_key); String loginType = "1"; if (StringUtil.isEmpty(userName)) { userName = worknumber; loginType = "2"; } String loginMenu = request.getParameter("loginMenu"); String contextpath = request.getContextPath(); String menuid = "newGetDoc"; if (loginMenu != null) { menuid = loginMenu; } HttpSession session = request.getSession(); boolean isWebSealServer = ConfigManager.getInstance().getConfigBooleanValue("isWebSealServer", false); if (isWebSealServer && userName == null) { String subsystem = "sany-mms"; try // uim检测 { CommonInfo info = new CommonInfo(); UimUserInfo userinfo = null; String ip = ""; userinfo = info.validateUIM(request); ip = userinfo.getUser_ip(); userName = userinfo.getUser_name(); AccessControl control = AccessControl.getInstance(); control.checkAccess(request, response, false); String user = control.getUserAccount(); request.setAttribute("fromsso", "true"); if (user == null || "".equals(user) || !userName.equals(user)) { try { if (!userName.equals(user)) control.resetSession(session); String password = SSOUserMapping.getUserPassword(userName); control = AccessControl.getInstance(); control.login(request, response, userName, password); if (StringUtil.isEmpty(successRedirect)) { Framework framework = Framework.getInstance(control.getCurrentSystemID()); MenuItem menuitem = framework.getMenuByID(menuid); if (menuitem instanceof Item) { Item menu = (Item) menuitem; successRedirect = MenuHelper.getRealUrl( contextpath, Framework.getWorkspaceContent(menu, control), MenuHelper.sanymenupath_menuid, menu.getId()); } else { Module menu = (Module) menuitem; String framepath = contextpath + "/sanydesktop/singleframe.page?" + MenuHelper.sanymenupath + "=" + menu.getPath(); successRedirect = framepath; } AccessControl.recordIndexPage(request, successRedirect); } else { successRedirect = URLDecoder.decode(successRedirect); } response.sendRedirect(successRedirect); return; } catch (Exception e) { response.sendRedirect( contextpath + "/webseal/websealloginfail.jsp?userName="******"&ip=" + ip + "&errormsg=" + java.net.URLEncoder.encode(e.getMessage(), "UTF-8")); return; } } else { control.resetUserAttributes(); if (StringUtil.isEmpty(successRedirect)) { Framework framework = Framework.getInstance(control.getCurrentSystemID()); MenuItem menuitem = framework.getMenuByID(menuid); if (menuitem instanceof Item) { Item menu = (Item) menuitem; successRedirect = MenuHelper.getRealUrl( contextpath, Framework.getWorkspaceContent(menu, control), MenuHelper.sanymenupath_menuid, menu.getId()); } else { Module menu = (Module) menuitem; String framepath = contextpath + "/sanydesktop/singleframe.page?" + MenuHelper.sanymenupath + "=" + menu.getPath(); successRedirect = framepath; } AccessControl.recordIndexPage(request, successRedirect); } else { successRedirect = URLDecoder.decode(successRedirect); } response.sendRedirect(successRedirect); return; } } catch (Exception e) // 检测失败,继续平台登录 { } } else { try { AccessControl control = AccessControl.getInstance(); control.checkAccess(request, response, false); String user = control.getUserAccount(); worknumber = control.getUserAttribute("userWorknumber"); boolean issameuser = false; if (loginType.equals("2")) { if (worknumber != null && !worknumber.equals("")) issameuser = userName.equals(worknumber); } else { if (user != null && !user.equals("")) issameuser = userName.equals(user); } if (user == null || "".equals(user) || !issameuser) { if (!issameuser) { control.resetSession(session); } try { // 1-域账号登录 2-工号登录 String password = null; if (loginType.equals("1")) { password = SSOUserMapping.getUserPassword(userName); } else { java.util.Map data = SSOUserMapping.getUserNameAndPasswordByWorknumber(userName); userName = (String) data.get("USER_NAME"); password = (String) data.get("USER_PASSWORD"); } control = AccessControl.getInstance(); request.setAttribute("fromsso", "true"); control.login(request, response, userName, password); if (StringUtil.isEmpty(successRedirect)) { Framework framework = Framework.getInstance(control.getCurrentSystemID()); MenuItem menuitem = framework.getMenuByID(menuid); if (menuitem instanceof Item) { Item menu = (Item) menuitem; successRedirect = MenuHelper.getRealUrl( contextpath, Framework.getWorkspaceContent(menu, control), MenuHelper.sanymenupath_menuid, menu.getId()); } else { Module menu = (Module) menuitem; String framepath = contextpath + "/sanydesktop/singleframe.page?" + MenuHelper.sanymenupath + "=" + menu.getPath(); successRedirect = framepath; } AccessControl.recordIndexPage(request, successRedirect); } else { successRedirect = URLDecoder.decode(successRedirect); } response.sendRedirect(successRedirect); return; } catch (Exception e) { response.sendRedirect( contextpath + "/webseal/websealloginfail.jsp?userName="******"&errormsg=" + java.net.URLEncoder.encode(e.getMessage(), "UTF-8")); return; } } else { control.resetUserAttributes(); if (StringUtil.isEmpty(successRedirect)) { Framework framework = Framework.getInstance(control.getCurrentSystemID()); MenuItem menuitem = framework.getMenuByID(menuid); if (menuitem instanceof Item) { Item menu = (Item) menuitem; successRedirect = MenuHelper.getRealUrl( contextpath, Framework.getWorkspaceContent(menu, control), MenuHelper.sanymenupath_menuid, menu.getId()); } else { Module menu = (Module) menuitem; String framepath = contextpath + "/sanydesktop/singleframe.page?" + MenuHelper.sanymenupath + "=" + menu.getPath(); successRedirect = framepath; } AccessControl.recordIndexPage(request, successRedirect); } else { successRedirect = URLDecoder.decode(successRedirect); } response.sendRedirect(successRedirect); return; } } catch (Throwable ex) { String errorMessage = ex.getMessage(); if (errorMessage == null) errorMessage = ""; errorMessage = errorMessage.replaceAll("\\n", "\\\\n"); errorMessage = errorMessage.replaceAll("\\r", "\\\\r"); try { response.getWriter().print(errorMessage + "登陆失败,请确保输入的用户名和口令是否正确!"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }