Search in sources :

Example 1 with OnlineUser

use of com.cdeledu.model.system.OnlineUser in project wechat by dllwh.

the class CustomSessionManager method getSessionEntity.

/**
 * ----------------------------------------------- [私有方法]
 */
private OnlineUser getSessionEntity(Session session) {
    /**
     * 获取登录信息
     */
    Object obj = session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
    if (null == obj) {
        return null;
    }
    if (obj instanceof SimplePrincipalCollection) {
        SimplePrincipalCollection spc = (SimplePrincipalCollection) obj;
        obj = spc.getPrimaryPrincipal();
        if (null != obj && obj instanceof SysUser) {
            OnlineUser onlineUser = new OnlineUser((SysUser) obj);
            // 最后一次和系统交互的时间
            onlineUser.setLastAccess(session.getLastAccessTime());
            // 主机的ip地址
            onlineUser.setHost(session.getHost());
            // session ID
            onlineUser.setSessionId(session.getId().toString());
            // 会话到期
            onlineUser.setTimeout(session.getTimeout());
            // 会话创建
            onlineUser.setStartTime(session.getStartTimestamp());
            SessionStatus sessionStatus = (SessionStatus) session.getAttribute(CacheConstans.SESSION_STATUS);
            boolean status = Boolean.TRUE;
            if (null != sessionStatus) {
                status = sessionStatus.getOnlineStatus();
            }
            onlineUser.setSessionStatus(status);
            return onlineUser;
        }
    }
    return null;
}
Also used : SysUser(com.cdeledu.model.rbac.SysUser) OnlineUser(com.cdeledu.model.system.OnlineUser) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection)

Example 2 with OnlineUser

use of com.cdeledu.model.system.OnlineUser in project wechat by dllwh.

the class CustomSessionManager method forbidUserById.

/**
 * @方法描述: 查询要禁用的用户是否在线。
 * @param id
 * @param status
 */
public void forbidUserById(Integer id, Long status) {
    for (OnlineUser bo : getAllUser()) {
        if (bo.getId().equals(id)) {
            // 匹配用户
            // 获取用户Session
            Session session = shiroSessionRepository.getSession(bo.getSessionId());
            // 标记用户Session
            SessionStatus sessionStatus = (SessionStatus) session.getAttribute(CacheConstans.SESSION_STATUS);
            // 是否踢出 true:有效,false:踢出。
            sessionStatus.setOnlineStatus(status.intValue() == 1);
        }
    }
}
Also used : OnlineUser(com.cdeledu.model.system.OnlineUser) Session(org.apache.shiro.session.Session)

Aggregations

OnlineUser (com.cdeledu.model.system.OnlineUser)2 SysUser (com.cdeledu.model.rbac.SysUser)1 Session (org.apache.shiro.session.Session)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1