1 19 20 package com.sslexplorer.networkplaces; 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 import com.sslexplorer.policyframework.ResourceType; 39 40 public class NetworkPlaceService extends AbstractResourceService implements RequestHandler { 41 42 public NetworkPlaceService(ResourceType resourceType, int[] events) { 43 super(resourceType, events); 44 } 46 47 static Log log = LogFactory.getLog(NetworkPlaceService.class); 48 49 50 53 public static final String SETUP_AND_LAUNCH_NETWORK_PLACE = "setupAndLaunchNetworkPlace@3sp.com"; 55 56 59 public NetworkPlaceService() { 60 super(NetworkPlacePlugin.NETWORK_PLACE_RESOURCE_TYPE, new int[] { 61 NetworkPlacesEventConstants.CREATE_NETWORK_PLACE, 62 NetworkPlacesEventConstants.DELETE_NETWORK_PLACE, 63 NetworkPlacesEventConstants.UPDATE_NETWORK_PLACE }); 64 } 65 66 public void performStartup(AgentTunnel tunnel) { 67 } 68 69 public void initializeTunnel(AgentTunnel tunnel) { 70 tunnel.registerRequestHandler(SETUP_AND_LAUNCH_NETWORK_PLACE, this); 71 } 72 73 public boolean processRequest(Request request, MultiplexedConnection connection) { 74 AgentTunnel agent = (AgentTunnel) connection; 75 if (request.getRequestName().equals(SETUP_AND_LAUNCH_NETWORK_PLACE) && request.getRequestData()!=null) { 76 try { 77 ByteArrayReader reader = new ByteArrayReader(request.getRequestData()); 78 int id = (int)reader.readInt(); 79 NetworkPlace resource = (NetworkPlace)NetworkPlacePlugin.NETWORK_PLACE_RESOURCE_TYPE.getResourceById(id); 80 if (resource == null) { 81 throw new Exception ("No resource with ID " + id); 82 } 83 Policy policy = LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource); 84 if (resource.sessionPasswordRequired(agent.getSession())) { 85 return true; 87 } else { 88 LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(agent.getSession(), 89 resource, 90 policy); 91 launchSession.checkAccessRights(null, agent.getSession()); 92 String uri = resource.getLaunchUri(launchSession); 93 ByteArrayWriter baw = new ByteArrayWriter(); 94 baw.writeString(uri); 95 request.setRequestData(baw.toByteArray()); 96 return true; 97 } 98 } catch (Exception e) { 99 log.error("Failed to start tunnel.", e); 100 return false; 101 } 102 } 103 return false; 104 } 105 106 public void postReply(MultiplexedConnection connection) { 107 } 108 109 public Channel createChannel(MultiplexedConnection connection, String type) throws ChannelOpenException { 110 return null; 111 } 112 } 113
| Popular Tags
|