KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > agent > AgentManager


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.agent;
21
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import com.sslexplorer.boot.RequestHandlerRequest;
26 import com.sslexplorer.security.User;
27
28 /**
29  */

30 public class AgentManager {
31     private static final AgentManager instance = new AgentManager();
32     private Map JavaDoc<String JavaDoc, AgentCallback> types = new HashMap JavaDoc<String JavaDoc, AgentCallback>();
33
34     AgentManager() {
35         // The default type of agent is the SSL-Explorer Agent
36
types.put(DefaultAgentCallback.DEFAULT_AGENT_TYPE, new DefaultAgentCallback());
37         if (System.getProperty("sslexplorer.agent.debug", "").equals("enabled")) {
38             types.put(DefaultAgentCallback.DEFAULT_AGENT_TYPE, new DummyAgentCallback());
39         } else if (System.getProperty("sslexplorer.agent.debug", "").equals("interactive")) {
40             types.put(DefaultAgentCallback.DEFAULT_AGENT_TYPE, new InteractiveAgentCallback());
41         } else if (System.getProperty("sslexplorer.agent.debug", "").equals("attach")) {
42             types.put(DefaultAgentCallback.DEFAULT_AGENT_TYPE, new AttachAgentCallback());
43         }
44     }
45
46     /**
47      * @return AgentManager
48      */

49     public static AgentManager getInstance() {
50         return instance;
51     }
52
53     /**
54      * @param remoteHost
55      * @param user
56      * @param type
57      * @param connectionParameters
58      * @return AgentTunnel
59      * @throws AgentException
60      */

61     public synchronized AgentTunnel createAgent(String JavaDoc remoteHost, User user, String JavaDoc type, RequestHandlerRequest connectionParameters) throws AgentException {
62         AgentCallback callback = (AgentCallback) types.get(type);
63         if (callback != null) {
64             return callback.createAgent(remoteHost, user, type, connectionParameters);
65         } else
66             return null;
67     }
68
69     /**
70      * @param tunnel
71      * @throws AgentException
72      */

73     public synchronized void removeAgent(AgentTunnel tunnel) throws AgentException {
74         AgentCallback callback = (AgentCallback) types.get(tunnel.getType());
75         if (callback != null)
76             callback.removeAgent(tunnel);
77     }
78
79     /**
80      * Register a new agent callback.
81      * @param type - the type of agent
82      * @param callback - the callback to use
83      */

84     public void registerAgentType(String JavaDoc type, AgentCallback callback) {
85         types.put(type, callback);
86     }
87
88     /**
89      * Deregister an agent callback
90      * @param type - the type of agent
91      */

92     public void deregisterAgentType(String JavaDoc type) {
93         types.remove(type);
94     }
95
96     /**
97      * @param type
98      * @param request
99      * @return User
100      */

101     public User authenticate(String JavaDoc type, RequestHandlerRequest request) {
102         AgentCallback callback = (AgentCallback) types.get(type);
103         return callback == null ? null : callback.authenticate(request);
104     }
105 }
Popular Tags