|
项目中涉及到论坛需求,同事使用jforum做的,需要集成到x5中,通过起步支持,目前已基本完成,现将集成方式、遇到的问题及解决方案共享给大家
1、实现SSO类:
package net.jforum.sso;
import javax.servlet.http.Cookie;
import net.jforum.ControllerUtils;
import net.jforum.JForumExecutionContext;
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("justep-username");//justep-username x5放入cookie中的用户名
logger.info("myCookie==" + myCookie);
String username = null;
if (myCookie != null) {
username = myCookie.getValue();
} else { //游客身份登录
myCookie = new Cookie("justep-username", "Anonymous");
myCookie.setPath("/");
myCookie.setMaxAge(-1); // 设置 cookie 的生命周期为:会话级,即浏览器关闭,该 cookie 就消失了
username = "Anonymous";
}
logger.info("cookie_name=" + myCookie.getName());
logger.info("cookie value=" + myCookie.getValue());
return username; // jforum username
}
public boolean isSessionValid(UserSession userSession,
RequestContext request) {
logger.info("执行isSessionValid方法");
Cookie SSOCookie = ControllerUtils.getCookie("justep-username");
// login
logger.info("SSOCookie==" + SSOCookie); // cookie
String remoteUser = null;
if (SSOCookie != null) {
remoteUser = SSOCookie.getValue(); // jforum username
} else { //游客身份登录
SSOCookie = new Cookie("justep-username", "Anonymous");
SSOCookie.setPath("/");
SSOCookie.setMaxAge(-1); // 设置 cookie 的生命周期为:会话级,即浏览器关闭,该 cookie就消失了
remoteUser = "Anonymous";
}
// 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
}
}
编译为.class 文件放到\jforum\WEB-INF\classes\net\jforum\sso下
2、修改SystemGlobals.properties
查找“SSO”字样,找到“SSO / User authentication”配置部分,将其修改为以下内容:
authentication.type = sso-----------特别注意:sso用小写,不能用大写
##...
sso.implementation = net.jforum.sso.CookieUserSSO----------你自己实现的SSO类
##...
sso.redirect=http://localhost:port/jforum---------------例如:sso.redirect=http://localhost:8080/jforum
sso.default.password = e10adc3949ba59abbe56e057f20f883e ------------自动注册用户密码123456
3、将jforum部署到x5的tomcat下
4、在x5中配置链接地址
两种方式:1.在功能树的url="http://ip:端口/jforum"
2.和主页面中的“注销”平级,在/UI/portal_X/x5/js/ext.js添加动作
$("#main_btn_luntan").click(function(){
justep.Portal.Tab.open("工作论坛", "http://ip:8080/jforum", true);
});
然后在index.w中<div id="header_right">加入<span id="main_btn_luntan" title="工作论坛">工作论坛<span class="sep"> | </span></span>;
遇到的问题:
1、将jforum部署到x5的tomcat下时出现java.lang.UnsupportedClassVersionError: Bad version number in .class
file (unable to load class com.microsoft.sqlserver.jdbc.SQLServerDriver)
原因是jforum编译的jdk是1.7.0版本比x5自带的要高,将x5jdk替换为1.7.0版本后又出现javax.xml.stream.FactoryConfigurationError: Provider for com.bea.xml.stream.MXParserFactory cannot be found错误,后来换成1.6版本就好了
2、cookie取值,在实现方法中取cookie的值总是取不到,后经起步何承荣老师远程查看发现问题是进入x5时使用的是http://localhost:端口/x5 而jforum链接是http://ip:端口/jforum,属于跨域,所以取不到x5的cookie
解决办法:1.进入x5时使用http://ip:端口/x5
2.修改jform, 使得它返回的页面头带p3p(参考:http://www.cnblogs.com/malicious/archive/2009/06/10/1500821.html), 支持跨域传cookie
第二种方法待研究(试了一下,有点问题,如果有那位大侠走通了可以补充下) |
评分
-
查看全部评分
|