Jforum2.1.8開源論壇的修改(tomcat+oracle)
本文中的配置文件指的是:jforum/WEB-INF/config/ SystemGlobals.properties文件
1、 項目的部署,首先下載開源項目包,解壓後放到tomcat下,
數據庫表的建立:找到jforum/WEB-INF/config/database/oracle/oracle_db_struct.sql文件
向表中插入數據:jforum/WEB-INF/config/database/oracle/ oracle_data_dump.sql文件
指定論壇使用的數據庫:找到配置文件
修改代碼如下:
# Database type to use
database.driver.name = oracle
# Time in seconds to healthcheck all database connections
database.ping.delay = 1521
配置oracle用戶名密碼:找到jforum/WEB-INF/config/database/oracle/ oracle.properties文件
修改代碼如下:
database.driver.name=oracle
database.connection.password=orcl
database.connection.dbname=orcl
database.connection.string_local=jdbc/:oracle/:oci/:${database.connection.username}/${database.connection.password}@${database.connection.dbname}
database.support.autokeys=false
database.connection.host=localhost
database.connection.pool.min=5
database.support.subqueries=true
database.connection.pool.timeout=120
database.connection.port=1521
database.connection.username=orcl
通過以上配置jforum就可以運行了,可可以試試,不過現在是英文的,好現在將它設置爲中文,
在配置文件40行修改代碼如下:
i18n.board.default = zh_CN
ok了,中文的可以了。
現在熟悉一下jforum吧!
可以用admin/admin登錄,前提是你已經加入了數據了!
到這裏基本的功能就可以了,下面說一下我在和項目集成時遇到的問題及解決辦法
(1) 單點登錄問題,因爲論壇是和項目集成使用的,所以要實現單點登錄,下面說一下cookie方式實現的單點登錄:
實現你自己的登陸類(SSO)
你的類必須實現JF的接口: net.forum.sso.SSO .
注意:使用你自定義的接口類後,關於用戶註冊/用戶激活等功能將不再使用了
下面是我的實現類,供參考
package net.jforum.sso;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
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 MyUserSSO implements SSO {
static final Logger logger = Logger
.getLogger(CookieUserSSO.class.getName());
HttpSession session = null;
public String authenticateUser(RequestContext request) {
String username = null;
try {
// 讀取cookie
Cookie[] rcookie = request.getCookies();
if (rcookie != null) {
for (int i = 0; i < rcookie.length; i++) {
Cookie myCookie = rcookie[i];
String unameString = SystemGlobals
.getValue(ConfigKeys.COOKIE_NAME_USER);
if (unameString.equals(myCookie.getName())) {
username = myCookie.getValue();
username = URLDecoder.decode(username.trim(), "UTF-8");
} else {
}
}
}
System.out.println(username + "myusersso.java");
} catch (Exception e) {
System.out.println(e.getMessage());
}
// login cookie set by my web LOGIN application
// Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals
// .getValue(ConfigKeys.COOKIE_NAME_USER));
//
// System.out.println(cookieNameUser+"<<<<<<<<"+SystemGlobals
// .getValue(ConfigKeys.COOKIE_NAME_USER));
// if (cookieNameUser != null) {
// username = cookieNameUser.getValue();
// }
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 = null;
try {
cookieNameUser = ControllerUtils.getCookie(SystemGlobals
.getValue(ConfigKeys.COOKIE_NAME_USER));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} // 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.
}
}
實現了自己的類之後,要設置jforum的登錄模式,找到配置文件329行
authentication.type = sso
346行:sso.implementation = net.jforum.sso.MyUserSSO
原理介紹:
當一個用戶訪問JForum時,JForum便會檢查是否配置SSO,如果配置了SSO,JForum便會調用authenticateUser()方法。該方法簡單地返回username或null。
- 若返回了一個不爲空的username時,JForum將會檢查是否匹配JForum數據庫的userid。
- 若沒有匹配的userid,JForum將動態加以創建
- JForum設置該user爲登陸狀態
- 若返回了一個null,則設置爲“Anonymous”
- 若一個“Anonymous”用戶試圖訪問權限以外的頁面,JForum將根據SSO的設置導航到登陸頁面,同時傳遞給一個登陸成功後應該遷移到的地址參數給login頁面。
下面是cookie的代碼:
request.setCharacterEncoding("UTF-8");
String username=request.getParameter("username");
Cookie cookiebbs = new Cookie("jforumSSOCookieNameUser", "用戶名");
cookiebbs.setMaxAge(-1);
response.addCookie(cookiebbs);
response.sendRedirect(request.getContextPath()+"/forums/list.page");
這裏cookie的名字是在配置文件中配置的,468行
cookie.name.user =jforumSSOCookieNameUser
好了,就寫到這裏吧,相信大家看到這裏像搜索問題、中文用戶名問題應該都能解決了。我就不再寫了,網上搜一下應該都能解決了。
希望這對像我一樣想使用jforum但又不知道怎麼下手的有幫助,歡迎大家指正。
將jforum放進MyEclipse裏做項目
很簡單,就是按照你的源碼那個目錄,然後按照目錄組織,(webroot部分)將各個文件夾放進webroot裏。完全按照jforum裏的目錄組織就可以了。然後將src文件夾放在工程裏覆蓋MyEclipse自動生成那種就可以了
原文:http://www.cnblogs.com/xingzhen/archive/2011/03/30/2000199.html