KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tunnels > actions > ShowTunnelsAction


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.tunnels.actions;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.struts.Globals;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31 import org.apache.struts.action.ActionMessage;
32 import org.apache.struts.action.ActionMessages;
33
34 import com.sslexplorer.agent.DefaultAgentManager;
35 import com.sslexplorer.boot.Util;
36 import com.sslexplorer.core.BundleActionMessage;
37 import com.sslexplorer.core.CoreException;
38 import com.sslexplorer.core.RedirectWithMessages;
39 import com.sslexplorer.policyframework.LaunchSession;
40 import com.sslexplorer.policyframework.LaunchSessionFactory;
41 import com.sslexplorer.policyframework.NoPermissionException;
42 import com.sslexplorer.policyframework.PolicyException;
43 import com.sslexplorer.policyframework.actions.AbstractFavoriteResourcesDispatchAction;
44 import com.sslexplorer.security.LogonControllerFactory;
45 import com.sslexplorer.security.SessionInfo;
46 import com.sslexplorer.security.User;
47 import com.sslexplorer.tunnels.TunnelPlugin;
48 import com.sslexplorer.tunnels.TunnelingService;
49 import com.sslexplorer.tunnels.forms.TunnelsForm;
50
51 /**
52  * Implementation of
53  * {@link com.sslexplorer.policyframework.actions.AbstractFavoriteResourcesDispatchAction}
54  * that lists all of the configured <i>SSL Tunnels</i>.
55  *
56  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
57  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
58  */

59 public class ShowTunnelsAction extends AbstractFavoriteResourcesDispatchAction {
60
61     final static Log log = LogFactory.getLog(ShowTunnelsAction.class);
62
63     /**
64      * Constructor
65      */

66     public ShowTunnelsAction() {
67         super(TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE, TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE);
68     }
69
70     /*
71      * (non-Javadoc)
72      *
73      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
74      * org.apache.struts.action.ActionForm,
75      * javax.servlet.http.HttpServletRequest,
76      * javax.servlet.http.HttpServletResponse)
77      */

78     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
79                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
80         ActionForward fwd = super.unspecified(mapping, form, request, response);
81         User user = LogonControllerFactory.getInstance().getUser(request);
82         TunnelsForm tunnelsForm = (TunnelsForm) form;
83         SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
84         tunnelsForm.initialise(session, user, ".name");
85         tunnelsForm.checkSelectedView(request, response);
86         Util.noCache(response);
87         return fwd;
88     }
89
90     /*
91      * (non-Javadoc)
92      *
93      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
94      * org.apache.struts.action.ActionForm,
95      * javax.servlet.http.HttpServletRequest,
96      * javax.servlet.http.HttpServletResponse)
97      */

98     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
99         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
100     }
101     
102     /**
103      * Remve a tunnel.
104      *
105      * @param mapping mapping
106      * @param form form
107      * @param request request
108      * @param response response
109      * @return forward
110      * @throws Exception on any error
111      */

112     public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
113                     throws Exception JavaDoc {
114         ActionForward fwd = super.remove(mapping, form, request, response);
115         ActionMessages msgs = new ActionMessages();
116         msgs.add(Globals.MESSAGE_KEY, new ActionMessage("tunnels.message.tunnelsRemoved", "1"/*String.valueOf(sel.size())*/));
117         saveMessages(request, msgs);
118         return fwd;
119     }
120
121     /**
122      * Stop the selected tunnel
123      *
124      * @param mapping
125      * @param form
126      * @param request
127      * @param response
128      * @return forward
129      * @throws Exception
130      */

131     public ActionForward stop(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
132                     throws Exception JavaDoc {
133         String JavaDoc launchId = request.getParameter(LaunchSession.LAUNCH_ID);
134         if (launchId == null)
135             throw new PolicyException(PolicyException.INTERNAL_ERROR, "No launchId parameter.");
136         LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId);
137         if (launchSession != null) {
138             try {
139                 ((TunnelingService) DefaultAgentManager.getInstance().getService(TunnelingService.class)).stopTunnels(launchSession);
140                 ActionMessages msgs = new ActionMessages();
141                 msgs.add(Globals.MESSAGE_KEY, new BundleActionMessage(TunnelPlugin.MESSAGE_RESOURCES_KEY, "tunnels.stopped", launchSession.getResource().getResourceName()));
142                 saveMessages(request, msgs);
143                 if (!Util.isNullOrTrimmedBlank(request.getParameter("returnTo"))) {
144                     return new RedirectWithMessages(request.getParameter("returnTo"), request);
145                 }
146                 return new RedirectWithMessages(mapping.findForward("refresh"), request);
147             } catch (CoreException ce) {
148                 ActionMessages msgs = new ActionMessages();
149                 msgs.add(Globals.ERROR_KEY, ce.getBundleActionMessage());
150                 saveErrors(request, msgs);
151                 return mapping.findForward("display");
152     
153             } catch (NoPermissionException e) {
154                 ActionMessages msgs = new ActionMessages();
155                 msgs.add(Globals.ERROR_KEY, new ActionMessage("tunnels.noPermission", launchSession.getResource().getResourceName()));
156                 saveErrors(request, msgs);
157             }
158         }
159         else {
160             log.warn("No launch value ID, user probably double clicked tunnel.");
161         }
162
163         if (!Util.isNullOrTrimmedBlank(request.getParameter("returnTo"))) {
164             return new RedirectWithMessages(request.getParameter("returnTo"), request);
165         }
166         return mapping.findForward("display");
167     }
168
169 }
Popular Tags