|
发表于 2018-6-7 14:44:21
|
显示全部楼层
从SSO那边登录过来,就在肯定提供的有接口啊,没有接口怎么知道用sso登录的
自己定义一个.j,在接口的地方调用.j
.j中调用action实现登录,跳转到首页,如下:
- 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 password = request.getParameter("password");
- String ip = request.getRemoteAddr();
- String language = "zh_CN";
- Date loginDate = new Date(System.currentTimeMillis());
- 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);
- try {
- ActionResult ar = ActionEngine.invokeActions(JustepConfig.getBusinessServer() + "/login2", null, action.asXML().getBytes("UTF-8"), null, ActionUtils.XML_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());
- }
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage() + "", e);
- }
- // 把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();
- }
- }
复制代码
|
|