/** * 同步会话数据到DB 一次请求最多同步一次 防止过多处理 需要放到Shiro过滤器之前 * * @param request * @param response * @return * @throws Exception */ @Override protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception { OnlineSession session = (OnlineSession) request.getAttribute(ShiroConstants.ONLINE_SESSION); // 如果session stop了 也不同步 if (session != null && session.getStopTimestamp() == null) { onlineSessionDAO.syncToDb(session); } return true; }
@RequestMapping("/forceLogout") public String forceLogout(@RequestParam(value = "ids") String[] ids) { if (!SecurityUtils.getSubject().isPermitted("sys:userOnline or monitor:userOnline")) { throw new UnauthorizedException( MessageUtils.message("no.view.permission", "sys:userOnline或monitor:userOnline")); } for (String id : ids) { UserOnline online = baseService.findOne(id); if (online == null) { continue; } OnlineSession onlineSession = (OnlineSession) onlineSessionDAO.readSession(online.getId()); if (onlineSession == null) { continue; } onlineSession.setStatus(OnlineSession.OnlineStatus.force_logout); online.setStatus(OnlineSession.OnlineStatus.force_logout); baseService.update(online); } return redirectToUrl(null); }