Examples of OnlineSession


Examples of org.apache.shiro.session.mgt.OnlineSession

        if (subject == null || subject.getSession(false) == null) {
            return true;
        }
        Session session = sessionDAO.readSession(subject.getSession().getId());
        if (session != null && session instanceof OnlineSession) {
            OnlineSession onlineSession = (OnlineSession) session;
            request.setAttribute(ShiroConstants.ONLINE_SESSION, onlineSession);

            if (onlineSession.getStatus() == OnlineSession.OnlineStatus.force_logout) {
                return false;
            }
        }
        return true;
    }
View Full Code Here

Examples of org.apache.shiro.session.mgt.OnlineSession

    @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();
        }
    }
View Full Code Here

Examples of org.apache.shiro.session.mgt.OnlineSession

    @Override
    public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException {
        Object removed = super.removeAttribute(sessionKey, attributeKey);
        if (removed != null) {
            OnlineSession s = (OnlineSession) doGetSession(sessionKey);
            s.markAttributeChanged();
        }

        return removed;
    }
View Full Code Here

Examples of org.apache.shiro.session.mgt.OnlineSession

     * @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;
    }
View Full Code Here

Examples of org.apache.shiro.session.mgt.OnlineSession

        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 id设置进去
            boolean isGuest = onlineSession.getUserId() == null || onlineSession.getUserId() == 0L;
            if (isGuest == true) {
                User user = (User) request.getAttribute(Constants.CURRENT_USER);
                if (user != null) {
                    onlineSession.setUserId(user.getId());
                    onlineSession.setUsername(user.getUsername());
                    onlineSession.markAttributeChanged();
                }
            }

            if (onlineSession.getStatus() == OnlineSession.OnlineStatus.force_logout) {
                return false;
            }
        }
        return true;
    }
View Full Code Here

Examples of org.apache.shiro.session.mgt.OnlineSession

*/
public class OnlineSessionTest {

    @Test
    public void testSerialize() throws IOException, ClassNotFoundException, DecoderException {
        OnlineSession session = new OnlineSession();

        session.setId(123);
        session.setHost("127.0.0.1");
        session.setTimeout(1);
        session.setUserId(123L);
        session.setAttribute("z", "z");
        session.setStatus(OnlineSession.OnlineStatus.force_logout);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(session);
        oos.close();
        bos.close();
        byte[] objectBytes = bos.toByteArray();

        String str = Hex.encodeHexString(objectBytes);

        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Hex.decodeHex(str.toCharArray())));

        OnlineSession actualSession = (OnlineSession) ois.readObject();
        ois.close();

        Assert.assertEquals(session.getId(), actualSession.getId());
        Assert.assertEquals(session.getHost(), actualSession.getHost());
        Assert.assertEquals(session.getTimeout(), actualSession.getTimeout());
        Assert.assertEquals(session.getUserId(), actualSession.getUserId());
        Assert.assertEquals(session.getAttributes().get("z"), actualSession.getAttributes().get("z"));
        Assert.assertEquals(session.getStatus(), actualSession.getStatus());
        Assert.assertEquals(session.getSystemHost(), actualSession.getSystemHost());


    }
View Full Code Here

Examples of org.apache.shiro.session.mgt.OnlineSession

        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);
    }
View Full Code Here

Examples of org.apache.shiro.session.mgt.OnlineSession

     *
     * @param session
     */
    @Override
    protected void doDelete(Session session) {
        OnlineSession onlineSession = (OnlineSession) session;
        //定时任务删除的此时就不删除了
        if (onlineSession.getAttribute(ShiroConstants.ONLY_CLEAR_CACHE) == null) {
            try {
                userOnlineService.offline(String.valueOf(onlineSession.getId()));
            } catch (Exception e) {
                //即使删除失败也无所谓
            }
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.