平台默认的登录是需要用户名和密码,另外提供了不用密码登录的action(ntLoginAction)
第三方集成不用密码登录可以调用时ntLoginAction实现,然后把登录产生的bsessionid放到Cookie中,打开首页的时候默认就会找Cookie中的bsessionid
.j的具体实现如下:
import java.io.IOException; import java.sql.Date; import java.util.HashMap; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSONObject; import com.justep.biz.client.Action; import com.justep.biz.client.ActionEngine; import com.justep.biz.client.ActionResult; import com.justep.biz.client.ActionUtils; import com.justep.ui.JustepConfig; public class Login extends com.justep.ui.impl.JProcessorImpl { public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 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[i].getName(); if (name.equals("bsessionid")) { bsessionid = cookies[i].getValue(); } } } // 判断bsessionid是否超时 ActionResult checkResult = ActionEngine.checkSession(bsessionid, ActionUtils.JSON_CONTENT_TYPE); if (checkResult.isSessionTimeOut()) { String username = request.getParameter("username"); String ip = request.getRemoteAddr(); String language = "zh_CN"; Date loginDate = new Date(System.currentTimeMillis()); //调用ntLoginAction不用密码登录 Action action = new Action(); action.setProcess("/SA/OPM/system/systemProcess"); action.setActivity("mainActivity"); action.setName("ntLoginAction"); action.setParameter("name", username); action.setParameter("loginDate", new java.sql.Date(System.currentTimeMillis())); action.setParameter("ip", "127.0.0.1"); action.setParameter("options", new HashMap<String, Object>()); action.setParameter("lang", language); ActionResult ar = ActionEngine.invokeActions(JustepConfig.getBusinessServer() + "/login2", null, action.asXML().getBytes("UTF-8"), null, ActionUtils.JSON_CONTENT_TYPE, ActionUtils.XML_CONTENT_TYPE, null, language, "post", null); if (ar.isSuccess()) { content = (JSONObject) ar.getContent(); bsessionid = ar.getBSessionID(); } else { throw new RuntimeException(ar.getMessage()); } // 把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); response.setCharacterEncoding("UTF-8"); response.addHeader("Access-Control-Allow-Origin", "*"); response.setContentType(ActionUtils.JSON_CONTENT_TYPE); response.sendRedirect("/x5/UI2/portal/pc3/index.w"); response.flushBuffer(); } }
评一波