zoukankan      html  css  js  c++  java
  • shiro session计算timeout

    /**
         * Determines if this session is expired.
         *
         * @return true if the specified session has expired, false otherwise.
         */
        protected boolean isTimedOut() {
    
            if (isExpired()) {
                return true;
            }
    
            long timeout = getTimeout();
    
            if (timeout >= 0l) {
    
                Date lastAccessTime = getLastAccessTime();
    
                if (lastAccessTime == null) {
                    String msg = "session.lastAccessTime for session with id [" +
                            getId() + "] is null.  This value must be set at " +
                            "least once, preferably at least upon instantiation.  Please check the " +
                            getClass().getName() + " implementation and ensure " +
                            "this value will be set (perhaps in the constructor?)";
                    throw new IllegalStateException(msg);
                }
    
                // Calculate at what time a session would have been last accessed
                // for it to be expired at this point.  In other words, subtract
                // from the current time the amount of time that a session can
                // be inactive before expiring.  If the session was last accessed
                // before this time, it is expired.
                long expireTimeMillis = System.currentTimeMillis() - timeout;
                Date expireTime = new Date(expireTimeMillis);
                return lastAccessTime.before(expireTime);
            } else {
                if (log.isTraceEnabled()) {
                    log.trace("No timeout for session with id [" + getId() +
                            "].  Session is not considered expired.");
                }
            }
    
            return false;
        }
  • 相关阅读:
    Cardiogram
    Increasing Speed Limits HDU
    Beaver Game CodeForces
    C++LeetCode:: Container With Most Water
    C++ leetcode::Reverse Integer
    C++ leetcode::ZigZag Conversion
    C++ leetcode Longest Palindromic Substring
    C++ leetcode Longest Substring Without Repeating Characters
    Faster RCNN
    C++ Leetcode Median of Two Sorted Arrays
  • 原文地址:https://www.cnblogs.com/gmq-sh/p/6214523.html
Copyright © 2011-2022 走看看