/**
   * 添加新评论
   *
   * @param docId 文档ID
   * @param commentUser 评论用户名
   * @param isGuest 是否是匿名用户
   * @param docComment 评论内容
   * @param status 评论状态
   * @param request HttpServletRequest
   * @return String
   * @throws Exception
   */
  public @ResponseBody(datatype = "jsonp") CommentResult addNewComment(
      long channelId,
      int docId,
      String commentUser,
      String isGuest,
      String docComment,
      HttpServletRequest request)
      throws Exception {

    DocComment docCommentBean = new DocComment();

    if (StringUtil.isEmpty(commentUser)) {
      if (Boolean.parseBoolean(isGuest)) docCommentBean.setUserName("__quest");
    } else {
      docCommentBean.setUserName(URLDecoder.decode(commentUser, "UTF-8"));
    }

    docCommentBean.setDocId(docId);

    if (!StringUtil.isEmpty(docComment)) {
      docCommentBean.setDocComment(URLDecoder.decode(docComment, "UTF-8"));
    }

    docCommentBean.setUserIP(com.frameworkset.util.StringUtil.getClientIP(request));

    // 默认即可发布
    int status = 1;

    // 获取频道的评论审核开关
    Integer aduitSwitchFlag = docCommentManager.getChannelCommentAduitSwitch((int) channelId);
    if (aduitSwitchFlag != null) {
      // 如果评论为开通状态,则评论的状态为待审核,否则为即可发布状态
      status = aduitSwitchFlag == 0 ? 2 : 1;
    }
    docCommentBean.setStatus(status);
    CommentResult result = new CommentResult();
    result.setAduitSwitchFlag(aduitSwitchFlag + "");
    try {
      docCommentManager.addOneComment(docCommentBean);
      result.setMsg("success");
    } catch (DocCommentManagerException e) {
      result.setMsg("failed");
      result.setError(StringUtil.exceptionToString(e));
    }

    return result;
  }
示例#2
0
	public void init(FilterConfig arg0) throws ServletException
	{
		String tokendualtime = arg0.getInitParameter("tokendualtime");
		String redirectpath_ =  arg0.getInitParameter("redirecturl");
		String tokenfailpath_ =   arg0.getInitParameter("tokenfailpath");
		String tokenstore_ = arg0.getInitParameter("tokenstore");
		if(!StringUtil.isEmpty(tokenstore_))
		{
			if(tokenstore_.toLowerCase().equals("mem") || tokenstore_.toLowerCase().equals("session"))
			{
				tokenstore = tokenstore_.toLowerCase();
				log.debug("Set tokenstore["+tokenstore_+"] failed,tokens will be stored in session.");
			}
			else
			{
				log.debug("Set tokenstore["+tokenstore_+"] success,tokens will be stored in session.");
			}
		}
		
		String tokenscaninterval = arg0.getInitParameter("tokenscaninterval");
		if(!StringUtil.isEmpty(redirectpath_))
		{
			redirectpath = redirectpath_; 
		}
		
		if(!StringUtil.isEmpty(tokenfailpath_))
		{
			tokenfailpath = tokenfailpath_; 
		}
//		else
//		{
//			tokenfailpath = redirectpath; 
//		}
		
		String enableToken_ = arg0.getInitParameter("enableToken");
		if(!StringUtil.isEmpty(enableToken_))
		{
			try {
				enableToken = Boolean.parseBoolean(enableToken_);
			} catch (Exception e) {
				log.debug("Set enableToken failed,false will be used.",(e));
			} 
		}
//		String tmp = arg0.getServletContext().getServletContextName();
//		this.redirectpath = StringUtil.getRealPath(tmp, redirectpath);
		
		long dualtime =  3600000;
		long tokenscaninterval_ = 1800000;
		if(!StringUtil.isEmpty(tokendualtime))
		{
			try {
				dualtime = Long.parseLong(tokendualtime);
			} catch (NumberFormatException e) {
				log.debug("Set tokendualtime failed,-1 will be used.",(e));
			}
		}
		if(!StringUtil.isEmpty(tokenscaninterval))
		{
			try {
				tokenscaninterval_ = Long.parseLong(tokenscaninterval);
			} catch (NumberFormatException e) {
				log.debug("Set tokendualtime failed,-1 will be used.",(e));
			}
		}
		if(enableToken)
			memTokenManager = MemTokenManagerFactory.getMemTokenManager(dualtime,tokenscaninterval_,enableToken,this.tokenstore,this);
	}
示例#3
0
  /**
   * 强制要求系统必须携带令牌
   *
   * @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();
        }
      }
    }
  }