1 18 19 package cowsultants.itracker.web.actions; 20 21 import java.io.*; 22 import java.rmi.*; 23 import java.util.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 27 import org.apache.struts.action.*; 28 import org.apache.struts.util.*; 29 30 import cowsultants.itracker.ejb.client.models.*; 31 import cowsultants.itracker.ejb.client.util.*; 32 import cowsultants.itracker.web.util.*; 33 34 35 public class LogoffAction extends ITrackerAction { 36 public LogoffAction() { 37 } 38 39 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 40 try { 41 HttpSession session = request.getSession(true); 42 UserModel user = (UserModel) session.getAttribute("user"); 43 String login = (user != null ? user.getLogin() : "UNKNOWN"); 44 45 if(clearSession(login, request, response)) { 46 Logger.logInfo("User " + login + " logged out successfully."); 47 } 48 } catch(Exception e) { 49 Logger.logError("Error logging out user. " + e.getMessage()); 50 } 51 return mapping.findForward("login"); 52 } 53 54 public boolean clearSession(String login, HttpServletRequest request, HttpServletResponse response) { 55 try { 56 HttpSession session = request.getSession(true); 57 session.invalidate(); 58 59 if(login != null) { 60 SessionManager.invalidateSession(login); 61 } 62 } catch(Exception e) { 63 Logger.logError("Unable to clear session for user " + (login == null ? "UNKNOWN" : login)); 64 return false; 65 } 66 return true; 67 } 68 } 69 | Popular Tags |