1 19 20 package com.sslexplorer.webforwards.webforwardwizard.actions; 21 22 import java.util.ArrayList ; 23 import java.util.Calendar ; 24 import java.util.List ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 import javax.servlet.http.HttpServletResponse ; 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 63 public class WebForwardFinishAction extends AbstractFinishWizardAction { 64 final static Log log = LogFactory.getLog(WebForwardFinishAction.class); 65 66 69 public WebForwardFinishAction() { 70 super(); 71 } 72 73 81 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 82 return SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 83 } 84 85 93 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 94 HttpServletResponse response) throws Exception { 95 List <WizardActionStatus> actionStatus = new ArrayList <WizardActionStatus>(); 96 AbstractWizardSequence seq = getWizardSequence(request); 97 String name = (String ) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_RESOURCE_NAME, null); 98 String description = (String ) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_RESOURCE_DESCRIPTION, null); 99 boolean favorite = ((Boolean ) seq.getAttribute(WebForwardResourceDetailsForm.ATTR_FAVORITE, Boolean.FALSE)).booleanValue(); 100 101 int type = ((Integer ) seq.getAttribute(WebForwardTypeSelectionForm.ATTR_TYPE, new Integer (0))).intValue(); 102 String category = (String ) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_CATEGORY, null); 103 String destinationURL = (String ) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_DESTINATION_URL, null); 104 105 PropertyList restrictToHosts = ((PropertyList) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_RESTRICT_TO_HOSTS, null)); 106 String encodeing = (String ) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_ENCODEING, ""); 107 108 String authenticationUsername = (String ) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_AUTHENTICATION_USERNAME, 109 null); 110 String authenticationPassword = (String ) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_AUTHENTICATION_PASSWORD, 111 null); 112 String preferredAuthenticationScheme = (String ) seq.getAttribute( 113 WebForwardAuthenticationDetailsForm.ATTR_PREFERRED_AUTHENTICATION_SCHEME, null); 114 115 String paths = (String ) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_PATHS, ""); 116 String hostHeader = (String ) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_HOST_HEADER, ""); 117 boolean activeDNS = ((Boolean ) seq.getAttribute(WebForwardSpecificDetailsForm.ATTR_ACTIVE_DNS, Boolean.FALSE)) 118 .booleanValue(); 119 120 String formParameters = (String ) seq.getAttribute(WebForwardAuthenticationDetailsForm.ATTR_FORM_PARAMETERS, ""); 121 String formType = (String ) 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 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 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 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 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 227 public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 228 throws Exception { 229 return cancel(mapping, form, request, response); 230 } 231 232 240 protected AbstractWizardSequence createWizardSequence(ActionMapping mapping, ActionForm form, HttpServletRequest request, 241 HttpServletResponse response) throws Exception { 242 throw new Exception ("Cannot create sequence on this page."); 243 } 244 245 } 246 | Popular Tags |