1 19 20 package com.sslexplorer.policyframework.actions; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.apache.struts.Globals; 26 import org.apache.struts.action.ActionForm; 27 import org.apache.struts.action.ActionForward; 28 import org.apache.struts.action.ActionMapping; 29 import org.apache.struts.action.ActionMessages; 30 31 import com.sslexplorer.agent.DefaultAgentManager; 32 import com.sslexplorer.boot.Util; 33 import com.sslexplorer.core.CoreException; 34 import com.sslexplorer.core.CoreUtil; 35 import com.sslexplorer.core.RedirectWithMessages; 36 import com.sslexplorer.core.actions.AuthenticatedAction; 37 import com.sslexplorer.policyframework.LaunchSession; 38 import com.sslexplorer.policyframework.LaunchSessionFactory; 39 import com.sslexplorer.policyframework.LaunchSessionManager; 40 import com.sslexplorer.policyframework.Policy; 41 import com.sslexplorer.policyframework.Resource; 42 import com.sslexplorer.policyframework.ResourceType; 43 import com.sslexplorer.security.SessionInfo; 44 45 53 public abstract class AbstractLaunchAction extends AuthenticatedAction { 54 55 private ResourceType resourceType; 56 private int navigationContext; 57 58 65 public AbstractLaunchAction(ResourceType resourceType, int navigationContext) { 66 super(); 67 this.resourceType = resourceType; 68 this.navigationContext = navigationContext; 69 } 70 71 74 public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 75 throws Exception { 76 String id = request.getParameter("resourceId"); 77 String returnTo = request.getParameter("returnTo"); 78 if (Util.isNullOrTrimmedBlank(id)) { 79 throw new Exception ("No resource ID supplied."); 80 } 81 if (Util.isNullOrTrimmedBlank(returnTo)) { 82 throw new Exception ("No returnTo path supplied."); 83 } 84 Resource resource = resourceType.getResourceById(Integer.parseInt(id)); 85 if(resource == null) { 86 throw new Exception ("No resource with ID " + id); 87 } 88 SessionInfo session = getSessionInfo(request); 89 Policy policy = LaunchSessionManager.getLaunchRequestPolicy(request, session, resource); 90 Util.noCache(response); 91 if(resource.sessionPasswordRequired(session)) { 92 return new ActionForward("/promptForSessionPassword.do?forwardTo=" + Util.urlEncode(CoreUtil.getRealRequestURI(request) + "?resourceId=" + id + "&policy=" + policy.getResourceId() + "&returnTo=" + Util.urlEncode(returnTo)), true); 94 } 95 else { 96 if(isAgentRequired(resource) && !DefaultAgentManager.getInstance().hasActiveAgent(request)) { 98 return new ActionForward("/launchAgent.do?returnTo=" + Util.urlEncode(CoreUtil.getRealRequestURI(request) + "?resourceId=" + id + "&policy=" + policy.getResourceId() + "&returnTo=" + Util.urlEncode(returnTo)), true); 99 } 100 else { 101 LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(session, resource, policy); 102 launchSession.checkAccessRights(null, session); 103 try { 104 return launch(mapping, launchSession, request, returnTo); 105 } 106 catch(CoreException ce) { 107 ActionMessages errs = new ActionMessages(); 108 errs.add(Globals.ERROR_KEY, ce.getBundleActionMessage()); 109 saveErrors(request, errs); 110 return new RedirectWithMessages(returnTo, request); 111 } 112 } 113 } 114 } 115 116 protected abstract ActionForward launch(ActionMapping mapping, LaunchSession launchSession, HttpServletRequest request, String returnTo) 117 throws Exception ; 118 119 protected abstract boolean isAgentRequired(Resource resource); 120 121 129 130 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 131 return navigationContext; 132 } 133 } 134 | Popular Tags |