home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 June / PCWorld_2000-06_cd.bin / Software / Servis / Sambar43 / _SETUP.1 / SessionKiller.java < prev    next >
Text File  |  1999-08-28  |  2KB  |  70 lines

  1. package sysadmin;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import javax.servlet.*;
  6. import javax.servlet.http.*;
  7.  
  8.  
  9. public class SessionKiller extends HttpServlet
  10. {
  11.     public void init(ServletConfig config)
  12.         throws ServletException
  13.     {
  14.         super.init(config);
  15.     }
  16.     public void service(HttpServletRequest req, HttpServletResponse res)
  17.         throws ServletException, IOException
  18.     {
  19.         // Only the Sambar System Administrator may run this servlet
  20.         String isAdmin = (String)req.getAttribute("isSambarAdmin");
  21.         if (isAdmin == null)
  22.             return;
  23.  
  24.         res.setContentType("text/html");
  25.         PrintWriter out = res.getWriter();
  26.         
  27.         out.println("User Name: " + req.getRemoteUser() + "<br>");
  28.         out.println("Authorization Type: " + req.getAuthType() + "<br>");
  29.         out.println("<br><br>");
  30.         out.println("Here are all the current sessions:<br> ");
  31.         HttpSession session = req.getSession(true);
  32.         HttpSessionContext context = session.getSessionContext();
  33.         Enumeration ids = context.getIds();
  34.         out.println("<table border=1 cellpadding=0 cellspacing=0>");
  35.         out.println("<tr>");
  36.         out.println("<td align=middle><font size=-1><b>Session ID</b></font></font></td>");
  37.         out.println("<td align=middle><font size=-1><b>New Session</b></font></font></td>");
  38.         out.println("<td align=middle><font size=-1><b>Created</b></font></font></td>");
  39.         out.println("<td align=middle><font size=-1><b>Last Accessed</b></font></font></td>");
  40.         out.println("<td align=middle><font size=-1><b>Killed?</b></font></font></td>");
  41.         out.println("</tr>");
  42.  
  43.         while (ids.hasMoreElements())
  44.         {
  45.             out.println("<tr>");
  46.             String id = (String)ids.nextElement();
  47.             out.println("<td align=middle><font size=-1> "+id +" </font></td>");
  48.             HttpSession foreignSession = context.getSession(id);
  49.  
  50.             if (foreignSession.isNew())
  51.                 out.println("<td align=middle><font size=-1>Y</font></td>");
  52.             else
  53.                 out.println("<td align=middle><font size=-1>N</font></td>");
  54.  
  55.             out.println("<td align=middle><font size=-1>" + 
  56.                 new Date(foreignSession.getCreationTime())+"</font></td>");
  57.             out.println("<td align=middle><font size=-1>" + 
  58.                 new Date(foreignSession.getLastAccessedTime())+"</font></td>");
  59.             foreignSession.invalidate();
  60.             out.println("<td align=middle><font size=-1>Y</font></td>");
  61.             out.println("</tr>");
  62.         }
  63.  
  64.         out.println("</table>");
  65.         session.invalidate();
  66.         out.flush();
  67.         out.close();
  68.     }
  69. }
  70.