Java Code Examples for com.ruoyi.framework.shiro.session.OnlineSession#getUserId()
The following examples show how to use
com.ruoyi.framework.shiro.session.OnlineSession#getUserId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OnlineSessionFilter.java From supplierShop with MIT License | 5 votes |
/** * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false; */ @Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { Subject subject = getSubject(request, response); if (subject == null || subject.getSession() == null) { return true; } Session session = onlineSessionDAO.readSession(subject.getSession().getId()); if (session != null && session instanceof OnlineSession) { OnlineSession onlineSession = (OnlineSession) session; request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession); // 把user对象设置进去 boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L; if (isGuest == true) { SysUser user = ShiroUtils.getSysUser(); if (user != null) { onlineSession.setUserId(user.getUserId()); onlineSession.setLoginName(user.getLoginName()); onlineSession.setAvatar(user.getAvatar()); onlineSession.setDeptName(user.getDept().getDeptName()); onlineSession.markAttributeChanged(); } } if (onlineSession.getStatus() == OnlineStatus.off_line) { return false; } } return true; }
Example 2
Source File: SyncOnlineSessionFilter.java From supplierShop with MIT License | 5 votes |
/** * 同步会话数据到DB 一次请求最多同步一次 防止过多处理 需要放到Shiro过滤器之前 */ @Override protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { OnlineSession session = (OnlineSession) request.getAttribute(ShiroConstants.ONLINE_SESSION); // 如果session stop了 也不同步 // session停止时间,如果stopTimestamp不为null,则代表已停止 if (session != null && session.getUserId() != null && session.getStopTimestamp() == null) { onlineSessionDAO.syncToDb(session); } return true; }
Example 3
Source File: OnlineSessionFilter.java From ruoyiplus with MIT License | 5 votes |
/** * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false; */ @Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { Subject subject = getSubject(request, response); if (subject == null || subject.getSession() == null) { return true; } Session session = onlineSessionDAO.readSession(subject.getSession().getId()); if (session != null && session instanceof OnlineSession) { OnlineSession onlineSession = (OnlineSession) session; request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession); // 把user对象设置进去 boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L; if (isGuest == true) { SysUser user = ShiroUtils.getSysUser(); if (user != null) { onlineSession.setUserId(user.getUserId()); onlineSession.setLoginName(user.getLoginName()); onlineSession.setDeptName(user.getDept().getDeptName()); onlineSession.markAttributeChanged(); } } if (onlineSession.getStatus() == OnlineStatus.off_line) { return false; } } return true; }
Example 4
Source File: SyncOnlineSessionFilter.java From ruoyiplus with MIT License | 5 votes |
/** * 同步会话数据到DB 一次请求最多同步一次 防止过多处理 需要放到Shiro过滤器之前 */ @Override protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { OnlineSession session = (OnlineSession) request.getAttribute(ShiroConstants.ONLINE_SESSION); // 如果session stop了 也不同步 // session停止时间,如果stopTimestamp不为null,则代表已停止 if (session != null && session.getUserId() != null && session.getStopTimestamp() == null) { onlineSessionDAO.syncToDb(session); } return true; }
Example 5
Source File: OnlineSessionFilter.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 表示是否允许访问;mappedValue就是[urls]配置中拦截器参数部分,如果允许访问返回true,否则false; */ @Override protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue){ Subject subject = getSubject(request, response); if (subject == null || subject.getSession() == null) { return true; } Session session = onlineSessionDAO.readSession(subject.getSession().getId()); if (session instanceof OnlineSession) { OnlineSession onlineSession = (OnlineSession) session; request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession); // 把user对象设置进去 boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L; if (isGuest) { SysUser user = ShiroUtils.getSysUser(); if (user != null) { onlineSession.setUserId(user.getUserId()); onlineSession.setLoginName(user.getLoginName()); onlineSession.setAvatar(user.getAvatar()); onlineSession.setDeptName(user.getDept().getDeptName()); onlineSession.markAttributeChanged(); } } return onlineSession.getStatus() != OnlineStatus.OFF_LINE; } return true; }
Example 6
Source File: SyncOnlineSessionFilter.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 同步会话数据到DB 一次请求最多同步一次 防止过多处理 需要放到Shiro过滤器之前 */ @Override protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue){ OnlineSession session = (OnlineSession) request.getAttribute(ShiroConstants.ONLINE_SESSION); // 如果session stop了 也不同步 // session停止时间,如果stopTimestamp不为null,则代表已停止 if (session != null && session.getUserId() != null && session.getStopTimestamp() == null) { onlineSessionDAO.syncToDb(session); } return true; }