Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 73419 Details for
Bug 195644
Add security support to New Agent Controller
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Platform.Execution patch
platform_execution.txt (text/plain), 78.90 KB, created by
Igor Alelekov
on 2007-07-10 10:31:03 EDT
(
hide
)
Description:
Platform.Execution patch
Filename:
MIME Type:
Creator:
Igor Alelekov
Created:
2007-07-10 10:31:03 EDT
Size:
78.90 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.tptp.platform.execution >Index: src/org/eclipse/tptp/platform/execution/util/internal/Constants.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/util/internal/Constants.java,v >retrieving revision 1.15 >diff -u -r1.15 Constants.java >--- src/org/eclipse/tptp/platform/execution/util/internal/Constants.java 3 May 2007 21:38:02 -0000 1.15 >+++ src/org/eclipse/tptp/platform/execution/util/internal/Constants.java 9 Jul 2007 14:37:56 -0000 >@@ -103,6 +103,12 @@ > public static final long CONNECT_DATA =0x10000000; > public static final long DATA_CONNECTION_COMPLETE =0x20000000; > public static final long DATA_CONNECTION_REFUSED =0x40000000; >+ >+ public static final long SECURITY_REQUIRED =0x00010000; >+ public static final long AUTHENTICATE =0x00020000; >+ public static final long AUTHENTICATION_FAILED =0x00040000; >+ public static final long AUTHENTICATION_SUCCESSFUL =0x00080000; >+ > public static final long DATA_PATH_SEND =0x00000001; > public static final long DATA_PATH_RECEIVE =0x00000002; > public static final long DATA_PATH_TWO_WAY = DATA_PATH_SEND | DATA_PATH_RECEIVE; >@@ -204,6 +210,7 @@ > public static final int PROCESS_LAUNCH_TIMEOUT_TRY_COUNT = 50; > public static final int DSSRVR_LAUNCH_TIMEOUT_TRY_COUNT = 1000; > public static final int CONNECT_TIMEOUT_TRY_COUNT = 32; >+ public static final int WAIT_RESPONCE_TIMEOUT = 10000; > > public static final boolean TPTP_AC = true; > >Index: src/org/eclipse/tptp/platform/execution/util/internal/AgentControllerPool.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/util/internal/AgentControllerPool.java,v >retrieving revision 1.1 >diff -u -r1.1 AgentControllerPool.java >--- src/org/eclipse/tptp/platform/execution/util/internal/AgentControllerPool.java 28 Jun 2007 17:18:04 -0000 1.1 >+++ src/org/eclipse/tptp/platform/execution/util/internal/AgentControllerPool.java 9 Jul 2007 14:37:56 -0000 >@@ -18,7 +18,10 @@ > import org.eclipse.tptp.platform.execution.client.core.INode; > import org.eclipse.tptp.platform.execution.client.core.NodeFactory; > import org.eclipse.tptp.platform.execution.exceptions.AgentControllerUnavailableException; >+import org.eclipse.tptp.platform.execution.exceptions.LoginFailedException; > import org.eclipse.tptp.platform.execution.exceptions.NotConnectedException; >+import org.eclipse.tptp.platform.execution.exceptions.SecureConnectionRequiredException; >+import org.eclipse.tptp.platform.execution.security.User; > > /** > * This delegate is used to keep track of connections with Agent Controller. >@@ -28,7 +31,7 @@ > * > * @author Ali Mehregani > */ >-public class AgentControllerPool { >+public class AgentControllerPool { // may be inherited to provide UI > /** > * The incremental wait times > */ >@@ -40,7 +43,7 @@ > public static final int TOTAL_WAIT = 100; > > /* The instance of this class */ >- private static AgentControllerPool instance = new AgentControllerPool(); >+ protected static AgentControllerPool instance; > > /* > * Keeps track of the connections to Agent Controller KEY = hostname VALUE = >@@ -60,15 +63,16 @@ > /** > * Hide the construtor > */ >- private AgentControllerPool() { >+ protected AgentControllerPool() { > } > > /** >- * Return the instance of this singleton class >+ * Return the instance of this singleton class > * > * @return The instance of this class > */ > public static AgentControllerPool getInstance() { >+ if (instance == null) instance = new AgentControllerPool(); > return instance; > } > >@@ -93,8 +97,8 @@ > */ > public IAgentController getConnection(String hostName, int portNumber, > boolean reuseExistingConnection) throws Exception { >+ > String hostKeyName = AgentStatePool.getUnifiedHostName(hostName); >- > /* Attempt to lookup the connection */ > IAgentController ac = (IAgentController) connectionPool.get(hostKeyName); > >@@ -155,34 +159,35 @@ > class EstablishConnection implements Runnable { > private Exception e; > private IAgentController ac; >+ private User user; > > public void run() { > try { >- ac = node.connect(connInfo); >+ if (user == null) >+ ac = node.connect(connInfo); >+ else >+ ac = node.connect(connInfo, user); > > /* Notify that the connection is done */ >- synchronized (AgentControllerPool.this) { >- AgentControllerPool.this.notify(); >- } >+ } catch (LoginFailedException e) { >+ } catch (SecureConnectionRequiredException e) { > } catch (Exception e) { > /* > * For some reason Sun JDK 1.5_06 has problems resolving the > * hostname "localhost". As a workaround change it to > * 127.0.0.1 > */ >+ >+ this.e = e; >+ > if ("localhost".equals(connInfo.getHostName())) { > connInfo.setHostName("127.0.0.1"); >+ >+ try { >+ ac = node.connect(connInfo); >+ this.e = null; >+ } catch (Exception ex) {} > } >- try { >- ac = node.connect(connInfo); >- >- /* Notify that the connection is done */ >- synchronized (AgentControllerPool.this) { >- AgentControllerPool.this.notify(); >- } >- } catch (Exception ex) { >- } >- this.e = e; > } > } > >@@ -193,42 +198,64 @@ > public IAgentController getConnection() { > return ac; > } >+ >+ public void setUser(User user) { >+ this.user = user; >+ } > } >- ; > > EstablishConnection establishConnection = new EstablishConnection(); >- int totalWait = 0; >- new Thread(establishConnection).start(); >- >- /* Wait for a maximum of 10 seconds before bailing out */ >- while (establishConnection.getConnection() == null >- && totalWait < TOTAL_WAIT >- && establishConnection.getException() == null) { >- totalWait++; >- synchronized (this) { >- try { >- wait(INCREMENTAL_WAIT); >- } catch (InterruptedException e) { >- /* Bail out */ >- break; >+ boolean connected = false; >+ String userName = null; >+ boolean lookingForUser = true; >+ int retry = 0; >+ >+ do { >+ Thread ect = new Thread(establishConnection); >+ ect.start(); >+ /* Wait for a maximum of 10 seconds before bailing out */ >+ ect.join(TOTAL_WAIT*INCREMENTAL_WAIT); >+ if (ect.isAlive()) ect.interrupt(); >+ >+ Exception error = establishConnection.getException(); >+ if (error != null) throw error; >+ >+ ac = establishConnection.getConnection(); >+ if (ac == null) { >+ throw new AgentControllerUnavailableException(""); >+ } >+ >+ if (ac.isAuthenticated()) break; >+ >+ User user = null; >+ if (lookingForUser) { >+ user = findUser(hostName); >+ lookingForUser = false; >+ if (user != null) { >+ userName = user.getName(); >+ establishConnection.setUser(user); >+ continue; // try it > } > } >+ >+ user = promptAuthentication(hostName, userName); >+ if(user == null) break; >+ >+ userName = user.getName(); >+ establishConnection.setUser(user); >+ } while (retry++ < 3); >+ >+ if (!ac.isAuthenticated()) { >+ try { ac.disconnect(); } catch (Exception e) {} >+ throw new LoginFailedException("Authentication failed"); > } >- >- /* If any errors occurred, then return it */ >- Exception error = establishConnection.getException(); >- if (error != null) >- throw error; >- ac = establishConnection.getConnection(); >- if (ac == null) >- throw new AgentControllerUnavailableException(); >- >+ > /* Store and return the connection */ > connectionPool.put(hostKeyName, ac); > setPortMapping(hostKeyName, portNumber, ac.getConnectionInfo().getPort()); > return ac; > } >- >+ > private int getPortMapping(String host, int port) { > String key = host + ":" + port; > if (portMappings.containsKey(key)) { >@@ -242,4 +269,13 @@ > String key = host + ":" + port; > portMappings.put(key, new Integer(newPort)); > } >+ >+ // to prevent multiple User registration, to be substituted by descendants >+ public User findUser(String hostName) { >+ return null; >+ } >+ >+ public User promptAuthentication(String hostName, String userName) { >+ return null; >+ } > } >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/SecureConnectionImpl.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/internal/SecureConnectionImpl.java,v >retrieving revision 1.2 >diff -u -r1.2 SecureConnectionImpl.java >--- src/org/eclipse/tptp/platform/execution/client/core/internal/SecureConnectionImpl.java 30 Aug 2006 17:38:58 -0000 1.2 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/SecureConnectionImpl.java 9 Jul 2007 14:37:56 -0000 >@@ -1,145 +1,94 @@ >-/******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation, Intel Corporation. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - Initial API and implementation >- * Vishnu K Naikawadi, Intel - Initial API and implementation >- * >- * $Id$ >- *******************************************************************************/ >- > package org.eclipse.tptp.platform.execution.client.core.internal; > >- > import java.io.IOException; >-import java.net.ConnectException; >-import java.net.InetAddress; >-import java.security.KeyManagementException; >-import java.security.NoSuchAlgorithmException; >-import java.security.Security; >- >-import javax.net.ssl.HandshakeCompletedEvent; >-import javax.net.ssl.HandshakeCompletedListener; >-import javax.net.ssl.SSLSession; >-import javax.net.ssl.SSLSocket; >-import javax.net.ssl.SSLSocketFactory; >- >-import org.eclipse.tptp.platform.execution.client.core.*; >-import org.eclipse.tptp.platform.execution.security.*; >-import org.eclipse.tptp.platform.execution.exceptions.*; >-import org.eclipse.tptp.platform.execution.util.internal.*; >- >+import java.net.Socket; > > import javax.net.ssl.SSLContext; >+import javax.net.ssl.SSLSocket; >+import javax.net.ssl.TrustManager; >+ >+import org.eclipse.tptp.platform.execution.client.core.INode; >+import org.eclipse.tptp.platform.execution.exceptions.LoginFailedException; >+import org.eclipse.tptp.platform.execution.exceptions.ReconnectRequestedException; >+import org.eclipse.tptp.platform.execution.exceptions.SecureConnectionRequiredException; >+import org.eclipse.tptp.platform.execution.exceptions.UntrustedAgentControllerException; > > public class SecureConnectionImpl extends ConnectionImpl { >- >- private boolean handshakeSuccess; >+ private SSLSocket initSSL (Socket socket) throws IOException { >+ if (socket == null || !socket.isConnected()) return null; >+ >+ TrustManager tms[] = null; >+ try { >+ X509TrustManagerImpl tm = new X509TrustManagerImpl(); >+ tms = new TrustManager[1]; >+ tms[0] = tm; >+ } catch (Exception e) {} >+ >+ SSLContext sslCtx; >+ try { >+ sslCtx = SSLContext.getInstance("SSL"); >+ sslCtx.init(null, tms, null); >+ } >+ catch(Exception e) { >+ sslCtx = null; >+ } >+ >+ if (sslCtx == null) return null; >+ >+ String host = socket.getInetAddress().getHostAddress(); >+ int port = socket.getPort(); >+ >+ SSLSocket sslSocket = (SSLSocket) sslCtx.getSocketFactory().createSocket(socket, host, port, true); >+ sslSocket.setUseClientMode(true); > >- public SecureConnectionImpl() { >- super(); >- } >+ sslSocket.startHandshake(); > >- public void connect(INode node, SecureConnectionInfo connInfo) throws IOException, SecureConnectionRequiredException, LoginFailedException, UntrustedAgentControllerException, ReconnectRequestedException { >- _port = connInfo.getPort(); >- int offset = 0; >- InetAddress[] addrs = node.getAllInetAddresses(); >- int protocolOffset = 0; >- ISecureClientParameters ClientSecureParams = connInfo.getSecureClientParameters(); >- >- /* Determine our acceptable protocols */ >- String[] sslProtocols = ClientSecureParams.getEnabledProtocols(); >- if(sslProtocols==null) { >- sslProtocols=new String[] {"SSL"}; >- } >+ if (sslSocket.getSession() == null) return null; > >- do { >- /* Connect to the remote machine */ >- try { >- /* Attach using SSL and initiate a handshake */ >- SSLContext sslContext = SSLContext.getInstance(sslProtocols[protocolOffset]/*,node.getSecurityParameters().getSecurityProvider()*/); >- //Commented the line below to support security for the RAC since it is not part of the new API >- //sslContext.init(ClientSecureParams.getKeystoreManager().getKeyManagers(), node.getAgentController(_port).getSecurityParameters().getKeystoreManager().getTrustManagers(), null); >- >- if (sslContext == null) { >- Security.addProvider(ClientSecureParams.getSecurityProvider()); >- >- _socket = SSLSocketFactory.getDefault().createSocket(addrs[offset], _port); >- ((SSLSocket) _socket).addHandshakeCompletedListener(new HandshakeCompletedListener() { >- public void handshakeCompleted(HandshakeCompletedEvent e) { >- } >- }); >- >- ((SSLSocket) _socket).startHandshake(); >- } >- else { >- _socket = sslContext.getSocketFactory().createSocket(addrs[offset], _port); >- ((SSLSocket) _socket).addHandshakeCompletedListener(new HandshakeCompletedListener() { >- public void handshakeCompleted(HandshakeCompletedEvent e) { >- } >- }); >- } >- >- String[] cyphers=ClientSecureParams.getEnabledCipherSuites(); >- if(cyphers!=null) { >- ((SSLSocket) _socket).setEnabledCipherSuites(ClientSecureParams.getEnabledCipherSuites()); >- } >- else { >- ((SSLSocket) _socket).setEnabledCipherSuites(((SSLSocket)_socket).getSupportedCipherSuites()); >- } >- ((SSLSocket) _socket).setUseClientMode(true); >- >- //((SSLSocket) _socket).startHandshake(); >- >- /* The underlying JSSE code returns the SSL socket before all >- * the SSL handshakes, including client authentication, are >- * completed. The handshake carries on, asynchronously, in >- * the background. If the handshake fails then the socket is >- * not usable. We synchronize things by calling getSession() >- * on the SSL socket. The thread calling getSession() is >- * forced to wait until the underlying SSL handshake is completed, >- * and if the handshake fails then getSession() returns a null. >- */ >- SSLSession session = ((SSLSocket) _socket).getSession(); >- >- /* If we could not establish a session we should throw an exception */ >- if (session==null) { >- throw new UntrustedAgentControllerException(Constants.TPTP_PLATFORM_EXEC_MSG39); >- } >- if(session.getCipherSuite().equals("SSL_NULL_WITH_NULL_NULL")) { >- throw new UntrustedAgentControllerException(Constants.TPTP_PLATFORM_EXEC_MSG39); >- } >- break; >- } >- catch (ConnectException e) { >- offset++; >- if (offset == addrs.length) { >- throw e; >- } >- /* Reset protocol offset */ >- protocolOffset = 0; >- } >- catch (NoSuchAlgorithmException e) { >- /* Try another protocol if there are any left */ >- protocolOffset++; >- if (protocolOffset == sslProtocols.length) { >- throw new ConnectException(Constants.TPTP_PLATFORM_EXEC_MSG40); >- } >- } >- //Commented the exception block below to allow for security - not implemented in the AC >-// catch (KeyManagementException e) { >-// /* We need to handle this */ >-// } >- } >- while (offset < addrs.length); >- >- sendConnectCommand(); >- _node = node; >- this.init(); >+ return sslSocket; > } >+ >+ public boolean connect(INode node, ConnectionImpl con) throws IOException, UntrustedAgentControllerException, >+ ReconnectRequestedException, SecureConnectionRequiredException, LoginFailedException { >+ >+ if (con == null) return false; >+ Socket socket = con.getSocket(); >+ if (socket == null || !socket.isConnected()) return false; >+ >+ con.setSocket(null); // to save socket from garbage collecting >+ >+ setSoTimeout(socket.getSoTimeout()); >+ _node = node; >+ _port = socket.getPort(); >+ inetAddress = socket.getInetAddress(); >+ >+ SSLSocket sslSocket = initSSL(socket); >+ if (sslSocket == null) return false; >+ >+ setSocket (sslSocket); > >+ init(); // to complete connection establishment >+ >+ return true; >+ } >+ >+ public int createDataConnection(int direction) throws IOException, SecureConnectionRequiredException { >+ Socket dataSock = connectSocket(); >+ if (dataSock == null) throw new IOException(); >+ >+ int dataConnectionId = -1; >+ boolean securityRequired = false; >+ >+ try { >+ dataConnectionId = initDataConnection(dataSock, direction); >+ } catch (SecureConnectionRequiredException e) { >+ securityRequired = true; >+ } >+ >+ if (!securityRequired) return dataConnectionId; >+ >+ SSLSocket sslDataSock = initSSL(dataSock); >+ >+ return initDataConnection(sslDataSock, direction); >+ } > } >\ No newline at end of file >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/NodeImpl.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/internal/NodeImpl.java,v >retrieving revision 1.6 >diff -u -r1.6 NodeImpl.java >--- src/org/eclipse/tptp/platform/execution/client/core/internal/NodeImpl.java 25 Apr 2007 15:33:58 -0000 1.6 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/NodeImpl.java 9 Jul 2007 14:37:56 -0000 >@@ -14,28 +14,20 @@ > > package org.eclipse.tptp.platform.execution.client.core.internal; > >-import java.io.IOException; > import java.net.InetAddress; > import java.net.UnknownHostException; >-import java.util.Enumeration; > import java.util.Hashtable; > import java.util.Vector; > > import org.eclipse.core.runtime.Platform; > import org.eclipse.tptp.platform.execution.client.core.*; >-import org.eclipse.tptp.platform.execution.util.*; > import org.eclipse.tptp.platform.execution.util.internal.*; > import org.eclipse.tptp.platform.execution.security.*; > import org.eclipse.tptp.platform.execution.exceptions.*; > import org.eclipse.tptp.platform.iac.administrator.internal.startstop.AutoStartStop; > import org.osgi.framework.Bundle; > >- >- > public class NodeImpl implements INode { >- >- private static final int DEFAULT_LIST_PROCESS_TIMEOUT = 7000; >- > protected String _name; > protected InetAddress[] _addr; > protected Vector _listeners=new Vector(10); >@@ -53,10 +45,7 @@ > try { > _addr=InetAddress.getAllByName(addr.getHostName()); > } >- catch(Exception e) { >- >- } >- >+ catch(Exception e) {} > } > > public NodeImpl(String name, InetAddress[] addr) { >@@ -95,11 +84,7 @@ > * @see Node#isConnected() > */ > public boolean isConnected() { >- if(_ac!=null) { >- //return _ac.isActive(); >- return true; >- } >- return false; >+ return _ac != null; > } > > /** >@@ -120,72 +105,55 @@ > > IConnection _connection = null; > int tryCount = 0; >- int ret = -1; >- if(_ac==null) >- { >- do >- { >- try >- { >- _connection=new ConnectionImpl(); >- _connection.connect(this, connInfo); >+ if(_ac == null) { >+ do { >+ try { >+ _connection = ConnectionFactory.createConnection(this, connInfo); > if (tryCount == Constants.CONNECT_TIMEOUT_TRY_COUNT) > { > throw new TimeoutException(Constants.TPTP_PLATFORM_EXEC_MSG21); > } > tryCount++; > } >+ catch (LoginFailedException e) { >+ throw e; >+ } > catch (ReconnectRequestedException e) { > connInfo.setPort(e.getReconnectPort()); > tryCount = 0; > _connection=null; > } > catch(Exception e) { >- _connection=null; >+ _connection = null; > if (Constants.TPTP_DEBUG) System.out.println("The NodeIml connect exception - " + e); > throw new AgentControllerUnavailableException(Constants.TPTP_PLATFORM_EXEC_MSG22 + e.getMessage()); > } > } > while(_connection == null); > } >- if(_connection != null) >- { >+ >+ if(_connection != null) { > _ac = new AgentController(this, connInfo); > ((AgentController)_ac).setConnection(_connection); >- return _ac; >- } >+ } > > return _ac; > } > >- public synchronized IAgentController connect(ConnectionInfo connInfo, User user) throws AgentControllerUnavailableException, SecureConnectionRequiredException, UntrustedAgentControllerException, LoginFailedException >- { >- boolean userAuthenticated = false; >- connect(connInfo); >+ public synchronized IAgentController connect(ConnectionInfo connInfo, User user) throws AgentControllerUnavailableException, SecureConnectionRequiredException, UntrustedAgentControllerException, LoginFailedException { >+ if (!isConnected()) connect(connInfo); >+ if (_ac == null) return null; > >- try >- { >- if (_ac != null) >- { >- userAuthenticated = _ac.authenticateUser(user); >- } >- >- if (userAuthenticated) >- { >- return _ac; >- } >- } >- catch(Exception e) >- { >- >- throw new AgentControllerUnavailableException(Constants.TPTP_PLATFORM_EXEC_MSG22); >+ try { >+ _ac.authenticateUser(user); >+ } catch (Exception e) { >+ throw new AgentControllerUnavailableException(); > } >- >- return null; >+ >+ return _ac; > } > >- public IAgentController getAgentController(int port) >- { >+ public IAgentController getAgentController(int port) { > return _ac; > } > >@@ -204,5 +172,11 @@ > > return isLocal; > } >+ >+ public void disconnect() { >+ if (_ac != null) { >+ _ac.disconnect(); >+ _ac = null; >+ } >+ } > } >- >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/AgentController.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/internal/AgentController.java,v >retrieving revision 1.29 >diff -u -r1.29 AgentController.java >--- src/org/eclipse/tptp/platform/execution/client/core/internal/AgentController.java 28 Jun 2007 17:18:04 -0000 1.29 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/AgentController.java 9 Jul 2007 14:37:56 -0000 >@@ -122,71 +122,23 @@ > return _connection.getNextContextId(); > } > >- public void disconnect() >- { >- _connection.disconnect(); >+ public void disconnect() { >+ if (_connection != null) { >+ _connection.disconnect(); >+ _connection = null; >+ } >+ >+ isConnected = false; > } > > /* > * Authenticate the User Credentials with AC > * > */ >- public boolean authenticateUser(User user) throws NotConnectedException >- { >- boolean userAuthenticated = false; >- final Object _launcherLock = new Object(); >- final Object _eclipseLock = new Object(); >- boolean _requireEclipseLock = false; >- if(!isConnected)throw new NotConnectedException(Constants.TPTP_PLATFORM_EXEC_MSG6); >- IAgent[] retagent = null; >- final GenericCommandHandler genCmdHandler = new GenericCommandHandler(); >+ public boolean authenticateUser(User user) throws NotConnectedException { >+ if(!isConnected) throw new NotConnectedException(Constants.TPTP_PLATFORM_EXEC_MSG6); > >- synchronized(_launcherLock) >- { >- _requireEclipseLock=false; >- StringBuffer AuthenticateUserCommand = new StringBuffer(""); >- try >- { >- AuthenticateUserCommand.append("<authenticateUser iid=\"org.eclipse.tptp.agentManager\"><userName>"); >- AuthenticateUserCommand.append(user.getName()); >- AuthenticateUserCommand.append("</userName><password>"); >- AuthenticateUserCommand.append(user.getPassword()); >- AuthenticateUserCommand.append("</password></authenticateUser>"); >- this.sendCommand(AuthenticateUserCommand.toString(), Constants.AC_DEST_ID, new ICommandHandler() >- { >- public void incomingCommand(INode node, ICommandElement command) >- { >- genCmdHandler.setCommandElement(command); >- } >- }); >- _requireEclipseLock=true; >- _launcherLock.wait(Constants.TIMEOUT_PERIOD); >- } >- catch(InterruptedException e) >- { >- e.printStackTrace(); >- } >- catch(Exception e) >- { >- e.printStackTrace(); >- } >- } >- if (genCmdHandler.getCommandElement() != null) >- { >- String commandStr = ((CommandFragment)genCmdHandler.getCommandElement()).getCommandData(); >- TPTPXMLParse ParseObj = new TPTPXMLParse(); >- ParseObj.setParser(commandStr); >- Hashtable CommandHash = ParseObj.getHashTable(); >- if (CommandHash.containsKey("userAuthenticated")) >- { >- userAuthenticated = true; >- } >- else if (CommandHash.containsKey("authenticationFailed")) >- { >- userAuthenticated = false; >- } >- } >- return userAuthenticated; >+ return ((ConnectionImpl)_connection).authenticateUser(user); > } > > /* (non-Javadoc) >@@ -1340,32 +1292,31 @@ > /* (non-Javadoc) > * @see org.eclipse.tptp.platform.execution.core.IAgentController#sendCommand(java.lang.String, int, org.eclipse.tptp.platform.execution.core.ICommandHandler) > */ >- public void sendCommand(String cmd, int destID, ICommandHandler handler) throws IOException >- { >- try >- { >- ControlMessage message = new ControlMessage(); >- message.setMessageType(Constants.TPTP_AC_MESSAGE); >- message.setMagicNumber(Constants.AC_MAGIC_NUMBER); >- message.setFlags(0); >- CommandFragment cmdFrag = new CommandFragment(); >- cmdFrag.setDestination(destID); >- cmdFrag.setSource(this._sourceID); >- cmdFrag.setContext(_connection.getNextContextId()); >- cmdFrag.setCommand(cmd); >- cmdFrag.buildCommand();//Build the command in ConnectionImpl::sendMessage as we don't know the context at this place >- message.appendCommand(cmdFrag); >+ public void sendCommand(String cmd, int destID, ICommandHandler handler) throws IOException { >+ try { >+ ControlMessage message = new ControlMessage(); >+ message.setMessageType(Constants.TPTP_AC_MESSAGE); >+ message.setMagicNumber(Constants.AC_MAGIC_NUMBER); >+ message.setFlags(0); >+ >+ CommandFragment cmdFrag = new CommandFragment(); >+ cmdFrag.setDestination(destID); >+ cmdFrag.setSource(this._sourceID); >+ cmdFrag.setContext(_connection.getNextContextId()); >+ cmdFrag.setCommand(cmd); >+ cmdFrag.buildCommand();//Build the command in ConnectionImpl::sendMessage as we don't know the context at this place >+ message.appendCommand(cmdFrag); > >- if (handler == null) >- { >+ if (handler == null) { > //this.getConnection().sendMessage(message, this.acCommandHandler); >- } >- else >- { >- this.getConnection().sendMessage(message, handler); >- } >- }catch(Exception e){e.printStackTrace();} >+ } >+ else { >+ getConnection().sendMessage(message, handler); >+ } >+ >+ } catch(Exception e){e.printStackTrace();} > } >+ > /** > * Sends a command to the specified destination, the command requires a control message object > * and a commandhandler >@@ -1599,6 +1550,8 @@ > this.value = value; > } > } >+ >+ public boolean isAuthenticated() { >+ return _connection != null && ((ConnectionImpl)_connection).isAuthenticated(); >+ } > } >- >- >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionImpl.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionImpl.java,v >retrieving revision 1.20 >diff -u -r1.20 ConnectionImpl.java >--- src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionImpl.java 28 Jun 2007 17:18:04 -0000 1.20 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionImpl.java 9 Jul 2007 14:37:56 -0000 >@@ -28,6 +28,8 @@ > import java.util.Hashtable; > > import org.eclipse.tptp.platform.execution.client.core.*; >+import org.eclipse.tptp.platform.execution.client.core.internal.commands.AuthenticateCommand; >+import org.eclipse.tptp.platform.execution.security.User; > import org.eclipse.tptp.platform.execution.util.*; > import org.eclipse.tptp.platform.execution.util.internal.CommandFragment; > import org.eclipse.tptp.platform.execution.util.internal.Constants; >@@ -37,10 +39,10 @@ > import org.eclipse.tptp.platform.execution.exceptions.*; > > public class ConnectionImpl implements IConnection { >- > protected Socket _socket; > protected INode _node; > protected int _port; >+ protected InetAddress inetAddress = null; > > private int _connectionId = 0; > >@@ -51,204 +53,243 @@ > private boolean _isComplete = false; > > private final Vector _listeners = new Vector(); >- private final Object _connectionLock = new Object(); >- private final Object _loginLock = new Object(); > >+ private static final Object writeLock = new Object(); >+ private static final Object writeDataLock = new Object(); > private static final Object contextLock = new Object(); >+ private static final Object authLock = new Object(); > private boolean _isInitialized = false; >- private boolean _loginPending = false; >- private ReconnectRequestedException _reconnectRequestedException=null; >- private SecureConnectionRequiredException _secureConnectionRequiredException=null; >- private LoginFailedException _loginFailed=null; >+ private boolean isAuthenticated = false; > > private int _soTimeout = Constants.TIMEOUT_PERIOD; > >- class DataConnection >- { >+ class DataConnection { // it is better to move all processing of data connections to AC or Node > private Socket _dataSocket; > private ACTCPDataServer _dataServer; >+ private int dataConnectionId; > >- public void setDataSocket(Socket dataSocket){_dataSocket = dataSocket;} >- public void setDataServer(ACTCPDataServer dataServer){_dataServer = dataServer;} >- public Socket getDataSocket(){return _dataSocket;} >- public ACTCPDataServer getDataServer(){return _dataServer;} >+ public void setDataSocket(Socket dataSocket) { _dataSocket = dataSocket; } >+ public void setDataServer(ACTCPDataServer dataServer) { _dataServer = dataServer; } >+ public Socket getDataSocket() { return _dataSocket; } >+ public ACTCPDataServer getDataServer() { return _dataServer; } >+ public int getDataConnectionId() { return dataConnectionId; } >+ public void setDataconnectionId(int dataConnectionId) { this.dataConnectionId = dataConnectionId; } > } > > public ConnectionImpl() { >- super(); > } >- >- public int getConnectionId() >- { >- return this._connectionId; >+ >+ public int getConnectionId() { >+ return _connectionId; > } > >- public boolean isNewAC() >- { >+ public boolean isNewAC() { > return true; > } > >- public long getNextContextId() >- { >+ public long getNextContextId() { > synchronized(contextLock){ > return _context++; > } >- > } > >- public void addContext(long contextID, ICommandHandler handler) >- { >+ public void addContext(long contextID, ICommandHandler handler) { > synchronized(contextLock){ > this._contextMapper.addContext(contextID, handler); > } > } > >- public void connect(INode node, ConnectionInfo connInfo) throws IOException, SecureConnectionRequiredException, LoginFailedException, UntrustedAgentControllerException, ReconnectRequestedException >- { >- _port=connInfo.getPort(); >+ protected Socket connectSocket () throws IOException { >+ if (_node == null) return null; >+ return connectSocket(_node.getAllInetAddresses(), _port); >+ } >+ >+ protected Socket connectSocket (InetAddress addrs[], int port) throws IOException { >+ if (addrs == null || addrs.length <= 0) return null; >+ >+ Socket socket = null; >+ >+ for (int i=0; i<addrs.length; i++) { >+ if(Constants.TPTP_DEBUG) System.out.println("Connecting to " + addrs[i] + " at port " + _port); >+ socket = new Socket(addrs[i], port); >+ socket.setSoTimeout(_soTimeout); >+ socket.setTcpNoDelay(true); >+ inetAddress = addrs[i]; >+ break; >+ } >+ >+ return socket; >+ } >+ >+ public void connect(INode node, ConnectionInfo connInfo) throws IOException, SecureConnectionRequiredException, >+ LoginFailedException, UntrustedAgentControllerException, ReconnectRequestedException { >+ > _soTimeout = connInfo.getSoTimeout(); >- int offset=0; >- InetAddress[] addrs=node.getAllInetAddresses(); >+ if (_soTimeout > 0) _soTimeout *= Constants.CONNECT_TIMEOUT_TRY_COUNT; >+ >+ _node = node; >+ _port = connInfo.getPort(); > >- do { >- /* Connect to the remote machine */ >- try { >- if(Constants.TPTP_DEBUG)System.out.println("Connecting to " + addrs[offset] + " at port " + _port); >- _socket=new Socket(addrs[offset], _port); >- >- sendConnectCommand(); >- break; >- } >- catch(IOException e) { >- offset++; >- if (Constants.TPTP_DEBUG)System.out.println(e.getMessage()); >- if(offset==addrs.length) { >- if (Constants.TPTP_DEBUG)System.out.println("Error while connecting to the Agent Controller on " + addrs[offset] + " running at port " + _port); >- throw e; >- } >- } >- }while(offset<addrs.length); >- _node=node; >+ _socket = connectSocket(node.getAllInetAddresses(), _port); >+ if (_socket == null) throw new IOException(); > >- this.init(); >+ init(); > > // We expected to have a connectionID by now. If we don't, it's because the wait above timed out >- if ( _connectionId == 0 ) { >+ if (_connectionId == 0) { > throw new LoginFailedException("Timeout while waiting for connection to complete"); > } > } >- public void connect(INode node, int port) throws IOException, SecureConnectionRequiredException, LoginFailedException, UntrustedAgentControllerException, ReconnectRequestedException >- { >+ >+ public void connect(INode node, int port) throws IOException, SecureConnectionRequiredException, LoginFailedException, UntrustedAgentControllerException, ReconnectRequestedException { > ConnectionInfo connInfo = new ConnectionInfo(); > connInfo.setPort(port); >- connect( node, connInfo ); >- } >- >- protected void sendConnectCommand() throws IOException >- { >- if(Constants.TPTP_DEBUG)System.out.println("The AC is New"); >- sendControlCommand(Constants.CONNECT); >+ connect(node, connInfo); > } > >- >- /* Init */ >- protected void init() throws SecureConnectionRequiredException, LoginFailedException, IOException, ReconnectRequestedException >- { >- try >- { >- _socket.setSoTimeout(_soTimeout); >- _socket.setTcpNoDelay(true); >- } >- catch(SocketException e) { >- /* We can ignore this */ >- } >- >- _contextMapper=new ContextMapper(); >+ protected void init() throws SecureConnectionRequiredException, LoginFailedException, IOException, ReconnectRequestedException { >+ _contextMapper = new ContextMapper(); > _dataConnectionMap = new Hashtable(); >- _cmdHandler=new ICommandHandler() >- { >- public void incomingCommand(INode node, ICommandElement command) >- { >+ >+ _cmdHandler = new ICommandHandler() { >+ public void incomingCommand(INode node, ICommandElement command) { > handleACCommands(command); > } > }; > >- /* RKD: With the V5 RAC it first accepts the socket connection and then determines is the connection >- * is allowed. If the connection is not allowed the the connection is cut. We need to first connect >- * and then determine if we have been cut off. The connection has already occurred above us in the >- * stack. We then will wait until either a read timeout has occured on the reader thread or the >- * connection gets cut by the other side. >- */ >- >- synchronized(_connectionLock) { >- SocketReaderThread reader=new SocketReaderThread(); >- reader.setName(_node.getName()+"_connection"); >- reader.setDaemon(true); >- reader.start(); >- try >- { >- _connectionLock.wait(); >- } >- catch(InterruptedException e){e.printStackTrace();} >- >- _isInitialized=true; >- >- if (_reconnectRequestedException!=null) { >- ReconnectRequestedException temp=_reconnectRequestedException; >- _reconnectRequestedException = null; >- throw temp; >- } >+ sendControlCommand(Constants.CONNECT); >+ >+ byte rbuf[] = new byte[512]; >+ BufferedInputStream inStream = new BufferedInputStream(_socket.getInputStream()); >+ int offset = 0; >+ >+ while (true) { >+ int bytesRead = inStream.read(rbuf, offset, rbuf.length-offset); >+ >+ if(bytesRead < 0) break; >+ >+ if (offset > 0) { >+ bytesRead += offset; >+ offset = 0; >+ } > >- /* If this connection has a pending exception because the server is secure we need to throw the >- * exception so that the caller can create a new connection with the proper security settings. >- */ >- if(_secureConnectionRequiredException!=null) { >- SecureConnectionRequiredException temp=_secureConnectionRequiredException; >- _secureConnectionRequiredException=null; >- _loginPending=false; >- throw temp; >+ // If we've tried to connect to a backward compatibility >+ // layer of the AC, we'll immediately get a response in >+ // RAC format. If we ignore this, the BC layer will >+ // respond to our first message by giving us the port >+ // to connect to the regular socket TL. >+ // >+ int v = checkForRACMessage(rbuf, offset); >+ if(v >= 0) { >+ // We read the header, the next four bytes will be the length >+ // (including the header) of the RAC message >+ int len = (int) TPTPMessageUtil.readTPTPLongFromBuffer(rbuf, v); >+ if (len == bytesRead) { >+ offset = 0; >+ continue; >+ } >+ >+ if (len > bytesRead) { >+ inStream.skip(len - bytesRead); >+ offset = 0; >+ continue; >+ } >+ >+ offset = len; >+ } >+ >+ // First we make sure we have at least enough read for the message header. >+ // If not, compress and re-read. >+ // >+ if (bytesRead-offset < Constants.AC_MESSAGE_HEADER_SIZE) { >+ System.arraycopy(rbuf, offset, rbuf, 0, bytesRead-offset); >+ offset = bytesRead - offset; >+ continue; > } >+ >+ // We have the header information, now lets try and get the entire message. Once >+ // again the same error conditions can occur. >+ // >+ //System.out.println("Offset xx::"+new String(buffer)); > >- //System.out.println("init - 7"); >- synchronized(_loginLock) { >- if(_loginPending) { >- try { >- _loginLock.wait(); >+ ControlMessage msg=new ControlMessage(); >+ msg.setMessageType(Constants.TPTP_AC_MESSAGE); >+ int current; >+ >+ try { >+ if (rbuf.length == bytesRead + offset) { >+ current = msg.readFromBuffer(rbuf, offset); >+ } >+ else { >+ // length is not passed to readFromBuffer so we should ensure >+ // that readFromBuffer will not read trash from the end of the buffer >+ // and no exception will be thrown. >+ // ControlMessage.readFromBuffer(buffer, offset, length) method >+ // is needed in order to prevent extra memory allocations in this case. >+ byte[] buffer2 = new byte[bytesRead]; >+ System.arraycopy(rbuf, offset, buffer2, 0, bytesRead); >+ current = msg.readFromBuffer(buffer2, 0); >+ } >+ } catch (Exception e) { >+ throw new IOException(); >+ } >+ >+ long flags = msg.getFlags(); >+ if ((flags & Constants.CONNECTION_COMPLETE) != 0) { >+ isAuthenticated = (flags & Constants.AUTHENTICATION_FAILED) == 0; >+ _connectionId = extractConnectionId(rbuf, current); >+ break; >+ } // equals - since CONNECTION_RECONNECT_REQUEST has two bits set >+ else if ((flags & Constants.CONNECTION_REFUSED) != 0) { >+ if ((flags & Constants.SECURITY_REQUIRED) != 0) { >+ throw new SecureConnectionRequiredException(); >+ } >+ else if((flags & Constants.CONNECTION_RECONNECT_REQUEST) == Constants.CONNECTION_RECONNECT_REQUEST) { >+ int portreq = -1; >+ >+ try { >+ close(); >+ CommandFragment cmd = (CommandFragment)msg.getCommand(0); >+ String strToParse = cmd.getCommandData(); >+ TPTPXMLParse ParseObj = new TPTPXMLParse(); >+ ParseObj.setParser(strToParse.trim()); >+ Hashtable CommandHash = ParseObj.getHashTable(); >+ if(CommandHash.containsKey("port")) { >+ portreq = Integer.parseInt((String)ParseObj.getHashTable().get("port")); >+ } > } >- catch(InterruptedException e) { >- /* We should ignore this */ >+ catch(Exception e){} >+ >+ if(portreq == -1) { >+ // This is a bad situation. The AC should have given us a port >+ // Since it didn't (unexpectedly), let's try a default >+ portreq = 10006; > } >+ >+ // Tell the caller how to reconnect >+ throw new ReconnectRequestedException(portreq); > } >+ >+ throw new IOException("Connection Refused"); > } >- >- if(_loginFailed!=null) { >- LoginFailedException temp=_loginFailed; >- _loginFailed=null; >- _loginPending=false; >- throw temp; >- } >- if(_isComplete) { >- throw new IOException(); >- } >+ >+ throw new IOException("Unknown command"); > } >+ >+ (new SocketReaderThread()).start(); > } >- >- private void handleACCommands(ICommandElement command) >- { >+ >+ private void handleACCommands(ICommandElement command) { > long contextId=command.getContext(); > if(Constants.TPTP_DEBUG)System.out.println("The context of the returned command:" + contextId); > > //Find the command handler associated with this contextId and > // forward the message appropriately. > ICommandHandler ch=_contextMapper.getHandler(contextId); >- if(ch != null) >- { >+ if(ch != null) { > if(Constants.TPTP_DEBUG)System.out.println("Forwarding to command handler"); > ch.incomingCommand(_node, command); > } >- else { >- if(Constants.TPTP_DEBUG)System.out.println("Could not find command handler"); >- } > } > > private int extractConnectionId(byte[] buffer, int offset) >@@ -273,8 +314,7 @@ > * nonzero if error > * > *********************************************************/ >- private void sendCONNECT_DATACommand(Socket datasock, int direction) throws IOException >- { >+ private void sendCONNECT_DATACommand(Socket datasock, int direction) throws IOException { > long flags = 0 ; > > /* build the CONNECT command string */ >@@ -291,7 +331,7 @@ > long dataPathType = direction; > offset = TPTPMessageUtil.writeTPTPLongToBuffer(buffer, offset, dataPathType); > >- OutputStream stream=datasock.getOutputStream(); >+ OutputStream stream = datasock.getOutputStream(); > stream.write(buffer); > stream.flush(); > } >@@ -308,8 +348,7 @@ > * nonzero if error > * > *********************************************************/ >- private void sendControlCommand(long commandFlags) throws IOException >- { >+ private void sendControlCommand(long commandFlags) throws IOException { > long flags = 0 ; > > /* build the CONNECT command string */ >@@ -324,104 +363,82 @@ > sendMessage(connectMessage, _cmdHandler); > } > >+ int createDataConnection(int direction) throws IOException, SecureConnectionRequiredException { >+ Socket datasock = connectSocket(); >+ if (datasock == null) throw new IOException(); > >- int createDataConnection(int direction) throws IOException >- { >- Socket datasock = null; >- int dataConnectionId = -1; >- byte[] buffer=new byte[Constants.MAX_MESSAGE_LENGTH]; >- int masterOffset=0; >+ return initDataConnection(datasock, direction); >+ } >+ >+ protected int initDataConnection(Socket datasock, int direction) throws IOException, SecureConnectionRequiredException { >+ if (datasock == null || !datasock.isConnected()) return -1; > >- int offset=0; >- InetAddress[] addrs=_node.getAllInetAddresses(); >- >- do { >- /* Connect to the remote machine */ >- try { >- datasock=new Socket(addrs[offset], _port); >- datasock.setTcpNoDelay(true); >- datasock.setSoTimeout(_soTimeout); >- break; >- } >- catch(IOException exp) >- { >- offset++; >- //System.out.println(e.getMessage()); >- if(offset==addrs.length) { >- throw exp; >- } >- } >- }while(offset<addrs.length); >- >- /* CONNECT_DATA command */ >+ // CONNECT_DATA command > sendCONNECT_DATACommand(datasock, direction); >- >- /* Get the InputStream for this socket so we can read some data */ >- InputStream inStream=datasock.getInputStream(); >- int bytesRead=inStream.read(buffer, masterOffset, buffer.length-masterOffset); >+ >+ // Get the InputStream for this socket so we can read some data >+ byte[] buffer = new byte[256]; >+ InputStream inStream = datasock.getInputStream(); >+ int d = inStream.read(buffer, 0, buffer.length); > > ControlMessage DataConnectionResponseMessage = new ControlMessage(); > DataConnectionResponseMessage.setMessageType(Constants.TPTP_AC_MESSAGE); >- masterOffset = DataConnectionResponseMessage.readFromBuffer(buffer, masterOffset); >+ int masterOffset = DataConnectionResponseMessage.readFromBuffer(buffer, 0); > long flags = DataConnectionResponseMessage.getFlags(); >- if ((flags & Constants.DATA_CONNECTION_COMPLETE) != 0) >- { >- dataConnectionId = extractConnectionId(buffer, masterOffset); >- } >+ if ((flags & Constants.CONNECTION_REFUSED) != 0) { >+ if ((flags & Constants.SECURITY_REQUIRED) != 0) { >+ throw new SecureConnectionRequiredException(); >+ } >+ >+ throw new IOException("Connection Refused"); >+ } >+ >+ if ((flags & Constants.DATA_CONNECTION_COMPLETE) <= 0) return -1; >+ >+ int dataConnectionId = extractConnectionId(buffer, masterOffset); >+ if (dataConnectionId <= 0) return -1; > > DataConnection dataConnectionInfo = new DataConnection(); > ACTCPDataServer dataServer = new ACTCPDataServer(); >- if (dataConnectionId > 0) >- { > //dataConnectionId = ::getConnectionId(pMsg) ; >- if(Constants.TPTP_DEBUG)System.out.println("The Data Channel ConnectionID: " + dataConnectionId); >- dataConnectionInfo.setDataSocket(datasock); >- dataConnectionInfo.setDataServer(dataServer); >- _dataConnectionMap.put(new Integer(dataConnectionId), dataConnectionInfo); >- >- try >- { >- dataServer.startServer(null, datasock); >- } >- catch(SocketException sockExp) >- { >- System.out.println("Error starting the TCPDataServer"); >- } >- catch(IOException Exp) >- { >- System.out.println("Error starting the TCPDataServer"); >- } >+ if(Constants.TPTP_DEBUG)System.out.println("The Data Channel ConnectionID: " + dataConnectionId); >+ dataConnectionInfo.setDataSocket(datasock); >+ dataConnectionInfo.setDataServer(dataServer); >+ dataConnectionInfo.setDataconnectionId(dataConnectionId); >+ _dataConnectionMap.put(new Integer(dataConnectionId), dataConnectionInfo); >+ >+ try { >+ dataServer.startServer(null, datasock); >+ } >+ catch(SocketException sockExp) { >+ } >+ catch(IOException Exp) { > } > > return dataConnectionId; > } > >- >- public int addDataListener(int dataConnectionId, IDataProcessor dataProcessor) >- { >- if(dataConnectionId == -1){ return -1;} >+ public int addDataListener(int dataConnectionId, IDataProcessor dataProcessor) { >+ if(dataConnectionId == -1) return -1; >+ > DataConnection dataConnectionInfo = (DataConnection)_dataConnectionMap.get(new Integer(dataConnectionId)); > ACTCPDataServer dataServer = dataConnectionInfo.getDataServer(); >- if(dataServer != null) >- { >+ if(dataServer != null) { > dataServer.addDataprocessor(dataProcessor); > return 0; > } >+ > return -1; > } > >- public int removeDataListener(int dataConnectionId, IDataProcessor dataProcessor) >- { >- try >- { >+ public int removeDataListener(int dataConnectionId, IDataProcessor dataProcessor) { >+ try { > DataConnection dataConnectionInfo = (DataConnection)_dataConnectionMap.get(new Integer(dataConnectionId)); > ACTCPDataServer dataServer = dataConnectionInfo.getDataServer(); > dataServer.removeDataprocessor(dataProcessor); > dataServer.shutdownServer(); >- }catch(Exception e) >- { >- ///e.printStackTrace(); >- } >+ } catch(Exception e) {} >+ > return 0; > } > >@@ -435,14 +452,11 @@ > _dataConnectionMap.remove(new Integer(dataConnID)); > } > >- private void closeDataConnection(int dataConnID) >- { >+ private void closeDataConnection(int dataConnID) { > DataConnection dataConnectionInfo = (DataConnection)_dataConnectionMap.get(new Integer(dataConnID)); > >- try >- { >- if (dataConnectionInfo != null) >- { >+ try { >+ if (dataConnectionInfo != null) { > // Send DISCONNECT command for data channel > sendControlCommand(Constants.DISCONNECT); > >@@ -452,71 +466,58 @@ > dataConnectionInfo.getDataSocket().close(); > } > } >- catch(Exception exp) >- { >+ catch(Exception exp) { > if (Constants.TPTP_DEBUG) System.out.println("Error destroying the data channel - " + exp.getMessage()); > } > } > >- public void sendData(int dataConnectionId, byte[] buffer, int bufferLength) >- { >- try >- { >+ public void sendData(int dataConnectionId, byte[] buffer, int bufferLength) { >+ try { > DataConnection dataConnectionInfo = (DataConnection)_dataConnectionMap.get(new Integer(dataConnectionId)); >- OutputStream stream=dataConnectionInfo._dataSocket.getOutputStream(); >- stream.write(buffer); >- stream.flush(); >- } >- catch(IOException exp) >- { >- System.out.println("Error writing the data to the Socket - " + exp); >- } >- catch(Exception e) >- { >- System.out.println("Error sending the data - " + e); >+ >+ synchronized (writeDataLock) { >+ OutputStream stream=dataConnectionInfo._dataSocket.getOutputStream(); >+ stream.write(buffer); >+ stream.flush(); >+ } >+ } >+ catch(IOException exp) { >+ } >+ catch(Exception e) { > } > } > >- public void sendMessage(IControlMessage msg, ICommandHandler handler) throws IOException >- { >- int commandCount = msg.getCommandCount(); >- >- try >- { >- for (int i=0; i < commandCount; i++) { >- //System.out.println("Adding the handler to the context ..."); >- //System.out.println("Context:" + msg.getCommand(i).getContext()); >- //System.out.println("Handler:" + handler); >- this._contextMapper.addContext(msg.getCommand(i).getContext(), handler); >+ public void sendMessage(IControlMessage msg, ICommandHandler handler) throws IOException { >+ try { >+ if (handler != null) { >+ int commandCount = msg.getCommandCount(); >+ for (int i=0; i < commandCount; i++) { >+ _contextMapper.addContext(msg.getCommand(i).getContext(), handler); >+ } > } > >- int count=msg.getSize(); >- //System.out.println("message size " + count); >- byte[] buffer=new byte[count]; >+ byte[] buffer=new byte[msg.getSize()]; > msg.writeToBuffer(buffer, 0); > >- OutputStream stream=_socket.getOutputStream(); >- stream.write(buffer); >- stream.flush(); >+ synchronized (writeLock) { >+ OutputStream stream=_socket.getOutputStream(); >+ stream.write(buffer); >+ stream.flush(); >+ } > } >- catch(IOException exp) >- { >+ catch(IOException exp) { > if (Constants.TPTP_DEBUG)System.out.println("SendMessage error - " + exp); > throw exp; > } >- catch(Exception exp) >- { >+ catch(Exception exp) { > if (Constants.TPTP_DEBUG)System.out.println("SendMessage error - " + exp); >- //throw exp; > } >- > } > > public void disconnect() { >- synchronized(_connectionLock) { > if(!_isComplete) { > _isComplete=true; >- _connectionLock.notifyAll(); >+ > try > { > // Destroy Data Connections >@@ -533,11 +534,6 @@ > // Send DISCONNECT command > sendControlCommand(Constants.DISCONNECT); > >- // Close the SocketReaderThread >- _isComplete = true; >- >- // Close the Socket >- _socket.close(); > if (Constants.TPTP_DEBUG) System.out.println("Successfully disconnected."); > } > catch(IOException e) { >@@ -545,6 +541,8 @@ > if (Constants.TPTP_DEBUG) System.out.println("Exception while disconnecting ... " + e); > } > >+ close(); >+ > /* If this is a nodeimpl clear the keystore spec so it tries an insecure connect next time */ > //Commented by GN since security not supported yet in the new > // if(_node instanceof INode) { >@@ -562,9 +560,18 @@ > } > */ > } >- } > } > >+ public void close () { >+ if (_socket != null) { >+ try { >+ _socket.close(); >+ } catch (Exception e) {} >+ } >+ >+ _isComplete = true; >+ } >+ > public INode getNode() { > return _node; > } >@@ -575,12 +582,11 @@ > } > return false; > } >- public static int checkForRACMessage(byte[] buffer, int offset) >- { >+ >+ public static int checkForRACMessage(byte[] buffer, int offset) { > Message tempMessage=new Message(); > tempMessage.readFromBuffer(buffer, offset); >- if(tempMessage.getMagicNumber() == Constants.RA_MAGIC) >- { >+ if(tempMessage.getMagicNumber() == Constants.RA_MAGIC) { > return Constants.RAC_MESSAGE_HEADER_SIZE; > } > return -1; >@@ -589,117 +595,84 @@ > public int getPort() { > return _port; > } >+ >+ public InetAddress getInetAddress() { >+ return inetAddress; >+ } >+ > protected ContextMapper getContextMapper() > { > return this._contextMapper; > } > > protected int processControlMessage(byte[] buffer, int offset, int length) { >- if(_cmdHandler != null) { >- ControlMessage msg=new ControlMessage(); >- msg.setMessageType(Constants.TPTP_AC_MESSAGE); >+ if(_cmdHandler == null) return -1; >+ >+ ControlMessage msg=new ControlMessage(); >+ msg.setMessageType(Constants.TPTP_AC_MESSAGE); > >- int current=-1; >- try { >- if(Constants.TPTP_DEBUG)System.out.println("Processing the Message."); >- if (buffer.length == length + offset) { >- current = msg.readFromBuffer(buffer, offset); >- } >- else { >- // length is not passed to readFromBuffer so we should ensure >- // that readFromBuffer will not read trash from the end of the buffer >- // and no exception will be thrown. >- // ControlMessage.readFromBuffer(buffer, offset, length) method >- // is needed in order to prevent extra memory allocations in this case. >- byte[] buffer2 = new byte[length]; >- System.arraycopy(buffer, offset, buffer2, 0, length); >- current = msg.readFromBuffer(buffer2, 0); >- if (current >= 0) >- current += offset; >- } >- /* If we read more bytes then were valid, return -1 */ >- if(current>offset+length) >- { >- return -1; >- } >+ int current=-1; >+ try { >+ if(Constants.TPTP_DEBUG)System.out.println("Processing the Message."); >+ if (buffer.length == length + offset) { >+ current = msg.readFromBuffer(buffer, offset); >+ } >+ else { >+ // length is not passed to readFromBuffer so we should ensure >+ // that readFromBuffer will not read trash from the end of the buffer >+ // and no exception will be thrown. >+ // ControlMessage.readFromBuffer(buffer, offset, length) method >+ // is needed in order to prevent extra memory allocations in this case. >+ byte[] buffer2 = new byte[length]; >+ System.arraycopy(buffer, offset, buffer2, 0, length); >+ current = msg.readFromBuffer(buffer2, 0); >+ if (current >= 0) >+ current += offset; > } >- catch(IndexOutOfBoundsException e) >- { >+ /* If we read more bytes then were valid, return -1 */ >+ if(current>offset+length) { > return -1; > } >- catch(Exception e) >- { >- System.out.println("Exception while processing the message" + e); >- return -1; >- } >+ } >+ catch(IndexOutOfBoundsException e) { >+ return -1; >+ } >+ catch(Exception e) { >+ System.out.println("Exception while processing the message" + e); >+ return -1; >+ } > >- /* If we have parsed the message successfully Then process it */ >- int len = msg.getSize(); >+ /* If we have parsed the message successfully Then process it */ >+ int len = msg.getSize(); > >- if (current == len+offset) { >- /* Valid pass on each command */ >- if(Constants.TPTP_DEBUG)System.out.println("Checking for CONNECTION_COMPLETE response"); >- long flags = msg.getFlags(); >- if ((flags & Constants.CONNECTION_COMPLETE) != 0) >- { >- this._connectionId = extractConnectionId(buffer, current); >- current += msg.getLength(); >- if(Constants.TPTP_DEBUG)System.out.println("Connection complete response - " + _connectionId); >- synchronized (_connectionLock) { >- _connectionLock.notifyAll(); >- } >- } >- if((flags & Constants.CONNECTION_RECONNECT_REQUEST) != 0) >- { >- int portreq = -1; >- synchronized(_socket) >- { >- try >- { >- _isComplete=true; >- _dataConnectionMap.clear(); >- _socket.close(); >- CommandFragment cmd=(CommandFragment)msg.getCommand(0); >- String strToParse = cmd.getCommandData();//new String(buffer,Constants.ACK_HDR_LEN,buffer.length-12); >- TPTPXMLParse ParseObj = new TPTPXMLParse(); >- ParseObj.setParser(strToParse.trim()); >- Hashtable CommandHash = ParseObj.getHashTable(); >- if(CommandHash.containsKey("port")) >- { >- portreq = Integer.parseInt((String)ParseObj.getHashTable().get("port")); >- } >- } >- catch(Exception e){} >- } >- >- if(portreq == -1) { >- // This is a bad situation. The AC should have given us a port >- // Since it didn't (unexpectedly), let's try a default >- portreq = 10006; >- } >- >- // Tell the caller how to reconnect >- _reconnectRequestedException = new ReconnectRequestedException( portreq ); >- synchronized (_connectionLock) { >- // This notify will cause init to throw the above request >- // and cause the read thread to bail >- _connectionLock.notifyAll(); >- } >- } >- int count=msg.getCommandCount(); >+ if (current == len+offset) { >+ /* Valid pass on each command */ >+// if(Constants.TPTP_DEBUG)System.out.println("Checking for CONNECTION_COMPLETE response"); >+ long flags = msg.getFlags(); >+ >+ if ((flags & Constants.AUTHENTICATION_FAILED) != 0) { >+ isAuthenticated = false; >+ synchronized (authLock) { >+ authLock.notifyAll(); >+ } >+ } >+ else if ((flags & Constants.AUTHENTICATION_SUCCESSFUL) != 0) { >+ isAuthenticated = true; >+ synchronized (authLock) { >+ authLock.notifyAll(); >+ } >+ } >+ else { >+ int count=msg.getCommandCount(); >+ for(int i=0; i<count; i++) { >+ _cmdHandler.incomingCommand(_node, msg.getCommand(i)); >+ } >+ } >+ } > >- for(int i=0; i<count; i++) >- { >- _cmdHandler.incomingCommand(_node, msg.getCommand(i)); >- } >- } >- return current; >- } >- return -1; >+ return current; > } > >- >- > /** > * @see Connection#addConnectionListener(ConnectionListener) > */ >@@ -710,7 +683,6 @@ > } > } > } >- > > /** > * @see Connection#removeConnectionListener(ConnectionListener) >@@ -726,19 +698,25 @@ > public void setSoTimeout(int timeout) { > _soTimeout = timeout; > } >+ >+ public Socket getSocket() { >+ return _socket; >+ } >+ >+ public void setSocket(Socket socket) { >+ _socket = socket; >+ _isComplete = true; >+ } > >- class SocketReaderThread extends Thread implements Constants >- { >- public void run() >- { >- /* Run forever */ >- byte[] buffer=new byte[MAX_MESSAGE_LENGTH]; >+ class SocketReaderThread extends Thread implements Constants { >+ public void run() { >+ byte[] buffer = new byte[MAX_MESSAGE_LENGTH]; > int masterOffset=0; > boolean incompleteMsg; >- int timeoutCount=0; >+ > _isComplete = false; > >- /* Get the InputStream for this socket so we can read some data */ >+ // Get the InputStream for this socket so we can read some data > BufferedInputStream inStream; > try { > inStream = new BufferedInputStream(_socket.getInputStream()); >@@ -749,71 +727,64 @@ > return; > } > >- while(!_isComplete) >- { >- incompleteMsg = false; /* 185463 */ >- try >- { >- int bytesRead=inStream.read(buffer, masterOffset, buffer.length-masterOffset); >+ while(!_isComplete) { >+ incompleteMsg = false; // 185463 >+ try { >+ int bytesRead = inStream.read(buffer, masterOffset, buffer.length-masterOffset); >+ if(bytesRead == -1) break; > >- if(bytesRead==-1) {break;} >- >- if (masterOffset > 0) >- { >+ if (masterOffset > 0) { > bytesRead += masterOffset; > masterOffset = 0; > } > >- /* >- * If we've tried to connect to a backward compatibility >- * layer of the AC, we'll immediately get a response in >- * RAC format. If we ignore this, the BC layer will >- * respond to our first message by giving us the port >- * to connect to the regular socket TL. >- */ >+ // >+ // If we've tried to connect to a backward compatibility >+ // layer of the AC, we'll immediately get a response in >+ // RAC format. If we ignore this, the BC layer will >+ // respond to our first message by giving us the port >+ // to connect to the regular socket TL. >+ // > int vret = checkForRACMessage(buffer, masterOffset); >- if(vret != -1) >- { >+ if (vret != -1) { > // We read the header, the next four bytes will be the length > // (including the header) of the RAC message >- long length=TPTPMessageUtil.readTPTPLongFromBuffer(buffer, vret); >+ long length = TPTPMessageUtil.readTPTPLongFromBuffer(buffer, vret); > masterOffset = (int)length; > } > >- while(masterOffset<bytesRead) >- { >+ while(masterOffset<bytesRead) { > int newOffset=0; >- /* First we make sure we have at least enough read for the message header. >- If not, compress and re-read. >- */ >+ // First we make sure we have at least enough read for the message header. >+ // If not, compress and re-read. >+ // > if ( bytesRead-masterOffset < AC_MESSAGE_HEADER_SIZE ) { > System.arraycopy( buffer, masterOffset, buffer, 0, bytesRead-masterOffset ); > masterOffset=bytesRead-masterOffset; > incompleteMsg = true; > break; > } >- /* We have the header information, now lets try and get the entire message. Once >- again the same error conditions can occur. >- */ >- if(Constants.TPTP_DEBUG)System.out.println("Received a non-acknowledgement message"); >- //System.out.println("Offset xx::"+new String(buffer)); >- newOffset=processControlMessage(buffer, masterOffset, bytesRead); >- if(Constants.TPTP_DEBUG)System.out.println("Recvd Message : " + buffer.toString()); >- if ( newOffset == -1 ) >- { >+ >+ // We have the header information, now lets try and get the entire message. Once >+ // again the same error conditions can occur. >+ // >+ newOffset = processControlMessage(buffer, masterOffset, bytesRead); >+ >+ if(Constants.TPTP_DEBUG)System.out.println("Recvd Message: " + buffer.toString()); >+ >+ if (newOffset == -1) { > // newOffset of -1 indicates the message is bigger than what's left in the buffer > // If the masterOffset is zero, this means the message is bigger than the buffer > // itself, so we need to grow the buffer. Otherwise, we'll slide the message > // to the beginning of the buffer and try to read some more >- if(masterOffset>0) >- { >+ if(masterOffset>0) { > System.arraycopy( buffer, masterOffset, buffer, 0, bytesRead-masterOffset ); > } > else if (bytesRead == buffer.length) > { > int len = buffer.length * 2; > byte[] tmpbuffer=new byte[len]; >- /* Copy necessary data over to new buffer */ >+ // Copy necessary data over to new buffer > System.arraycopy(buffer, masterOffset, tmpbuffer, 0, bytesRead-masterOffset); > buffer = tmpbuffer; > } >@@ -822,22 +793,14 @@ > break; > } > masterOffset=newOffset; >- } /* end of inner while */ >+ } // end of inner while > > if (!incompleteMsg) > { > masterOffset=0; > } > } >- catch(InterruptedIOException e) >- { >- if(timeoutCount > Constants.CONNECT_TIMEOUT_TRY_COUNT && !_isInitialized) >- { >- synchronized(_connectionLock) { >- _connectionLock.notifyAll(); >- } >- } >- timeoutCount++; >+ catch(InterruptedIOException e) { > } > catch(SocketException e) > { >@@ -849,9 +812,40 @@ > //e.printStackTrace(); > break; > } >- } /* end of outer while */ >- /* The server is now stopping */ >+ } // end of outer while >+ // The server is now stopping >+ > disconnect(); > } > } >+ >+ public boolean isAuthenticated() { >+ return isAuthenticated; >+ } >+ >+ protected boolean authenticateUser(User user) { >+ if (user == null || user.getName() == null || user.getPassword() == null) return false; >+ >+ ControlMessage authMsg = new ControlMessage(); >+ authMsg.setMessageType(Constants.TPTP_AC_MESSAGE); >+ authMsg.setMagicNumber(Constants.AC_MAGIC_NUMBER); >+ authMsg.setFlags(Constants.AUTHENTICATE); >+ >+ AuthenticateCommand authCmd = new AuthenticateCommand(user.getName(), user.getPassword()); >+ authMsg.appendCommand(authCmd); >+ >+ try { >+ sendMessage(authMsg, new ICommandHandler() { >+ public void incomingCommand(INode node, ICommandElement command) {} >+ }); >+ } catch (Exception e) { >+ return false; >+ } >+ >+ synchronized (authLock) { >+ try { authLock.wait(Constants.WAIT_RESPONCE_TIMEOUT); } catch (Exception e) {} >+ } >+ >+ return isAuthenticated; >+ } > } >Index: src/org/eclipse/tptp/platform/execution/exceptions/LoginFailedException.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/exceptions/LoginFailedException.java,v >retrieving revision 1.3 >diff -u -r1.3 LoginFailedException.java >--- src/org/eclipse/tptp/platform/execution/exceptions/LoginFailedException.java 10 Feb 2006 21:10:24 -0000 1.3 >+++ src/org/eclipse/tptp/platform/execution/exceptions/LoginFailedException.java 9 Jul 2007 14:37:56 -0000 >@@ -28,6 +28,10 @@ > private long _port; > > >+ public LoginFailedException() { >+ _port = 0; >+ } >+ > public LoginFailedException(long port) { > _port=port; > } >Index: src/org/eclipse/tptp/platform/execution/client/core/IAgentController.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/IAgentController.java,v >retrieving revision 1.17 >diff -u -r1.17 IAgentController.java >--- src/org/eclipse/tptp/platform/execution/client/core/IAgentController.java 26 Apr 2006 04:02:51 -0000 1.17 >+++ src/org/eclipse/tptp/platform/execution/client/core/IAgentController.java 9 Jul 2007 14:37:55 -0000 >@@ -283,6 +283,8 @@ > */ > boolean authenticateUser(User user) throws NotConnectedException; > >+ boolean isAuthenticated(); >+ > /** > * Get a Agent Reference to communicate with the agent > * @param agentName >Index: src/org/eclipse/tptp/platform/execution/client/core/NodeFactory.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/NodeFactory.java,v >retrieving revision 1.4 >diff -u -r1.4 NodeFactory.java >--- src/org/eclipse/tptp/platform/execution/client/core/NodeFactory.java 24 Apr 2006 20:31:26 -0000 1.4 >+++ src/org/eclipse/tptp/platform/execution/client/core/NodeFactory.java 9 Jul 2007 14:37:55 -0000 >@@ -87,8 +87,11 @@ > * if the Node exists it will be returned. > */ > public static INode createNode(InetAddress address) throws UnknownHostException { >- //return createNode(address, null); >- return createNode(address); >+ String hostname = address.getHostName(); >+ INode node = containsNode(hostname); >+ if (node != null) return node; >+ >+ return addNode(hostname, address, null); > } > > >@@ -148,10 +151,6 @@ > } > } > >- >- >- >- > private static INode containsNode(String name) { > synchronized(_servers) { > // If this is "localhost" try and resolve its real name first >@@ -199,7 +198,6 @@ > return null; > } > >- > /** > * Searches the Node list based upon the InetAddress. > * @return the Node if it exists, null otherwise. >@@ -208,7 +206,4 @@ > //return getNode(addr, null); > return containsNode(addr.getHostName()); > } >- >- > } >- >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/X509TrustManagerImpl.java >=================================================================== >RCS file: src/org/eclipse/tptp/platform/execution/client/core/internal/X509TrustManagerImpl.java >diff -N src/org/eclipse/tptp/platform/execution/client/core/internal/X509TrustManagerImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/X509TrustManagerImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,47 @@ >+package org.eclipse.tptp.platform.execution.client.core.internal; >+ >+import java.security.KeyStore; >+import java.security.cert.CertificateException; >+import java.security.cert.X509Certificate; >+ >+import javax.net.ssl.TrustManager; >+import javax.net.ssl.TrustManagerFactory; >+import javax.net.ssl.X509TrustManager; >+ >+public class X509TrustManagerImpl implements X509TrustManager { >+ private X509TrustManager defaultX509tm; >+ >+ X509TrustManagerImpl () throws Exception { >+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509"); >+ tmf.init((KeyStore) null); >+ >+ TrustManager tms[] = tmf.getTrustManagers(); >+ for (int i=0; i<tms.length; i++) { >+ if (tms[i] instanceof X509TrustManager) { >+ defaultX509tm = (X509TrustManager) tms[i]; >+ break; >+ } >+ } >+ } >+ >+ public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { >+ if (defaultX509tm == null) throw new CertificateException ("Trust manager not found"); >+ >+ defaultX509tm.checkClientTrusted(certs, authType); >+ } >+ >+ public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { >+ if (defaultX509tm != null) >+ try { >+ defaultX509tm.checkServerTrusted(certs, authType); >+ return; >+ } catch (Exception e) {} >+ >+// ask user if certificate is trusted, save it >+ } >+ >+ public X509Certificate[] getAcceptedIssuers() { >+ if (defaultX509tm != null) return defaultX509tm.getAcceptedIssuers(); >+ return null; >+ } >+} >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/commands/AuthenticateCommand.java >=================================================================== >RCS file: src/org/eclipse/tptp/platform/execution/client/core/internal/commands/AuthenticateCommand.java >diff -N src/org/eclipse/tptp/platform/execution/client/core/internal/commands/AuthenticateCommand.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/commands/AuthenticateCommand.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+package org.eclipse.tptp.platform.execution.client.core.internal.commands; >+ >+import org.eclipse.tptp.platform.execution.util.internal.CommandElement; >+import org.eclipse.tptp.platform.execution.util.internal.TPTPMessageUtil; >+import org.eclipse.tptp.platform.execution.util.internal.TPTPString; >+ >+public class AuthenticateCommand extends CommandElement { >+ private TPTPString name; >+ private TPTPString password; >+ >+ public AuthenticateCommand(String name, String password) { >+ this.name = new TPTPString(name); >+ this.password = new TPTPString(password); >+ } >+ >+ public int getSize() { >+ return name.getSize() + password.getSize(); >+ } >+ >+ public int readFromBuffer(byte[] buffer, int offset) { >+ return 0; >+ } >+ >+ public int writeToBuffer(byte[] buffer, int offset) { >+ int current = TPTPMessageUtil.writeTPTPStringToBuffer(buffer, offset, name); >+ return TPTPMessageUtil.writeTPTPStringToBuffer(buffer, current, password); >+ } >+} >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionFactory.java >=================================================================== >RCS file: src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionFactory.java >diff -N src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/ConnectionFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,39 @@ >+package org.eclipse.tptp.platform.execution.client.core.internal; >+ >+import java.io.IOException; >+ >+import org.eclipse.tptp.platform.execution.client.core.ConnectionInfo; >+import org.eclipse.tptp.platform.execution.client.core.INode; >+import org.eclipse.tptp.platform.execution.exceptions.LoginFailedException; >+import org.eclipse.tptp.platform.execution.exceptions.NotConnectedException; >+import org.eclipse.tptp.platform.execution.exceptions.ReconnectRequestedException; >+import org.eclipse.tptp.platform.execution.exceptions.SecureConnectionRequiredException; >+import org.eclipse.tptp.platform.execution.exceptions.UntrustedAgentControllerException; >+ >+public class ConnectionFactory { >+ public static IConnection createConnection (INode node, ConnectionInfo conInfo) throws LoginFailedException, >+ UntrustedAgentControllerException, IOException, ReconnectRequestedException, SecureConnectionRequiredException, >+ NotConnectedException { >+ >+ ConnectionImpl con = null; >+ boolean securityRequired = false; >+ >+ try { >+ con = new ConnectionImpl(); >+ con.connect(node, conInfo); >+ } catch (SecureConnectionRequiredException e) { >+ securityRequired = true; >+ } >+ >+ if (!securityRequired) return con; // insecure connection >+ >+ SecureConnectionImpl secCon = new SecureConnectionImpl (); >+ >+ if (!secCon.connect(node, con)) { >+ secCon.close(); >+ secCon = null; >+ } >+ >+ return secCon; >+ } >+} >Index: src/org/eclipse/tptp/platform/execution/samples/SecureClientAC.java >=================================================================== >RCS file: src/org/eclipse/tptp/platform/execution/samples/SecureClientAC.java >diff -N src/org/eclipse/tptp/platform/execution/samples/SecureClientAC.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/tptp/platform/execution/samples/SecureClientAC.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,116 @@ >+package org.eclipse.tptp.platform.execution.samples; >+ >+import org.eclipse.tptp.platform.execution.client.agent.*; >+import org.eclipse.tptp.platform.execution.client.core.*; >+import org.eclipse.tptp.platform.execution.security.User; >+import org.eclipse.tptp.platform.execution.util.*; >+ >+public class SecureClientAC { >+ public final static String HOST = "localhost"; >+ public final static int PORT = 10006; >+ >+ public static void main(String[] args) { >+ ConnectionInfo connInfo = null; >+ IAgentController ac = null; >+ INode node = null; >+ >+ System.out.println("Connecting to Agent Controller\n"); >+ >+ try { >+ node = NodeFactory.createNode(HOST); >+ //Set the connection parameters required >+ connInfo = new ConnectionInfo(); >+ connInfo.setHostName(HOST); >+ connInfo.setPort(PORT); >+ >+ ac = node.connect(connInfo); >+ } catch (Exception e) { >+ System.out.println("Error occurred while connecting to " + HOST + ":" + e); >+ } >+ >+ if (ac == null) return; >+ >+ System.out.println("Connected to " + HOST + ":" + PORT); >+ >+ while (!ac.isAuthenticated()) { >+ User user = getUser(); >+ if (user == null) { >+ System.out.println("\nAuthentication failed"); >+ break; >+ } >+ >+ try { >+ ac = node.connect(connInfo, user); >+ } catch (Exception e) {} >+ } >+ >+ if (!ac.isAuthenticated()) { >+ ac.disconnect(); >+ return; >+ } >+ >+ try { >+ ICollector timeCollector = (ICollector) ac.getAgent("org.eclipse.tptp.TimeCollector", "org.eclipse.tptp.platform.execution.client.agent.ICollector"); >+ if(timeCollector == null) { >+ System.out.println("Agent not available, configure the agent and retry"); >+ ac.disconnect(); >+ return; >+ } >+ >+ //Create the Data Connection required to recieve response from the collector; >+ //The input to startMonitoring is the to establish the data connection between the client and >+ //the agent controller for the direction of data flow. >+ //See constants for additional values. >+ timeCollector.startMonitoring(TPTPDataPath.DATA_PATH_TWO_WAY); >+ timeCollector.addDataListener(new IDataProcessor() { >+ public void incomingData(byte[] buffer, int length, java.net.InetAddress peer) { >+ String data = new String(buffer, 0, length); >+ System.out.println("The Data received from TimeCollector - " + data.trim()); >+ } >+ >+ public void incomingData(char[] buffer, int length, java.net.InetAddress peer) {} >+ public void invalidDataType(byte[] data, int length, java.net.InetAddress peer) {} >+ public void waitingForData() {} >+ }); >+ >+ //Send a message to Agent >+ >+ timeCollector.run(); >+ timeCollector.sendData("HELLO from org.eclipse.tptp.platform.execution plugin".getBytes()); >+ //Wait for the response to arrive >+ Thread.sleep(2000); >+ >+ timeCollector.stop(); >+ >+ Thread.sleep(1000); >+ // Disconnect from AC >+ ac.disconnect(); >+ System.out.println("disconnected"); >+ } >+ catch(Exception exp) { >+ System.out.println("Error occurred while connecting to " + HOST + ":" + exp); >+ } >+ } >+ >+ private static User getUser() { >+ byte buf[] = new byte[256]; >+ int n; >+ >+ System.out.println("\nUser authentication."); >+ System.out.print("Login: "); >+ try { n = System.in.read(buf); } catch (Exception e) { n = 0; } >+ if (n <= 0) return null; >+ >+ String login = new String(buf, 0, n).trim(); >+ if (login.length() == 0) return null; >+ >+ System.out.print("Password: "); >+ try { n = System.in.read(buf); } catch (Exception e) { n = 0; } >+ if (n <= 0) return null; >+ >+ String psw = new String(buf, 0, n).trim(); >+ if (psw.length() == 0) return null; >+ >+ return new User(null, login, psw); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 195644
:
73419
|
73421
|
73422
|
73423
|
73425
|
73429
|
77241
|
77242
|
77243
|
80051
|
80132
|
80870
|
84612
|
84631