Example usage for org.apache.shiro.session.mgt SimpleSession isValid

List of usage examples for org.apache.shiro.session.mgt SimpleSession isValid

Introduction

In this page you can find the example usage for org.apache.shiro.session.mgt SimpleSession isValid.

Prototype

public boolean isValid() 

Source Link

Usage

From source file:net.eggcanfly.spring.shiro.support.RedisSessionDao.java

License:Apache License

protected Session deserializeSession(Serializable sessionId) {

    BoundHashOperations<String, String, Object> hashOperations = redisTemplate
            .boundHashOps(SESSION_KEY + sessionId);

    SimpleSession session = new SimpleSession();

    try {/*from  www  .  jav a2 s.  c om*/

        session.setHost((String) hashOperations.get("host"));
        session.setId(sessionId);
        session.setLastAccessTime(
                hashOperations.get("lastAccessTime") == null ? new Date(System.currentTimeMillis())
                        : (Date) hashOperations.get("lastAccessTime"));
        session.setStartTimestamp((Date) hashOperations.get("startTimestamp"));
        session.setStopTimestamp((Date) hashOperations.get("stopTimestamp"));
        session.setTimeout((long) hashOperations.get("timeout"));
        Set<String> hashKeys = hashOperations.keys();
        for (Iterator<String> iterator = hashKeys.iterator(); iterator.hasNext();) {
            String hashKey = iterator.next();
            session.setAttribute(hashKey, hashOperations.get(hashKey));
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);

    }

    logger.debug("read session " + sessionId + ", session is " + session);

    return session.isValid() ? session : null;
}

From source file:uk.q3c.krail.core.shiro.VaadinSessionManager.java

License:Apache License

@Override
public Session getSession(SessionKey key) throws SessionException {

    // Retrieve the VaadinSession for the current user.
    VaadinSession vaadinSession = sessionProvider.get();

    String attributeName = SESSION_ATTRIBUTE_PREFIX + key.getSessionId();

    if (vaadinSession != null) {
        // If we have a valid VaadinSession, try to get the Shiro Session.
        SimpleSession shiroSession = (SimpleSession) vaadinSession.getAttribute(attributeName);

        if (shiroSession != null) {

            // Make sure the Shiro Session hasn't been stopped or expired (i.e. the
            // user logged out).
            if (shiroSession.isValid()) {
                return shiroSession;
            } else {
                // This is an invalid or expired session so we'll clean it up.
                vaadinSession.setAttribute(attributeName, null);
            }/*from w  w w . ja  va 2  s  . c om*/
        }
    }

    return null;
}