Exemplo n.º 1
0
 @SuppressWarnings("unchecked")
 public void setAttribute(
     HttpServletRequest request, HttpServletResponse response, String name, Serializable value) {
   Map<String, Serializable> session =
       (Map<String, Serializable>) request.getAttribute(CURRENT_SESSION);
   String root;
   if (session == null) {
     root = RequestUtils.getRequestedSessionId(request);
     if (root != null && root.length() == 32) {
       session = sessionCache.getSession(root);
     }
     if (session == null) {
       session = new HashMap<String, Serializable>();
       do {
         root = sessionIdGenerator.get();
       } while (sessionCache.exist(root));
       response.addCookie(createCookie(request, root));
     }
     request.setAttribute(CURRENT_SESSION, session);
     request.setAttribute(CURRENT_SESSION_ID, root);
   } else {
     root = (String) request.getAttribute(CURRENT_SESSION_ID);
     if (root == null) {
       do {
         root = sessionIdGenerator.get();
       } while (sessionCache.exist(root));
       response.addCookie(createCookie(request, root));
       request.setAttribute(CURRENT_SESSION_ID, root);
     }
   }
   session.put(name, value);
   sessionCache.setSession(root, session, sessionTimeout);
 }
Exemplo n.º 2
0
  @SuppressWarnings("unchecked")
  public Serializable getAttribute(HttpServletRequest request, String name) {
    // 为了避免同一个请求多次获取缓存session,所以将缓存session保存至request中。
    Map<String, Serializable> session =
        (Map<String, Serializable>) request.getAttribute(CURRENT_SESSION);
    if (session != null) {
      return session.get(name);
    }

    String root = (String) request.getAttribute(CURRENT_SESSION_ID);
    if (root == null) {
      root = RequestUtils.getRequestedSessionId(request);
    }
    if (StringUtils.isBlank(root)) {
      request.setAttribute(CURRENT_SESSION, new HashMap<String, Serializable>());
      return null;
    }
    session = sessionCache.getSession(root);
    if (session != null) {
      request.setAttribute(CURRENT_SESSION_ID, root);
      request.setAttribute(CURRENT_SESSION, session);
      return session.get(name);
    } else {
      return null;
    }
  }
Exemplo n.º 3
0
 /**
  * 客户端包含
  *
  * @param request
  * @param model
  * @return
  */
 @RequestMapping(value = "/login_csi.jspx")
 public String csi(HttpServletRequest request, ModelMap model) {
   CmsSite site = CmsUtils.getSite(request);
   // 将request中所有参数
   model.putAll(RequestUtils.getQueryParams(request));
   FrontUtils.frontData(request, model, site);
   return FrontUtils.getTplPath(request, site.getSolutionPath(), TPLDIR_CSI, LOGIN_CSI);
 }
Exemplo n.º 4
0
 /**
  * 解析至自定义模板页
  *
  * @param tpl 自定义模板名称
  * @param request
  * @param response
  * @param model
  * @return
  */
 @RequestMapping(value = "/csi_custom.jspx")
 public String custom(
     String tpl, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
   log.debug("visit csi custom template: {}", tpl);
   CmsSite site = CmsUtils.getSite(request);
   // 将request中所有参数保存至model中。
   model.putAll(RequestUtils.getQueryParams(request));
   FrontUtils.frontData(request, model, site);
   return FrontUtils.getTplPath(site.getSolutionPath(), TPLDIR_CSI_CUSTOM, tpl);
 }
Exemplo n.º 5
0
 public void logout(HttpServletRequest request, HttpServletResponse response) {
   request.removeAttribute(CURRENT_SESSION);
   request.removeAttribute(CURRENT_SESSION_ID);
   String root = RequestUtils.getRequestedSessionId(request);
   if (!StringUtils.isBlank(root)) {
     sessionCache.clear(root);
     Cookie cookie = createCookie(request, null);
     cookie.setMaxAge(0);
     response.addCookie(cookie);
   }
 }
Exemplo n.º 6
0
 public String getSessionId(HttpServletRequest request, HttpServletResponse response) {
   String root = (String) request.getAttribute(CURRENT_SESSION_ID);
   if (root != null) {
     return root;
   }
   root = RequestUtils.getRequestedSessionId(request);
   if (root == null || root.length() != 32 || !sessionCache.exist(root)) {
     do {
       root = sessionIdGenerator.get();
     } while (sessionCache.exist(root));
     sessionCache.setSession(root, new HashMap<String, Serializable>(), sessionTimeout);
     response.addCookie(createCookie(request, root));
   }
   request.setAttribute(CURRENT_SESSION_ID, root);
   return root;
 }