今天做了个单点登陆 。
但是怎么测试呢?
下面请看详解:
源码中是这样的:
/** * 单点登录改造 * * @param request * @param response * @return * @throws IOException * @throws HttpException * @throws IOException */ @RequestMapping(value = "/rcbSingleLoginCheck.do") public Object singleLoginCheck(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setCharacterEncoding("UTF-8"); // 会话失效 request.getSession().invalidate();// 使会话失效,解除资源占用 PrintWriter writer = null; PbUser pbUser = null; // 用户编码 String userCode = request.getParameter("user_code"); //config String config = request.getParameter("config"); log.info("单点登陆时获取的config-----"+config); try { if (StringUtils.isEmpty(userCode)) { throw new PbException("无法获取用户编码,请确认!"); } if(StringUtils.isEmpty(config)){ throw new PbException("无法获取外设配置信息config!"); } //将config保存在session中 Session sc = new Session(); HashMap customParam = new HashMap(); customParam.put("config", config); sc.setCustomParam(customParam); pbUser = pbUserService.loadPbUser(userCode); if (null == pbUser) { throw new PbException("登录失败,当前系统中不存在该用户:" + userCode); } else if (pbUser.getEnabled() != 1) { throw new PbException("登录失败, 用户:" + userCode + "已禁用"); } request.getSession().setAttribute("userInfo", pbUser); sc.setUserId(pbUser.getUser_id()); sc.setUserCode(pbUser.getUser_code()); sc.setUserName(pbUser.getUser_name()); sc.setUserType(pbUser.getUser_type()); sc.setEntry(pbUser.getEntry()); //记录用户登陆的网点编码、转账时需要传递机构编码(即是用户登陆的网点编码) sc.setBelongOrgCode(pbUser.getBank_code()); sc.setTop_org(1); Calendar cal = Calendar.getInstance(); sc.setBusiYear( cal.get(Calendar.YEAR)); sc.setBelongOrgId(pbUser.getBank_id()); //add zhouqi 20131213 终端号 sc.setTellerCode(pbUser.getTellercode()); //ztl 2014年4月23日17:42:07 济南 建行核心使用 sc.setBankcode(pbUser.getBank_code()); sc.setBankname(pbUser.getBank_name()); //wtb 20160224 用户客户端id sc.setIp(this.getIp(request)); sc.setBankLevel(pbUser.getBank_level()); sc.setManager_type(pbUser.getManager_type()); request.getSession().setAttribute("session", sc); //记录登录日志 logService.saveLoginLogInfo(sc,"用户登录,ip:" + this.getIp(request),pbUser.getCode()); int loginModel = PbParameters .getIntParameter(PbParaConstant.LOGINMODEL); request.getSession().setAttribute("loginModel", loginModel); request.getSession().setAttribute("session", sc); // 更改用户最后登陆日期 pbUserService.editUserLastloginDate(pbUser); return new ModelAndView("/Index"); } catch (Exception e) { log.error(e.getMessage(), e); writer = response.getWriter(); writer.write(e.getMessage()); } return null; }
url 写 : http://localhost:8080/realware/rcbSingleLoginCheck.do?config=1&user_code=000015 这样就可以测试了。 经测试:成功。
时间: 2024-10-15 14:49:38