posts - 37,  comments - 53,  trackbacks - 0
          關于JForum論壇的基本情況就不在此介紹了,官方網址:www.jforum.net.jforum論壇系統的安裝也很簡單,按照官方文檔,或者google一下,基本都可以搞定,在此就不在介紹了。大概描述一下我使用jforum的情況:
          1.應用服務器:weblogic8.1
          2.數據庫:oracle10g
          3.已有一個電子商務網站,需要和jforum進行簡單的集成,提供sso(單點登錄的功能)。
          4.說明:已有的電子商務網站域名:http://www.123.com jforum域名:www.123.com/forum,電子商務網站和jfroum在統一臺服務器和同一應用服務器下,如果分開可能會存在session或cookie訪問的問題。
          5.JForum版本:2.1.8
          下面簡要的介紹一下使用cookie進行jforum和電子商務網站的sso集成的過程:
          (1)實現net.jforum.sso接口
          public class CookieUserSSO implements SSO {
              static final Logger  logger       = Logger.getLogger(CookieUserSSO.class.getName());

              public String authenticateUser(RequestContext request) {
                  // login cookie set by my web LOGIN application
                  Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals
                          .getValue(ConfigKeys.COOKIE_NAME_USER));
                  String username = null;

                  if (cookieNameUser != null) {
                      username = cookieNameUser.getValue();
                  }
                  logger.info("cookie username="+username);
                  System.out.println("cookie username="+username);
                  return username; // return username for jforum
                  // jforum will use this name to regist database or set in HttpSession
              }

              public boolean isSessionValid(UserSession userSession,
                      RequestContext request) {
                  Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals
                          .getValue(ConfigKeys.COOKIE_NAME_USER)); // user cookie
                  String remoteUser = null;

                  if (cookieNameUser != null) {
                      remoteUser = cookieNameUser.getValue(); // jforum username
                  }

                  if (remoteUser == null
                          && userSession.getUserId() != SystemGlobals
                                  .getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
                      // user has since logged out
                      return false;
                  } else if (remoteUser != null
                          && userSession.getUserId() == SystemGlobals
                                  .getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
                      // anonymous user has logged in
                      return false;
                  } else if (remoteUser != null
                          && !remoteUser.equals(userSession.getUsername())) {
                      // not the same user (cookie and session)
                      return false;
                  }       
                  return true; // myapp user and forum user the same. valid user.
              }

          }
          (2)修改SystemGlobals.properties中的配置:
              修改
          SystemGlobals.properties文件中的一下屬性的內容:
              authentication.type = sso
              sso.implementation = net.jforum.sso.CookieUserSSO
              sso.redirect = http://www.123.com/login.jsp //可根據實際的登錄頁面地址進行修改

              cookie.name.user = 123UserInfo //電子商務網站中保存的cookie名稱,可根據實際情況修改

          (3)修改web應用中的登錄和注銷部分的邏輯:
              登錄部分加入以下代碼:
             
          ...
              Cookie cookie = new Cookie("springTourUserInfo", sname);
               cookie.setMaxAge(-1);
               cookie.setPath("/");//cookie只在同一應用服務器有效
               response.addCookie(cookie);

             ...
              注銷部分加入以下代碼:
              ......
                Cookie cookie = new Cookie("springTourUserInfo", "");
                cookie.setMaxAge(0); // delete the cookie.
                cookie.setPath("/");
                response.addCookie(cookie);

              ......
          (4)在電子商務網站增加論壇的鏈接:
              <a href="/forum">論壇</a>

          基本配置完整,測試通過,如有問題,歡迎交流!

          感謝網友提供的資料:
          http://www.lifevv.com/java/doc/20080305224358885.html?page=0
          http://www.99inf.net/SoftwareDev/Java/54230.htm(作者:王保政)


             

          posted on 2008-06-26 16:54 雪地孤鴻 閱讀(4037) 評論(3)  編輯  收藏 所屬分類: java

          FeedBack:
          # re: JForum 的 SSO集成的問題解決
          2008-09-24 11:43 | wn
          請問我按照上面說的配置以后,在得到cookie的時候得不到,
          Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals
          .getValue(ConfigKeys.COOKIE_NAME_USER));
          cookieNameUser始終是null,
          cookie.setPath("/");不起作用,
          所以登錄的時候一直是游客的身份,如何解決呢,謝謝!  回復  更多評論
            
          # re: JForum 的 SSO集成的問題解決
          2008-11-22 17:17 | 雪地孤鴻
          上面這樣的解決方式是有個前提條件的,就是你的forum必須和你的主web應用是在同一域名下,例如:主web應用為:www.ggyy.com,你的forum的訪問路徑應該為www.ggyy.com/forum這樣的,cookie才能正確的被訪問到,這個也是由于瀏覽的安全因素導致,如果跨域訪問cookie,一般情況下是不會被允許的。  回復  更多評論
            
          # re: JForum 的 SSO集成的問題解決
          2010-11-09 13:36 | sail
          解決難題了。。3Q。。  回復  更多評論
            
          <2008年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(17)

          隨筆分類

          隨筆檔案

          文章檔案

          blog

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 睢宁县| 平泉县| 孙吴县| 巴东县| 平阴县| 双城市| 巩义市| 宿州市| 溧阳市| 乌海市| 辽宁省| 黎城县| 临潭县| 平乐县| 永修县| 临漳县| 克山县| 灵山县| 盘山县| 海南省| 云和县| 比如县| 藁城市| 聂拉木县| 延吉市| 永年县| 宝应县| 隆子县| 台中市| 奉贤区| 宜春市| 随州市| 潮安县| 犍为县| 筠连县| 江西省| 句容市| 宁蒗| 丹寨县| 郸城县| 内黄县|