KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > webforwards > webforwardwizard > actions > WebForwardFinishAction


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.webforwardwizard.actions;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Calendar JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletResponse JavaDoc;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.apache.struts.action.ActionForm;
32 import org.apache.struts.action.ActionForward;
33 import org.apache.struts.action.ActionMapping;
34
35 import com.sslexplorer.boot.PropertyList;
36 import com.sslexplorer.core.CoreEvent;
37 import com.sslexplorer.core.CoreServlet;
38 import com.sslexplorer.policyframework.ResourceChangeEvent;
39 import com.sslexplorer.security.SessionInfo;
40 import com.sslexplorer.security.User;
41 import com.sslexplorer.webforwards.AbstractAuthenticatingWebForward;
42 import com.sslexplorer.webforwards.WebForward;
43 import com.sslexplorer.webforwards.WebForwardDatabaseFactory;
44 import com.sslexplorer.webforwards.WebForwardEventConstants;
45 import com.sslexplorer.webforwards.WebForwardTypeItem;
46 import com.sslexplorer.webforwards.WebForwardTypes;
47 import com.sslexplorer.webforwards.webforwardwizard.forms.WebForwardAuthenticationDetailsForm;
48 import com.sslexplorer.webforwards.webforwardwizard.forms.WebForwardResourceDetailsForm;
49 import com.sslexplorer.webforwards.webforwardwizard.forms.WebForwardSpecificDetailsForm;
50 import com.sslexplorer.webforwards.webforwardwizard.forms.WebForwardTypeSelectionForm;
51 import com.sslexplorer.wizard.AbstractWizardSequence;
52 import com.sslexplorer.wizard.WizardActionStatus;
53 import com.sslexplorer.wizard.actions.AbstractFinishWizardAction;
54 import com.sslexplorer.wizard.forms.AbstractWizardFinishForm;
55
56 /**
57  * <p>
58  * The final action in which the resource is created.
59  *
60  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
61  *
62  */

63 public class WebForwardFinishAction extends AbstractFinishWizardAction {
64     final static Log log = LogFactory.getLog(WebForwardFinishAction.class);
65
66     /**
67      * Constructor.
68      */

69     public WebForwardFinishAction() {
70         super();
71     }
72
73     /*
74      * (non-Javadoc)
75      *
76      * @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping,
77      * org.apache.struts.action.ActionForm,
78      * javax.servlet.http.HttpServletRequest,
79      * javax.servlet.http.HttpServletResponse)
80      */

81     public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
82         return SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
83     }
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see org.apache.struts.actions.DispatchAction#unspecified(org.apache.struts.action.ActionMapping,
89      * org.apache.struts.action.ActionForm,
90      * javax.servlet.http.HttpServletRequest,
91      * javax.servlet.http.HttpServletResponse)
92      */

93     public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
94                                      HttpServletResponse JavaDoc response) throws Exception JavaDoc {
95         List JavaDoc<WizardActionStatus> actionStatus = new ArrayList JavaDoc<WizardActionStatus>();
96         AbstractWizardSequence seq = getWizardSequence(request);
97         String JavaDoc name = (String JavaDoc) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_RESOURCE_NAME, null);
98         String JavaDoc description = (String JavaDoc) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_RESOURCE_DESCRIPTION, null);
99         boolean favorite = ((Boolean JavaDoc) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_FAVORITE, Boolean.FALSE)).booleanValue();
100
101         int type = ((Integer JavaDoc) seq.getAttribute(WebForwardTypeSelectionForm.ATTR_TYPE, new Integer JavaDoc(0))).intValue();
102         String JavaDoc category = (String JavaDoc) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_CATEGORY, null);
103         String JavaDoc destinationURL = (String JavaDoc) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_DESTINATION_URL, null);
104
105         PropertyList restrictToHosts = ((PropertyList) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_RESTRICT_TO_HOSTS, null));
106         String JavaDoc encodeing = (String JavaDoc) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_ENCODEING, "");
107
108         String JavaDoc authenticationUsername = (String JavaDoc) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_AUTHENTICATION_USERNAME,
109             null);
110         String JavaDoc authenticationPassword = (String JavaDoc) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_AUTHENTICATION_PASSWORD,
111             null);
112         String JavaDoc preferredAuthenticationScheme = (String JavaDoc) seq.getAttribute(
113             WebForwardAuthenticationDetailsForm.ATTR_PREFERRED_AUTHENTICATION_SCHEME, null);
114
115         String JavaDoc paths = (String JavaDoc) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_PATHS, "");
116         String JavaDoc hostHeader = (String JavaDoc) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_HOST_HEADER, "");
117         boolean activeDNS = ((Boolean JavaDoc) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_ACTIVE_DNS, Boolean.FALSE))
118                         .booleanValue();
119
120         String JavaDoc formParameters = (String JavaDoc) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_FORM_PARAMETERS, "");
121         String JavaDoc formType = (String JavaDoc) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_FORM_TYPE, "");
122
123         User user = this.getSessionInfo(request).getUser();
124         
125         WebForward webForward = null;
126         try {
127             try {
128                 Calendar JavaDoc now = Calendar.getInstance();
129
130                 if (type == WebForward.TYPE_TUNNELED_SITE) {
131                     com.sslexplorer.webforwards.TunneledSiteWebForward sswf = new com.sslexplorer.webforwards.TunneledSiteWebForward(user.getRealm().getRealmID(),
132                                     -1, destinationURL, name, description, category, now, now);
133                     webForward = WebForwardDatabaseFactory.getInstance().createWebForward(sswf);
134                     CoreEvent evt = new ResourceChangeEvent(this, WebForwardEventConstants.CREATE_WEB_FORWARD, webForward, this
135                                     .getSessionInfo(request), CoreEvent.STATE_SUCCESSFUL).addAttribute(
136                                                     WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_CATEGORY, webForward.getCategory()).addAttribute(
137                                                                     WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_TYPE,
138                         ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(webForward.getType())).getName()).addAttribute(
139                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_URL, webForward.getDestinationURL());
140                     CoreServlet.getServlet().fireCoreEvent(evt);
141                 } else if (type == WebForward.TYPE_REPLACEMENT_PROXY) {
142                     com.sslexplorer.webforwards.ReplacementProxyWebForward spwf = new com.sslexplorer.webforwards.ReplacementProxyWebForward(user.getRealm().getRealmID(),
143                                     -1, destinationURL, name, description, category, authenticationUsername,
144                                     authenticationPassword, preferredAuthenticationScheme, encodeing, restrictToHosts, formType,
145                                     formParameters, now, now);
146
147                     AbstractAuthenticatingWebForward abstractAuthenticatingWebForward = (AbstractAuthenticatingWebForward) WebForwardDatabaseFactory
148                                     .getInstance().createWebForward(spwf);
149                     CoreEvent evt = new ResourceChangeEvent(this, WebForwardEventConstants.CREATE_WEB_FORWARD, abstractAuthenticatingWebForward, this
150                                     .getSessionInfo(request), CoreEvent.STATE_SUCCESSFUL).addAttribute(
151                                                     WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_CATEGORY, abstractAuthenticatingWebForward.getCategory()).addAttribute(
152                                                                     WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_TYPE,
153                         ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(abstractAuthenticatingWebForward.getType())).getName()).addAttribute(
154                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_URL, abstractAuthenticatingWebForward.getDestinationURL()).addAttribute(
155                                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_PREFERED_AUTH_SCHEME,
156                         abstractAuthenticatingWebForward.getPreferredAuthenticationScheme()).addAttribute(
157                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_AUTH_USERNAME,
158                         abstractAuthenticatingWebForward.getAuthenticationUsername()).addAttribute(
159                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_AUTH_FORM_TYPE,
160                         abstractAuthenticatingWebForward.getFormType()).addAttribute(
161                                         WebForwardEventConstants.EVENT_ATTR_REPLACEMENT_WEB_FORWARD_ENCODEING, spwf.getEncoding());
162
163                     spwf.addFormParametersToEvent(evt, WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_AUTH_FORM_PARAMETERS);
164                     spwf
165                                     .addRestrictToHostsToEvent(evt,
166                                                     WebForwardEventConstants.EVENT_ATTR_REPLACEMENT_WEB_FORWARD_RESTRICT_TO_HOSTS);
167                     CoreServlet.getServlet().fireCoreEvent(evt);
168                     webForward = abstractAuthenticatingWebForward;
169                 } else if (type == WebForward.TYPE_PATH_BASED_REVERSE_PROXY || type == WebForward.TYPE_HOST_BASED_REVERSE_PROXY) {
170                     com.sslexplorer.webforwards.ReverseProxyWebForward rpwf = new com.sslexplorer.webforwards.ReverseProxyWebForward(user.getRealm().getRealmID(),
171                                     -1, type, destinationURL, name, description, category, authenticationUsername,
172                                     authenticationPassword, preferredAuthenticationScheme, formType, formParameters, paths,
173                                     hostHeader, activeDNS, now, now, encodeing);
174                     AbstractAuthenticatingWebForward abstractAuthenticatingWebForward = (AbstractAuthenticatingWebForward) WebForwardDatabaseFactory
175                                     .getInstance().createWebForward(rpwf);
176                     CoreEvent evt = new ResourceChangeEvent(this, WebForwardEventConstants.CREATE_WEB_FORWARD, abstractAuthenticatingWebForward, this
177                                     .getSessionInfo(request), CoreEvent.STATE_SUCCESSFUL).addAttribute(
178                                                     WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_CATEGORY, abstractAuthenticatingWebForward.getCategory()).addAttribute(
179                                                                     WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_TYPE,
180                         ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(abstractAuthenticatingWebForward.getType())).getName()).addAttribute(
181                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_URL, abstractAuthenticatingWebForward.getDestinationURL()).addAttribute(
182                                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_PREFERED_AUTH_SCHEME,
183                         abstractAuthenticatingWebForward.getPreferredAuthenticationScheme()).addAttribute(
184                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_AUTH_USERNAME,
185                         abstractAuthenticatingWebForward.getAuthenticationUsername()).addAttribute(
186                                         WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_AUTH_FORM_TYPE,
187                         abstractAuthenticatingWebForward.getFormType()).addAttribute(
188                                         WebForwardEventConstants.EVENT_ATTR_REVERSE_WEB_FORWARD_ACTIVE_DNS, String.valueOf(rpwf.getActiveDNS()))
189                                     .addAttribute(WebForwardEventConstants.EVENT_ATTR_REVERSE_WEB_FORWARD_HOST_HEADER,
190                                         rpwf.getHostHeader());
191
192                     rpwf.addPathsToEvent(evt, WebForwardEventConstants.EVENT_ATTR_REVERSE_WEB_FORWARD_PATHS);
193                     rpwf.addCustomHeadersToEvent(evt, WebForwardEventConstants.EVENT_ATTR_REVERSE_WEB_FORWARD_CUSTOM_HEADERS);
194                     rpwf.addFormParametersToEvent(evt, WebForwardEventConstants.EVENT_ATTR_WEB_FORWARD_AUTH_FORM_PARAMETERS);
195                     CoreServlet.getServlet().fireCoreEvent(evt);
196                     webForward = abstractAuthenticatingWebForward;
197                 }
198
199             } catch (Exception JavaDoc e) {
200                 CoreServlet.getServlet().fireCoreEvent(
201                     new ResourceChangeEvent(this, WebForwardEventConstants.CREATE_WEB_FORWARD, this.getSessionInfo(request), e));
202                 throw e;
203             }
204             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
205                             "webForwardWizard.webForwardFinish.status.profileCreated"));
206         } catch (Exception JavaDoc e) {
207             log.error("Failed to create profile.", e);
208             actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
209                             "webForwardWizard.webForwardFinish.status.failedToCreateProfile", e.getMessage()));
210         }
211         // TODO do the attaching.
212
if (webForward != null) {
213             actionStatus.add(attachToPoliciesAndAddToFavorites("webForwardWizard.webForwardFinish", seq, webForward, favorite, request));
214         }
215         ((AbstractWizardFinishForm) form).setActionStatus(actionStatus);
216         return super.unspecified(mapping, form, request, response);
217     }
218
219     /*
220      * (non-Javadoc)
221      *
222      * @see com.sslexplorer.wizard.actions.AbstractFinishWizardAction#exit(org.apache.struts.action.ActionMapping,
223      * org.apache.struts.action.ActionForm,
224      * javax.servlet.http.HttpServletRequest,
225      * javax.servlet.http.HttpServletResponse)
226      */

227     public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
228                     throws Exception JavaDoc {
229         return cancel(mapping, form, request, response);
230     }
231
232     /*
233      * (non-Javadoc)
234      *
235      * @see com.sslexplorer.wizard.actions.AbstractWizardAction#createWizardSequence(org.apache.struts.action.ActionMapping,
236      * org.apache.struts.action.ActionForm,
237      * javax.servlet.http.HttpServletRequest,
238      * javax.servlet.http.HttpServletResponse)
239      */

240     protected AbstractWizardSequence createWizardSequence(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request,
241                                                           HttpServletResponse JavaDoc response) throws Exception JavaDoc {
242         throw new Exception JavaDoc("Cannot create sequence on this page.");
243     }
244
245 }
246
Popular Tags