设为首页 收藏本站
查看: 915|回复: 0

[经验分享] Jforum2.1.8开源论坛的修改(tomcat+oracle)

[复制链接]

尚未签到

发表于 2015-8-11 07:43:26 | 显示全部楼层 |阅读模式
  本文中的配置文件指的是: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;

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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-97166-1-1.html 上篇帖子: Tomcat: IllegalStateException: No output folder 下篇帖子: myeclipse tomcat 部署错误
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表