KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > webforwards > WebForwardService


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.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     /**
45      * Setup and launch web forward
46      */

47     public static final String JavaDoc SETUP_AND_LAUNCH_WEB_FORWARD = "setupAndLaunchWebForward@3sp.com"; //$NON-NLS-1$
48

49     
50     /**
51      * Constructor
52      */

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 JavaDoc("No resource with ID " + id);
76                 }
77                 Policy policy = LaunchSessionManager.getLaunchRequestPolicy(null, agent.getSession(), resource);
78                 if (resource.sessionPasswordRequired(agent.getSession())) {
79                     // TODO: prompt user for credentials through agent!
80
return true;
81                 } else {
82                     LaunchSession launchSession = LaunchSessionFactory.getInstance().createLaunchSession(agent.getSession(),
83                         resource,
84                         policy);
85                     launchSession.checkAccessRights(null, agent.getSession());
86                     String JavaDoc 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 JavaDoc 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 JavaDoc type) throws ChannelOpenException {
101         return null;
102     }
103
104     public void postReply(MultiplexedConnection connection) {
105     }
106 }
107
Popular Tags