KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > extensions > actions > AbstractLaunchViaAppletAction


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.extensions.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.action.ActionForm;
28 import org.apache.struts.action.ActionForward;
29 import org.apache.struts.action.ActionMapping;
30
31 import com.sslexplorer.core.CoreUtil;
32 import com.sslexplorer.core.actions.AuthenticatedAction;
33 import com.sslexplorer.extensions.ExtensionDescriptor;
34 import com.sslexplorer.policyframework.LaunchSession;
35 import com.sslexplorer.policyframework.LaunchSessionFactory;
36 import com.sslexplorer.security.Constants;
37 import com.sslexplorer.security.LogonControllerFactory;
38 import com.sslexplorer.security.SessionInfo;
39
40 /**
41  * Abstract action to launch an application via the <i>Agent Launcher Applet</i>. This
42  * should be extended and the {@link #getExtensionDescriptor(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)}
43  * method implemented to return the descriptor of the extension to
44  * launch.
45  *
46  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
47  */

48
49 public abstract class AbstractLaunchViaAppletAction extends AuthenticatedAction {
50     
51     final static Log log = LogFactory.getLog(AbstractLaunchViaAppletAction.class);
52
53     /*
54      * (non-Javadoc)
55      *
56      * @see com.sslexplorer.core.actions.AuthenticatedAction#onExecute(org.apache.struts.action.ActionMapping,
57      * org.apache.struts.action.ActionForm,
58      * javax.servlet.http.HttpServletRequest,
59      * javax.servlet.http.HttpServletResponse)
60      */

61     protected ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
62                     HttpServletResponse JavaDoc response) throws Exception JavaDoc {
63         ExtensionDescriptor desc = getExtensionDescriptor(mapping, form, request, response);
64         if(desc == null) {
65             throw new Exception JavaDoc("No application extension.");
66         }
67         SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
68         String JavaDoc ref = request.getParameter("returnTo");
69         if (ref == null) {
70            ref = CoreUtil.getReferer(request);
71            ref = ref == null ? "/showHome.do" : ref;
72         }
73         LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(session, null, null);
74         launchSession.setAttribute(Constants.LAUNCH_ATTR_AGENT_RETURN_TO, ref);
75         launchSession.setAttribute(Constants.LAUNCH_ATTR_AGENT_EXTENSION, desc);
76         request.setAttribute(Constants.REQ_ATTR_LAUNCH_SESSION, launchSession);
77         postSetup(mapping, form, request, response, launchSession);
78         return mapping.findForward("launchViaAgentApplet");
79     }
80
81     /**
82      * Invoked after launch session has been created.
83      *
84      * @param mapping
85      * @param form
86      * @param request
87      * @param response
88      * @param launchSession
89      */

90     protected abstract void postSetup(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, LaunchSession launchSession);
91
92     /**
93      * Get the descriptor for the application to launch. If the
94      * application cannot be launched for any reason an
95      * {@link Exception} should be thrown.
96      *
97      * @param mapping mapping
98      * @param form form
99      * @param request request
100      * @param response response
101      * @return extension
102      * @throws Exception on any error
103      */

104     protected abstract ExtensionDescriptor getExtensionDescriptor(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
105                     HttpServletResponse JavaDoc response) throws Exception JavaDoc;
106
107 }
Popular Tags