KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > replacementproxy > actions > LaunchReplacementProxyAction


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.replacementproxy.actions;
21
22 import java.util.HashMap JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32
33 import com.sslexplorer.boot.Util;
34 import com.sslexplorer.core.CoreEvent;
35 import com.sslexplorer.core.CoreServlet;
36 import com.sslexplorer.core.actions.AuthenticatedAction;
37 import com.sslexplorer.core.stringreplacement.VariableReplacement;
38 import com.sslexplorer.policyframework.LaunchSession;
39 import com.sslexplorer.policyframework.LaunchSessionFactory;
40 import com.sslexplorer.policyframework.ResourceAccessEvent;
41 import com.sslexplorer.security.SessionInfo;
42 import com.sslexplorer.webforwards.ReplacementProxyWebForward;
43 import com.sslexplorer.webforwards.WebForwardEventConstants;
44 import com.sslexplorer.webforwards.WebForwardTypeItem;
45 import com.sslexplorer.webforwards.WebForwardTypes;
46
47 /**
48  * Implementation of {@link com.sslexplorer.core.actions.AuthenticatedAction}
49  * that is the entry point for <i>Replacement Proxy Web Forward</i>.
50  *
51  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
52  */

53 public class LaunchReplacementProxyAction extends AuthenticatedAction {
54
55     static boolean debug = "true".equalsIgnoreCase(System.getProperty("sslexplorer.debugReplacementProxyTraffic"));
56     static HashMap JavaDoc caches = new HashMap JavaDoc();
57     static Log log = LogFactory.getLog(LaunchReplacementProxyAction.class);
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see com.sslexplorer.core.actions.AuthenticatedAction#isIgnoreSessionLock()
63      */

64     protected boolean isIgnoreSessionLock() {
65         return true;
66     }
67
68     /*
69      * (non-Javadoc)
70      *
71      * @see com.sslexplorer.core.actions.AuthenticatedAction#onExecute(org.apache.struts.action.ActionMapping,
72      * org.apache.struts.action.ActionForm,
73      * javax.servlet.http.HttpServletRequest,
74      * javax.servlet.http.HttpServletResponse)
75      */

76     public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
77                     throws Exception JavaDoc {
78         // Setup the Replacement proxy
79
LaunchSession launchSession = LaunchSessionFactory.getInstance()
80                         .getLaunchSession(request.getParameter(LaunchSession.LAUNCH_ID));
81         launchSession.checkAccessRights(null, getSessionInfo(request));
82         ReplacementProxyWebForward f = (ReplacementProxyWebForward) launchSession.getResource();
83
84         VariableReplacement r = new VariableReplacement();
85         r.setServletRequest(request);
86         r.setLaunchSession(launchSession);
87         String JavaDoc destinationURL = r.replace(f.getDestinationURL());
88
89         CoreEvent evt = new ResourceAccessEvent(this,
90                         WebForwardEventConstants.WEB_FORWARD_STARTED,
91                         f,
92                         launchSession.getPolicy(),
93                         this.getSessionInfo(request),
94                         CoreEvent.STATE_SUCCESSFUL).addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_TYPE,
95             ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(f.getType())).getName())
96                         .addAttribute(WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_URL, destinationURL);
97
98         CoreServlet.getServlet().fireCoreEvent(evt);
99
100         response.sendRedirect("/replacementProxyEngine?" + LaunchSession.LONG_LAUNCH_ID
101             + "="
102             + launchSession.getId()
103             + "&sslex_url="
104             + Util.urlEncode(destinationURL));
105         return null;
106     }
107
108     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
109         return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT;
110     }
111
112 }
113
Popular Tags