KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > webforwards > actions > LaunchTunneledSiteAction


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.webforwards.actions;
21
22 import java.net.URL JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.struts.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30
31 import com.maverick.multiplex.MultiplexedConnection;
32 import com.sslexplorer.agent.AgentTunnel;
33 import com.sslexplorer.agent.DefaultAgentManager;
34 import com.sslexplorer.boot.Util;
35 import com.sslexplorer.core.CoreEvent;
36 import com.sslexplorer.core.CoreServlet;
37 import com.sslexplorer.core.actions.AuthenticatedAction;
38 import com.sslexplorer.core.stringreplacement.VariableReplacement;
39 import com.sslexplorer.policyframework.LaunchSession;
40 import com.sslexplorer.policyframework.LaunchSessionFactory;
41 import com.sslexplorer.policyframework.ResourceAccessEvent;
42 import com.sslexplorer.properties.Property;
43 import com.sslexplorer.properties.impl.profile.ProfilePropertyKey;
44 import com.sslexplorer.security.SessionInfo;
45 import com.sslexplorer.webforwards.WebForward;
46 import com.sslexplorer.webforwards.WebForwardEventConstants;
47 import com.sslexplorer.webforwards.WebForwardTypeItem;
48 import com.sslexplorer.webforwards.WebForwardTypes;
49
50 /**
51  * Implementation of {@link com.sslexplorer.core.actions.AuthenticatedAction}
52  * that launches a <i>Tunneled Site Web Forward</i>.
53  * <p>
54  *
55  *
56  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
57  */

58 public class LaunchTunneledSiteAction extends AuthenticatedAction {
59
60     /**
61      * Constructor.
62      *
63      */

64     public LaunchTunneledSiteAction() {
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see com.sslexplorer.core.actions.AuthenticatedAction#isIgnoreSessionLock()
71      */

72     protected boolean isIgnoreSessionLock() {
73         return true;
74     }
75
76     public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
77                     throws Exception JavaDoc {
78         // Get the web forward
79

80         String JavaDoc launchId = request.getParameter(LaunchSession.LAUNCH_ID);
81         if (Util.isNullOrTrimmedBlank(launchId)) {
82             throw new Exception JavaDoc("No launch ID supplied.");
83         }
84         
85         LaunchSession launchSession = LaunchSessionFactory.getInstance().getLaunchSession(launchId);
86         launchSession.checkAccessRights(null, getSessionInfo(request));
87         WebForward wf = (WebForward)launchSession.getResource();
88
89         CoreEvent evt = new ResourceAccessEvent(this, WebForwardEventConstants.WEB_FORWARD_STARTED, wf, launchSession.getPolicy(), launchSession.getSession(),
90                         CoreEvent.STATE_SUCCESSFUL).addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_URL,
91             wf.getDestinationURL()).addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_TYPE,
92             ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(wf.getType())).getName());
93         CoreServlet.getServlet().fireCoreEvent(evt);
94         
95         VariableReplacement replacer = new VariableReplacement();
96         replacer.setLaunchSession(launchSession);
97         URL JavaDoc url = new URL JavaDoc(replacer.replace(wf.getDestinationURL()));
98         MultiplexedConnection agent = DefaultAgentManager.getInstance().getAgentBySession(getSessionInfo(request));
99         int port = DefaultAgentManager.getInstance().openURL((AgentTunnel)agent, url, launchSession);
100         if(port == -1) {
101             throw new Exception JavaDoc("Agent couldn't open tunnel.");
102         }
103         
104         // BPS to LDP - We have to wait for the serversocket on the agent end to startup
105
// as it is in a thread. Is there a better way of doing this?
106
Thread.sleep(1000);
107         
108         return new ActionForward(url.getProtocol() + "://" + Property.getProperty(new ProfilePropertyKey("client.localhostAddress", launchSession.getSession())) + ":" + port + url.getFile(), true);
109     }
110
111     /*
112      * (non-Javadoc)
113      *
114      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
115      * org.apache.struts.action.ActionForm,
116      * javax.servlet.http.HttpServletRequest,
117      * javax.servlet.http.HttpServletResponse)
118      */

119     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
120         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
121     }
122 }
123
Popular Tags