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但又不知道怎么下手的有帮助,欢迎大家指正。

posted @ 2011-03-30 18:03  zalexing  阅读(1191)  评论(0编辑  收藏  举报