1 19 20 package com.sslexplorer.agent; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import com.sslexplorer.boot.RequestHandlerRequest; 26 import com.sslexplorer.security.User; 27 28 30 public class AgentManager { 31 private static final AgentManager instance = new AgentManager(); 32 private Map <String , AgentCallback> types = new HashMap <String , AgentCallback>(); 33 34 AgentManager() { 35 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 49 public static AgentManager getInstance() { 50 return instance; 51 } 52 53 61 public synchronized AgentTunnel createAgent(String remoteHost, User user, String 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 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 84 public void registerAgentType(String type, AgentCallback callback) { 85 types.put(type, callback); 86 } 87 88 92 public void deregisterAgentType(String type) { 93 types.remove(type); 94 } 95 96 101 public User authenticate(String type, RequestHandlerRequest request) { 102 AgentCallback callback = (AgentCallback) types.get(type); 103 return callback == null ? null : callback.authenticate(request); 104 } 105 } | Popular Tags |