|
1、需求如下:登录门户系统后,需要在门户中点击某个按钮,直接跳转到x5系统的首页,不需要再次登录2、实现方式如下:门户通过链接:http://am.hieo.com/wl/x5/UI2/portal/base/login/dLogin.j 调用我们X5系统中的dLogin.j 文件进行单点登录,门户是通过Header认证方式将username放在header中
3、问题如下:每次跳转的时候都进不了首页还是会跳转到登录页面,断点调试dLogin.j 文件时,是可以取到登录后的bessionID的,也就说登录应该成功了,为什么不跳转到首页,该如何解决??dLogin.j 文件如下:
public class dLogin extends com.justep.ui.impl.JProcessorImpl {
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getHeader("username");
//判断用户是否登录,如果登录强制注销
ActionResult onLineResult = ActionEngine.invokeActions(JustepConfig.getBusinessServer() + "/onlineUsers", null, null, null, "application/json", "application/json", null, null, "get", null);
JSONObject onLineContent = (JSONObject) onLineResult.getContent();
JSONObject data = (JSONObject) ((JSONObject)onLineContent.get("data")).get("value");
JSONArray ar = (JSONArray) data.get("rows");
for (int i = 0; i < ar.size(); i++) {//解析在线用户数据的JSONArray
JSONObject jsonObject = ar.getJSONObject(i);
String name = (String) ((JSONObject)jsonObject.get("name")).get("value");
String bsessionID = (String) ((JSONObject)jsonObject.get("sessionid")).get("value");
if(name.equals(username)){
ActionEngine.logout(bsessionID, ActionUtils.JSON_CONTENT_TYPE); //注销已登录的当前用户
}
}
//用户登录
JSONObject content = null;
String bsessionid = "";
//从cookie中获取已有的bsessionid
Cookie[] cookies = request.getCookies();
if (cookies != null){
for (int i = 0; i < cookies.length; i++) {
String name = cookies.getName();
if(name.equals("bsessionid")){
bsessionid = cookies.getValue();
}
}
}
//判断bsessionid是否超时
ActionResult checkResult = ActionEngine.checkSession(bsessionid, ActionUtils.JSON_CONTENT_TYPE);
if (checkResult.isSessionTimeOut()) {
String password = request.getParameter("password");
String ip = request.getRemoteAddr();
String language = "zh_CN";
Date loginDate = new Date(System.currentTimeMillis());
ActionResult actionResult = ActionEngine.login2(username, ActionUtils.md5("123456"), ip, language, loginDate, null, ActionUtils.JSON_CONTENT_TYPE, null);
content = (JSONObject) actionResult.getContent();
bsessionid = actionResult.getBSessionID();
//把bsessionid放到Cookie中
Cookie cookie = new Cookie("bsessionid",bsessionid);
cookie.setMaxAge(-1);
cookie.setPath("/");
response.addCookie(cookie);
} else {
content = (JSONObject) checkResult.getContent();
}
content.put("bsessionid", bsessionid);
System.out.println("bsessionid:::::"+bsessionid);
response.setCharacterEncoding("UTF-8");
response.addHeader("Access-Control-Allow-Origin", "*");
response.setContentType(ActionUtils.JSON_CONTENT_TYPE);
response.sendRedirect("http://192.168.5.11:8080/x5/UI2/portal/pc2/index.w");
response.flushBuffer();
}
}
|
|