Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 195644 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 11-17 Link Here
11
 org.eclipse.tptp.platform.common;bundle-version="[4.3.0,5.0.0)",
11
 org.eclipse.tptp.platform.common;bundle-version="[4.3.0,5.0.0)",
12
 org.eclipse.tptp.platform.models;bundle-version="[4.1.0,5.0.0)",
12
 org.eclipse.tptp.platform.models;bundle-version="[4.1.0,5.0.0)",
13
 org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
13
 org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
14
 org.eclipse.hyades.execution;bundle-version="[4.1.0,5.0.0)"
14
 org.eclipse.hyades.execution;bundle-version="[4.1.0,5.0.0)",
15
 org.eclipse.tptp.platform.execution
15
Eclipse-LazyStart: true
16
Eclipse-LazyStart: true
16
Export-Package: org.eclipse.hyades.execution.security,
17
Export-Package: org.eclipse.hyades.execution.security,
17
 org.eclipse.hyades.security.internal.util,
18
 org.eclipse.hyades.security.internal.util,
(-)src-common-internal/org/eclipse/tptp/platform/common/ui/internal/util/ACConnectionPool.java (+123 lines)
Added Link Here
1
package org.eclipse.tptp.platform.common.ui.internal.util;
2
3
import java.io.IOException;
4
import java.net.InetAddress;
5
6
import org.eclipse.hyades.internal.execution.local.common.ControlMessage;
7
import org.eclipse.hyades.internal.execution.local.control.CommandHandler;
8
import org.eclipse.hyades.internal.execution.local.control.ConnectionListener;
9
import org.eclipse.hyades.internal.execution.local.control.Node;
10
import org.eclipse.hyades.internal.execution.security.AuthenticationListener;
11
import org.eclipse.hyades.internal.execution.security.LoginFailedException;
12
import org.eclipse.hyades.internal.execution.security.SecureConnectionRequiredException;
13
import org.eclipse.hyades.internal.execution.security.UntrustedAgentControllerException;
14
import org.eclipse.hyades.security.internal.util.ConnectUtilUI;
15
import org.eclipse.hyades.security.internal.util.IConnectUtilUser;
16
import org.eclipse.tptp.platform.execution.client.core.IAgentController;
17
import org.eclipse.tptp.platform.execution.security.User;
18
import org.eclipse.tptp.platform.execution.util.internal.AgentControllerPool;
19
20
public class ACConnectionPool extends AgentControllerPool {
21
	public static AgentControllerPool getInstance() {
22
		if (instance == null) instance = new ACConnectionPool();
23
		return instance;
24
	}
25
26
	public static IAgentController getACConnection(String hostName, int portNumber) throws Exception {
27
		return getInstance().getConnection(hostName, portNumber);
28
	}
29
	
30
	public static IAgentController getACConnection(String hostName, int portNumber, 
31
			boolean reuseExistingConnection) throws Exception {
32
33
		return getInstance().getConnection(hostName, portNumber, reuseExistingConnection);
34
	}
35
	
36
	public User promptAuthentication(String hostName, String userName) {
37
		ConnectUtilUI cui = new ConnectUtilUI();
38
		IConnectUtilUser cuUser = cui.promptAuthentication(hostName, userName);
39
		if(cuUser == null) return null;
40
		
41
		return new User(null, cuUser.getName(), cuUser.getPassword());
42
	}
43
	
44
	public User findUser(String hostName) {
45
		User user = findUserForHost (hostName);
46
		if (user != null) return user;
47
		
48
		if ("localhost".equals(hostName))
49
			return findUserForHost (null);
50
		
51
		return null;
52
	}
53
	
54
	private User findUserForHost (String hostName) {
55
		org.eclipse.hyades.internal.execution.local.control.Node node;
56
		
57
		try {
58
			if (hostName != null)
59
				node = org.eclipse.hyades.internal.execution.local.control.NodeFactory.getNode(hostName, null);
60
			else
61
				node = org.eclipse.hyades.internal.execution.local.control.NodeFactory.getNode(InetAddress.getLocalHost(), null);
62
		} catch (Exception e) {
63
			node = null;
64
		}
65
		
66
		if (node == null || !node.isConnected()) {
67
			return null;
68
		}
69
		
70
		org.eclipse.hyades.internal.execution.security.User hyadesUser = node.getUser();
71
		if (hyadesUser == null) {
72
			return null;
73
		}
74
							// just to extract the password saving current hyades.User API
75
		HyadesConnection con = new HyadesConnection();
76
		try { hyadesUser.login(con); } catch (Exception e) {}
77
		
78
		return con.getUser();
79
	}
80
	
81
	class HyadesConnection implements org.eclipse.hyades.internal.execution.local.control.Connection {
82
		public User user = null;
83
84
		public void sendMessage(ControlMessage msg, CommandHandler handler)	throws IOException {
85
			int count = msg.getSize();
86
			if (count <= 1) return;
87
88
			org.eclipse.hyades.internal.execution.local.common.CommandElement ce = msg.getCommand(0);
89
			if (!(ce instanceof org.eclipse.hyades.internal.execution.local.common.AuthenticateCommand)) return;
90
			
91
			org.eclipse.hyades.internal.execution.local.common.AuthenticateCommand acmd =
92
				(org.eclipse.hyades.internal.execution.local.common.AuthenticateCommand) ce;
93
			
94
			byte buf[] = new byte[acmd.getSize()];
95
			acmd.writeToBuffer(buf, 0);
96
97
			org.eclipse.hyades.internal.execution.local.common.RAString hyadesName = 
98
				new org.eclipse.hyades.internal.execution.local.common.RAString();
99
			
100
			org.eclipse.hyades.internal.execution.local.common.RAString hyadesPsw = 
101
				new org.eclipse.hyades.internal.execution.local.common.RAString();
102
103
			int offset = org.eclipse.hyades.internal.execution.local.common.Message.readRAStringFromBuffer(buf, 4, hyadesName);
104
			org.eclipse.hyades.internal.execution.local.common.Message.readRAStringFromBuffer(buf, offset, hyadesPsw);
105
			
106
			user = new User(null, hyadesName.getData(), hyadesPsw.getData());
107
		}
108
109
		public void addAuthenticationListener(AuthenticationListener listener) {}
110
		public void addConnectionListener(ConnectionListener listener) {}
111
		public void connect(Node node, int port) throws IOException,SecureConnectionRequiredException, LoginFailedException,
112
				UntrustedAgentControllerException {
113
		}
114
		public void disconnect() {}
115
		public Node getNode() { return null; }
116
		public int getPort() { return 0; }
117
		public boolean isActive() {	return false; }
118
		public void removeAuthenticationListener(AuthenticationListener listener) {}
119
		public void removeConnectionListener(ConnectionListener listener) {}
120
		
121
		public User getUser() { return user; }
122
	}
123
}

Return to bug 195644