1 package dinamica.security; 2 3 import dinamica.*; 4 import javax.servlet.http.*; 5 import javax.servlet.*; 6 import java.sql.*; 7 import javax.sql.*; 8 9 13 14 public final class SessionListener implements HttpSessionListener 15 { 16 17 18 public void sessionCreated(javax.servlet.http.HttpSessionEvent sbe) 19 { 20 } 21 22 26 public void sessionDestroyed(javax.servlet.http.HttpSessionEvent sbe) 27 { 28 29 HttpSession s = sbe.getSession(); 31 String id = s.getId(); 32 33 Connection conn = null; 34 35 String sql = "delete from s_session where jsessionid = '" + id + "'"; 36 37 ServletContext ctx = s.getServletContext(); 38 39 try 40 { 41 42 String jndiName = (String )ctx.getAttribute("dinamica.security.datasource"); 45 if (jndiName==null) 46 throw new Throwable ("Context attribute [dinamica.security.datasource] is null, check your security filter configuration."); 47 48 DataSource ds = Jndi.getDataSource(jndiName); 49 conn = ds.getConnection(); 50 51 Db db = new Db(conn); 52 db.exec(sql); 53 54 } 55 catch (Throwable e) 56 { 57 System.err.println( "[WARNING@" + new java.util.Date () + "] SessionListener: " + e.getMessage() ); 58 } 59 finally 60 { 61 if (conn!=null) 62 { 63 try { conn.close(); } catch (Throwable e1){} 64 } 65 66 } 67 68 } 69 70 } 71 72 | Popular Tags |