diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/web/session/OnlineWebSessionManager.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/web/session/OnlineWebSessionManager.java index 080567ee..08980673 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/web/session/OnlineWebSessionManager.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/shiro/web/session/OnlineWebSessionManager.java @@ -14,6 +14,8 @@ import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ruoyi.common.constant.ShiroConstants; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.framework.shiro.session.OnlineSession; import com.ruoyi.system.domain.SysUserOnline; @@ -27,15 +29,15 @@ import com.ruoyi.system.service.ISysUserOnlineService; public class OnlineWebSessionManager extends DefaultWebSessionManager { private static final Logger log = LoggerFactory.getLogger(OnlineWebSessionManager.class); - + @Override public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException { super.setAttribute(sessionKey, attributeKey, value); if (value != null && needMarkAttributeChanged(attributeKey)) { - OnlineSession s = (OnlineSession) doGetSession(sessionKey); - s.markAttributeChanged(); + OnlineSession session = getOnlineSession(sessionKey); + session.markAttributeChanged(); } } @@ -68,13 +70,25 @@ public class OnlineWebSessionManager extends DefaultWebSessionManager Object removed = super.removeAttribute(sessionKey, attributeKey); if (removed != null) { - OnlineSession s = (OnlineSession) doGetSession(sessionKey); + OnlineSession s = getOnlineSession(sessionKey); s.markAttributeChanged(); } return removed; } + public OnlineSession getOnlineSession(SessionKey sessionKey) + { + OnlineSession session = null; + Object obj = doGetSession(sessionKey); + if (StringUtils.isNotNull(obj)) + { + session = new OnlineSession(); + BeanUtils.copyBeanProp(session, obj); + } + return session; + } + /** * 验证session是否有效 用于删除过期session */