|
发表于 2019-8-12 13:53:29
|
显示全部楼层
代码如下:
- public class SSOLogin3 extends com.justep.ui.impl.JProcessorImpl {
- public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- JSONObject content = null;
- String bsessionid = "";
- String username="";
- // 从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();
- }
- }
- }
- // username = (String) request.getSession().getAttribute("company");
- // username = (String) request.getSession().getAttribute("ssoclientagent.user");
- try
- {
- username = (String) request.getSession().getAttribute("ssoclientagent.company");
- // System.out.println("登陆帐号:"+username);
- //
- // 判断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", ip);
- 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()+"~1111111111");
- }
- // 把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();
- }
- catch(Exception e)
- {
- response.setCharacterEncoding("UTF-8");
- response.addHeader("Access-Control-Allow-Origin", "*");
- response.getWriter().write("当前账号不可用。");
- response.flushBuffer();
- }
-
- }
- }
复制代码
|
|