01: /******************************************************************************
02: * $Source: /cvsroot/sshwebproxy/src/java/com/ericdaugherty/sshwebproxy/SessionCleanup.java,v $
03: * $Revision: 1.1 $
04: * $Author: edaugherty $
05: * $Date: 2003/12/07 20:48:18 $
06: ******************************************************************************
07: * Copyright (c) 2003, Eric Daugherty (http://www.ericdaugherty.com)
08: * All rights reserved.
09: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions are met:
12: *
13: * * Redistributions of source code must retain the above copyright notice,
14: * this list of conditions and the following disclaimer.
15: * * Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * * Neither the name of the Eric Daugherty nor the names of its
19: * contributors may be used to endorse or promote products derived
20: * from this software without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32: * THE POSSIBILITY OF SUCH DAMAGE.
33: * *****************************************************************************
34: * For current versions and more information, please visit:
35: * http://www.ericdaugherty.com/dev/sshwebproxy
36: *
37: * or contact the author at:
38: * web@ericdaugherty.com
39: *****************************************************************************/package com.ericdaugherty.sshwebproxy;
40:
41: import java.util.Collection;
42: import java.util.Iterator;
43: import javax.servlet.http.HttpSessionListener;
44: import javax.servlet.http.HttpSessionEvent;
45: import javax.servlet.http.HttpSession;
46:
47: import org.apache.commons.logging.Log;
48: import org.apache.commons.logging.LogFactory;
49:
50: /**
51: * Closes any open connections for sessions that
52: * have timed out.
53: *
54: * @author Eric Daugherty
55: */
56: public class SessionCleanup implements HttpSessionListener {
57:
58: //***************************************************************
59: // Variables
60: //***************************************************************
61:
62: /** Logger */
63: private static final Log log = LogFactory
64: .getLog(SessionCleanup.class);
65:
66: //***************************************************************
67: // HttpSessionListener Methods
68: //***************************************************************
69:
70: public void sessionCreated(HttpSessionEvent event) {
71: log.debug("New Session Created");
72: }
73:
74: /**
75: * Close any opoen SshConnections in the expired session.
76: * @param event
77: */
78: public void sessionDestroyed(HttpSessionEvent event) {
79: log.info("Session Expired");
80:
81: HttpSession httpSession = event.getSession();
82: SshSession sshSession = new SshSession(httpSession);
83:
84: Collection connections = sshSession.getConnections();
85: Iterator connectionIterator = connections.iterator();
86: while (connectionIterator.hasNext()) {
87: SshConnection connection = (SshConnection) connectionIterator
88: .next();
89: connection.close();
90: }
91:
92: sshSession.removeConnectionMap();
93: }
94:
95: }
|