惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
F
Fortinet All Blogs
Vercel News
Vercel News
C
Check Point Blog
P
Privacy International News Feed
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
T
Troy Hunt's Blog
TaoSecurity Blog
TaoSecurity Blog
I
Intezer
T
The Exploit Database - CXSecurity.com
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
P
Proofpoint News Feed
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
Attack and Defense Labs
Attack and Defense Labs
S
Security @ Cisco Blogs
IT之家
IT之家
D
DataBreaches.Net
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
Y
Y Combinator Blog
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
Lohrmann on Cybersecurity
T
Tenable Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 最新话题
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
Recorded Future
Recorded Future
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
K
Kaspersky official blog
PCI Perspectives
PCI Perspectives
A
Arctic Wolf
Latest news
Latest news
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
雷峰网
雷峰网
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
Schneier on Security
Schneier on Security
M
MIT News - Artificial intelligence

博客园 - hone

管理 java学习 服务器相关 总统和亿万富翁经典语录(转载) js学习笔记 最近学习计划 VC控制Excel 真乱(转自csdn) 沟通(网上搜集) 工作 无题 将文档发送到打印机(From MSN) 经典68个故事 java的zip压缩(转自Jeet) 图形相关 在Oracle9i中计算时间差 六度分隔 经典故事 新年竟然第一篇?!
Manually Invalidating All Stale Sessions
hone · 2005-05-20 · via 博客园 - hone

 1import java.io.*;
 2import java.util.*;
 3import javax.servlet.*;
 4import javax.servlet.http.*;
 5
 6public class ManualInvalidateScan extends HttpServlet {
 7
 8  public void doGet(HttpServletRequest req, HttpServletResponse res)
 9                               throws ServletException, IOException {
10    res.setContentType("text/plain");
11    PrintWriter out = res.getWriter();
12
13    // Get the current session object, create one if necessary
14    HttpSession dummySession = req.getSession(true);
15
16    // Use the session to get the session context
17    HttpSessionContext context = dummySession.getSessionContext();
18
19    // Use the session context to get a list of session IDs
20    Enumeration ids = context.getIds();
21
22    // Iterate over the session IDs checking for stale sessions
23    while (ids.hasMoreElements()) {
24      String id = (String)ids.nextElement();
25      out.println("Checking " + id + "");
26      HttpSession session = context.getSession(id);
27
28      // Invalidate the session if it's more than a day old or has been
29      // inactive for more than an hour.
30      Date dayAgo = new Date(System.currentTimeMillis() - 24*60*60*1000);
31      Date hourAgo = new Date(System.currentTimeMillis() - 60*60*1000);
32      Date created = new Date(session.getCreationTime());
33      Date accessed = new Date(session.getLastAccessedTime());
34
35      if (created.before(dayAgo)) {
36        out.println("More than a day old, invalidated!");
37        session.invalidate();
38      }

39      else if (accessed.before(hourAgo)) {
40        out.println("More than an hour inactive, invalidated!");
41        session.invalidate();
42      }

43      else {
44        out.println("Still valid.");
45      }

46      out.println();
47    }

48  }

49}

50