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

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

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

    posts - 55,comments - 89,trackbacks - 0
       jforum是一個不錯的開源BBS論壇,支持中文,操作方便,容易擴展,是一個不錯的選擇。通過參考網(wǎng)上的資料,下面給出了jforum與web項目整合的方法:
    1、實現(xiàn)SSO類:

    package net.jforum.sso;

    import javax.servlet.http.Cookie;

    import net.jforum.ControllerUtils;
    import net.jforum.context.RequestContext;
    import net.jforum.entities.UserSession;
    import net.jforum.util.preferences.ConfigKeys;
    import net.jforum.util.preferences.SystemGlobals;
    import org.apache.log4j.Logger;
     
      public class CookieUserSSO implements SSO {     
        
        static final Logger logger = Logger.getLogger(CookieUserSSO.class.getName());     
        
        public String authenticateUser(RequestContext request) { 
             // myapp login cookie, contain logged username     
            Cookie myCookie = ControllerUtils.getCookie("jforumSSOCookieNameUser");     
                 
            String username = null;          
            if (myCookie != null) username = myCookie.getValue();      
            System.out.println("cookie_name1="+myCookie.getName());   
            System.out.println("cookie value1="+myCookie.getValue());  
                 
            if (myCookie == null || username.trim().equals("")) {     
                //JForumExecutionContext.setRedirect(SystemGlobals.getValue(ConfigKeys.SSO_REDIRECT));     
                return null; // no cookie found     
            }      
            System.out.println("cookie_name2="+myCookie.getName());  
            System.out.println("cookie value2="+myCookie.getValue());  
            return username; // jforum username     
        }     
        
        public boolean isSessionValid(UserSession userSession, RequestContext request) {   
      System.out.println("執(zhí)行isSessionValid方法");
            Cookie SSOCookie = ControllerUtils.getCookie("jforumSSOCookieNameUser"); // myapp login cookie      
                           
            String remoteUser = null;     
                 
            if (SSOCookie != null) remoteUser = SSOCookie.getValue(); //  jforum username     
        
            // user has since logged out     
            if(remoteUser == null &&      
                    userSession.getUserId() != SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {     
                return false;     
            // user has since logged in     
            } else if(remoteUser != null &&      
                    userSession.getUserId() == SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {     
                return false;     
            // user has changed user     
            } else if(remoteUser != null && !remoteUser.equals(userSession.getUsername())) {     
                return false;     
            }     
            return true; // myapp user and forum user the same     
        }     
    }    

    把該類放在jforum\WEB-INF\classes下,然后用javac  -d  .  CookieUserSSO .java 命令編譯,.class文件存放在jforum\WEB-INF\classes\net\jforum\sso下。
    2、修改SystemGlobals.properties
       有些JForum版本為jforum-custom.conf文件。
       查找“SSO”字樣,找到“SSO / User authentication”配置部分,將其修改為以下內(nèi)容:
    authentication.type = sso-----------特別注意:sso用小寫,不能用大寫
    ##...
    sso.implementation = net.jforum.sso.CookieUserSSO----------你自己實現(xiàn)的SSO類
    ##...
    sso.redirect=http://localhost:port/jforum---------------例如:sso.redirect=http://localhost:8082/jforum
    3、在程序的登錄或注銷部分加入如下代碼:
         登錄:
    Cookie cookie = new Cookie("jforumSSOCookieNameUser",name);-------name為從登錄界面取得的用戶名,把它加入到cookie里面
      cookie.setPath("/");
      cookie.setMaxAge(-1);//設(shè)置cookie的生命周期為:會話級,即瀏覽器關(guān)閉,該cookie就消失了
      response.addCookie(cookie);

        注銷:

      Cookie cookie =  new    Cookie(jforumSSOCookieNameUser, "");
      cookie.setMaxAge(0); // delete the cookie.
      response.addCookie(cookie);

    4、在html/jsp頁面加入超鏈接:
    <a href="/jforum">轉(zhuǎn)到論壇</a>

    這就配置完成了。


    posted on 2008-11-18 11:39 jiafang83 閱讀(1918) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     
    主站蜘蛛池模板: 国产黄片不卡免费| 成人无遮挡毛片免费看| 亚洲精品视频免费观看| 久久久久亚洲精品美女| 亚洲成电影在线观看青青| 丰满亚洲大尺度无码无码专线| 成人性生活免费视频| 亚洲爆乳无码专区www| 日韩精品免费视频| 亚洲一卡2卡三卡4卡有限公司| 国产精品成人亚洲| 亚洲高清最新av网站| 日韩毛片免费一二三| 亚洲一区二区三区免费视频| 国产成人亚洲综合无码| 国产精品永久免费| 亚洲五月激情综合图片区| 30岁的女人韩剧免费观看| 亚洲中文字幕无码永久在线| 免费播放在线日本感人片| 蜜芽亚洲av无码精品色午夜| 久久久高清免费视频| 精品国产日韩亚洲一区在线| 久久久久久亚洲精品不卡| 久草免费福利视频| 亚洲精品国产综合久久一线| 国产真人无码作爱免费视频| 久久精品国产亚洲av日韩| 国产精品成人免费一区二区 | 久久精品蜜芽亚洲国产AV| 97碰公开在线观看免费视频| 亚洲精品国产av成拍色拍| av在线亚洲欧洲日产一区二区| 可以免费观看的国产视频| 亚洲入口无毒网址你懂的| 16女性下面无遮挡免费| 亚洲欧美成人av在线观看| 搡女人免费视频大全| 一个人看的www在线免费视频| 亚洲AV无码成H人在线观看| 久久免费视频精品|