1 19 20 package com.sslexplorer.webforwards; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import com.maverick.multiplex.Channel; 26 import com.maverick.multiplex.ChannelOpenException; 27 import com.maverick.multiplex.MultiplexedConnection; 28 import com.maverick.multiplex.Request; 29 import com.maverick.multiplex.RequestHandler; 30 import com.maverick.util.ByteArrayReader; 31 import com.maverick.util.ByteArrayWriter; 32 import com.sslexplorer.agent.AbstractResourceService; 33 import com.sslexplorer.agent.AgentTunnel; 34 import com.sslexplorer.policyframework.LaunchSession; 35 import com.sslexplorer.policyframework.LaunchSessionFactory; 36 import com.sslexplorer.policyframework.LaunchSessionManager; 37 import com.sslexplorer.policyframework.Policy; 38 39 public class WebForwardService extends AbstractResourceService implements RequestHandler { 40 41 static Log log = LogFactory.getLog(WebForwardService.class); 42 43 44 47 public static final String SETUP_AND_LAUNCH_WEB_FORWARD = "setupAndLaunchWebForward@3sp.com"; 49 50 53 public WebForwardService() { 54 super(WebForwardPlugin.WEBFORWARD_RESOURCE_TYPE, new int[] { 55 WebForwardEventConstants.CREATE_WEB_FORWARD, 56 WebForwardEventConstants.DELETE_WEBFORWARD, 57 WebForwardEventConstants.UPDATE_WEB_FORWARD }); 58 } 59 60 public void performStartup(AgentTunnel tunnel) { 61 } 62 63 public void initializeTunnel(AgentTunnel tunnel) { 64 tunnel.registerRequestHandler(SETUP_AND_LAUNCH_WEB_FORWARD, this); 65 } 66 67 public boolean processRequest(Request request, MultiplexedConnection connection) { 68 AgentTunnel agent = (AgentTunnel) connection; 69 if (request.getRequestName().equals(SETUP_AND_LAUNCH_WEB_FORWARD) && request.getRequestData()!=null) { 70 try { 71 ByteArrayReader reader = new ByteArrayReader(request.getRequestData()); 72 int id = (int)reader.readInt(); 73 WebForward resource = (WebForward)WebForwardPlugin.WEBFORWARD_RESOURCE_TYPE.getResourceById(id); 74 if (resource == null) { 75 throw new Exception ("No resource with ID " + id); 76 } 77 Policy policy = LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource); 78 if (resource.sessionPasswordRequired(agent.getSession())) { 79 return true; 81 } else { 82 LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(agent.getSession(), 83 resource, 84 policy); 85 launchSession.checkAccessRights(null, agent.getSession()); 86 String uri = resource.getLaunchUri(launchSession); 87 ByteArrayWriter baw = new ByteArrayWriter(); 88 baw.writeString(uri); 89 request.setRequestData(baw.toByteArray()); 90 return true; 91 } 92 } catch (Exception e) { 93 log.error("Failed to start tunnel.", e); 94 return false; 95 } 96 } 97 return false; 98 } 99 100 public Channel createChannel(MultiplexedConnection connection, String type) throws ChannelOpenException { 101 return null; 102 } 103 104 public void postReply(MultiplexedConnection connection) { 105 } 106 } 107 | Popular Tags |