KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > networkplaces > NetworkPlaceService


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

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         // TODO Auto-generated constructor stub
45
}
46
47     static Log log = LogFactory.getLog(NetworkPlaceService.class);
48
49     
50     /**
51      * Setup and launch network place
52      */

53     public static final String JavaDoc SETUP_AND_LAUNCH_NETWORK_PLACE = "setupAndLaunchNetworkPlace@3sp.com"; //$NON-NLS-1$
54

55     
56     /**
57      * Constructor
58      */

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 JavaDoc("No resource with ID " + id);
82                 }
83                 Policy policy = LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource);
84                 if (resource.sessionPasswordRequired(agent.getSession())) {
85                     // TODO: prompt user for credentials through agent!
86
return true;
87                 } else {
88                     LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(agent.getSession(),
89                         resource,
90                         policy);
91                     launchSession.checkAccessRights(null, agent.getSession());
92                     String JavaDoc 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 JavaDoc 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 JavaDoc type) throws ChannelOpenException {
110         return null;
111     }
112 }
113
Popular Tags