View Javadoc
1   /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   *
19   * For further informations on the SmartWeb Framework please visit
20   *
21   *                        http://smartweb.sourceforge.net
22   */
23  package net.smartlab.ssh;
24  
25  import java.io.IOException;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  import org.apache.struts.action.ActionForm;
29  import org.apache.struts.action.ActionMapping;
30  import net.smartlab.web.ActionException;
31  import net.smartlab.web.BusinessException;
32  import net.smartlab.web.DynaAction;
33  
34  /**
35   * TODO documentation
36   * @author rlogiacco
37   */
38  public class ShellAction extends DynaAction {
39  
40  	/**
41  	 * The key used to store and retrieve the current user from session.
42  	 */
43  	public final static String SESSION_KEY = "net.smartlab.web.shell";
44  
45  
46  	/**
47  	 * TODO documentation
48  	 * @param form
49  	 * @param request
50  	 * @param response
51  	 * @param mapping
52  	 * @return
53  	 * @throws Exception
54  	 * @throws ActionException
55  	 */
56  	public String login(ActionForm form, HttpServletRequest request, HttpServletResponse response, ActionMapping mapping)
57  			throws ActionException {
58  		logger.info("login() - start");
59  		Shell shell = new Shell();
60  		super.valorize(form, shell, null);
61  		try {
62  			shell.open();
63  			request.getSession().setAttribute(ShellAction.SESSION_KEY, shell);
64  			logger.info("Connection established to " + shell);
65  			return "success";
66  		} catch (BusinessException be) {
67  			logger.warn("Connection failed to " + shell);
68  			return "error";
69  		} catch (IOException ioe) {
70  			throw new ActionException(ioe.getMessage(), ioe.getCause());
71  		}
72  	}
73  
74  	/**
75  	 * TODO documentation
76  	 * @param form
77  	 * @param request
78  	 * @param response
79  	 * @param mapping
80  	 * @return
81  	 * @throws ActionException
82  	 */
83  	public String logout(ActionForm form, HttpServletRequest request, HttpServletResponse response,
84  			ActionMapping mapping) throws ActionException {
85  		logger.info("logout() - start");
86  		Shell shell = (Shell)request.getSession().getAttribute(ShellAction.SESSION_KEY);
87  		if (shell != null) {
88  			shell.close();
89  			request.getSession().removeAttribute(ShellAction.SESSION_KEY);
90  		}
91  		return "success";
92  	}
93  }