<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Sky's blog

    我和我追逐的夢

    常用鏈接

    統計

    其他鏈接

    友情鏈接

    最新評論

    resin的session id reuse特性(2)--分析問題

        上文中詳細描述了問題的表現情況,由于這個特性嚴重影響到目前為公司設計的一套前臺統一認證方案,因此不得不特別關注。好在resin的源代碼是公開的,直接從resin的官網將resin的源代碼拿下來,看resin到底是如何處理的。

    首先找到com.caucho.server.http.HttpRequest,發現是extends AbstractHttpRequest
     在AbstractHttpRequest中找到方法
      public HttpSession getSession(boolean create)

            發現調用
    _session = createSession(create, hasOldSession);
        這里有一段注釋解釋了重用jsessonid的行為:
            Must accept old ids because different applications in the same server must share the same cookie
            But, if the session group doesn't match, then create a new session.

      在createSession方法中找到
      manager.createSession(id, now, this, _isSessionIdFromCookie);

     
      打開com.caucho.server.session.SessionManager的createSession()方法,
      發現有注釋: @param oldId the id passed to the request.  Reuse if possible.
     
      看代碼:
      String id = oldId;

        
    if (id == null || id.length() < 4 ||
            
    ! isInSessionGroup(id) || ! reuseSessionId(fromCookie)) {
          id 
    = createSessionId(request, true);
        }

        SessionImpl session 
    = create(id, now, true);

     
            我們關注! reuseSessionId(fromCookie)這句,打開看函數
       /**
       * True if the server should reuse the current session id if the
       * session doesn't exist.
       
    */
      
    public boolean reuseSessionId(boolean fromCookie)
      {
        
    int reuseSessionId = _reuseSessionId;
       
        
    return reuseSessionId == TRUE || fromCookie && reuseSessionId == COOKIE;
      }

      注:非常不喜歡resin的這種代碼風格,一般我寧可寫成下面的這種,看代碼時容易理解
      return (reuseSessionId == TRUE) || (fromCookie && (reuseSessionId == COOKIE));
            再看
     
    /**
       * True if the server should reuse the current session id if the
       * session doesn't exist.
       
    */
      
    public void setReuseSessionId(String reuse)
        
    throws ConfigException
      {
        
    if (reuse == null)
          _reuseSessionId 
    = COOKIE;
        
    else if (reuse.equalsIgnoreCase("true"||
             reuse.equalsIgnoreCase(
    "yes"||
             reuse.equalsIgnoreCase(
    "cookie"))
          _reuseSessionId 
    = COOKIE;
        
    else if (reuse.equalsIgnoreCase("false"|| reuse.equalsIgnoreCase("no"))
          _reuseSessionId 
    = FALSE;
        
    else if (reuse.equalsIgnoreCase("all"))
          _reuseSessionId 
    = TRUE;
        
    else
          
    throw new ConfigException(L.l("'{0}' is an invalid value for reuse-session-id.  'true' or 'false' are the allowed values.",
                        reuse));
      }
          并且可以看到默認值為COOKIE
    private int _reuseSessionId = COOKIE;
       
        翻一下resin的文檔,可以發現在resin.conf的<session-config>有reuse-session-id這個配置項,resin文檔的說明如下:
       
        "reuse-session-id defaults to true so that Resin can share the session id amongst different web-apps."
       
        默認情況下reuse-session-id設置為true,setReuseSessionId("true")會使得_reuseSessionId=COOKIE,而reuseSessionId()方法中的表達式可以簡化:
        (reuseSessionId == TRUE) || (fromCookie && (reuseSessionId == COOKIE));
        -->  (COOKIE == TRUE) || (fromCookie && (COOKIE == COOKIE))
        --> (false) || (fromCookie && true)
        --> fromCookie
        因此默認情況下jsessionid用cookie傳遞就可以做到重用,否則就要生成新的jsessionid.
       
        按照這個思路,只要將reuse-session-id配置項設置為"all",就可以做到即使使用url rewrite也可以重用jsessionid.
        ok,問題解決

    posted on 2007-12-28 12:01 sky ao 閱讀(1695) 評論(0)  編輯  收藏 所屬分類: web

    主站蜘蛛池模板: 黄页网站免费在线观看| 香港a毛片免费观看| 女人张开腿给人桶免费视频| 亚洲黑人嫩小videos| 国产精品白浆在线观看免费| 亚洲妇熟XXXX妇色黄| 最近2019中文免费字幕在线观看| 国产偷国产偷亚洲清高动态图| sss在线观看免费高清| 国产成人A亚洲精V品无码| 国产综合免费精品久久久| 亚洲AV无码专区亚洲AV伊甸园| 另类免费视频一区二区在线观看| 亚洲成在人线av| aⅴ免费在线观看| 亚洲一区二区三区丝袜| 国产成人精品男人免费| 色婷婷综合缴情综免费观看| 久久亚洲精品无码播放| 性无码免费一区二区三区在线| 亚洲人成伊人成综合网久久| 成人永久免费高清| 黄色网址免费在线观看| 亚洲成年轻人电影网站www| 精品国产无限资源免费观看| 色婷婷亚洲一区二区三区| 亚洲综合精品香蕉久久网| 精品无码AV无码免费专区| 亚洲熟女精品中文字幕| 亚洲国产一区二区三区| 少妇无码一区二区三区免费| 亚洲国产日韩综合久久精品| 亚洲第一区精品日韩在线播放| 一级毛片免费播放| 亚洲国产成人久久一区二区三区| 国产成人亚洲影院在线观看| 1000部拍拍拍18勿入免费视频软件| 亚洲精品无码专区| 亚洲欧洲无码AV电影在线观看 | 国产精品亚洲精品观看不卡| 国产片免费在线观看|