1 19 20 package com.sslexplorer.applications.types; 21 22 import java.io.IOException ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.jdom.Element; 33 34 import com.maverick.multiplex.Request; 35 import com.sslexplorer.agent.AgentTunnel; 36 import com.sslexplorer.agent.DefaultAgentManager; 37 import com.sslexplorer.applications.ApplicationLauncherType; 38 import com.sslexplorer.applications.ApplicationService; 39 import com.sslexplorer.applications.ApplicationShortcut; 40 import com.sslexplorer.extensions.ExtensionDescriptor; 41 import com.sslexplorer.extensions.ExtensionException; 42 import com.sslexplorer.policyframework.LaunchSession; 43 import com.sslexplorer.security.SessionInfo; 44 45 53 public class ExecutableType implements ApplicationLauncherType { 54 55 final static Log log = LogFactory.getLog(ExecutableType.class); 56 57 60 public final static String TYPE = "executable"; 61 62 68 public void start(ExtensionDescriptor descriptor, Element element) throws ExtensionException { 69 70 if (element.getName().equals(TYPE)) { 71 verifyExecutable(element); 72 } 73 74 } 75 76 81 public void verifyRequiredElements() throws ExtensionException { 82 83 } 84 85 88 public ActionForward launch(Map <String , String > parameters, ExtensionDescriptor descriptor, ApplicationShortcut shortcut, 89 ActionMapping mapping, LaunchSession launchSession, String returnTo, HttpServletRequest request) throws ExtensionException { 90 if (log.isInfoEnabled()) 91 log.info("Launching client application " + shortcut.getResourceName()); 92 93 if (DefaultAgentManager.getInstance().hasActiveAgent(launchSession.getSession())) { 96 try { 97 Request agentRequest = ((ApplicationService) DefaultAgentManager.getInstance().getService(ApplicationService.class)).launchApplication(launchSession); 98 AgentTunnel agent = DefaultAgentManager.getInstance().getAgentBySession(launchSession.getSession()); 99 if (!agent.sendRequest(agentRequest, true, 60000)) { 100 throw new ExtensionException(ExtensionException.AGENT_REFUSED_LAUNCH); 101 } 102 } catch (ExtensionException ee) { 103 throw ee; 104 } catch (Exception e) { 105 throw new ExtensionException(ExtensionException.INTERNAL_ERROR, e); 106 } 107 } else { 108 throw new ExtensionException(ExtensionException.NO_AGENT); 109 } 110 return null; 111 } 112 113 118 public boolean isHidden() { 119 return false; 120 } 121 122 127 public String getType() { 128 return TYPE; 129 } 130 131 136 public void stop() throws ExtensionException { 137 } 138 139 145 public boolean isAgentRequired(ApplicationShortcut shortcut, ExtensionDescriptor descriptor) { 146 return true; 147 } 148 149 154 public void activate() throws ExtensionException { 155 } 156 157 162 public boolean canStop() throws ExtensionException { 163 return true; 164 } 165 166 private void verifyExecutable(Element element) throws ExtensionException { 167 for (Iterator it = element.getChildren().iterator(); it.hasNext();) { 168 Element e = (Element) it.next(); 169 if (e.getName().equalsIgnoreCase("if")) { 170 verifyExecutable(e); 171 } else if (!e.getName().equalsIgnoreCase("arg") && !e.getName().equalsIgnoreCase("program") && !e.getName().equalsIgnoreCase("jvm")) { 172 throw new ExtensionException(ExtensionException.FAILED_TO_PROCESS_DESCRIPTOR, "Unexpected element <" + e.getName() 173 + "> found in <executable>"); 174 } 175 } 176 177 } 178 179 182 public void descriptorCreated(Element element, SessionInfo session) throws IOException { 183 } 184 185 188 public String getTypeBundle() { 189 return "applications"; 190 } 191 192 195 public boolean isServerSide() { 196 return false; 197 } 198 } | Popular Tags |