关于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接口
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
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文件中的一下属性的内容:
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
authentication.type
=
sso sso.implementation
=
net.jforum.sso.CookieUserSSO sso.redirect
=
http:
//
www.123.com/login.jsp
//
可根据实际的登录页面地址进行修改
cookie.name.user
=
123UserInfo
//
电子商务网站中保存的cookie名称,可根据实际情况修改
(3)修改web应用中的登录和注销部分的逻辑:
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->
登录部分加入以下代码: ... 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>