Bug 162475 - Agent Controller authentication code is tightly coupled with UI code
Summary: Agent Controller authentication code is tightly coupled with UI code
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: TPTP (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P1 major (vote)
Target Milestone: ---   Edit
Assignee: Eugene Chan CLA
QA Contact:
URL:
Whiteboard:
Keywords: plan
Depends on:
Blocks: 171840
  Show dependency tree
 
Reported: 2006-10-26 16:17 EDT by Joe Toomey CLA
Modified: 2016-05-05 10:44 EDT (History)
1 user (show)

See Also:


Attachments
stack trace showing where we try to bring up UI even when username & password are specified (143.60 KB, image/jpeg)
2007-05-03 17:28 EDT, Joe Toomey CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Toomey CLA 2006-10-26 16:17:06 EDT
I'd like to write an automated test for the file transfer service using a secure Agent Contoller, but I have found that you can't programmatically connect to a secure Agent Controller without going through TPTP Platform UI.  I have tried specifying username and password in a ConnectionSpecifier, but that code doesn't appear to be hooked up properly yet.

				ConnectionSpecifier spec = new ConnectionSpecifier(null,
						null, HOST, 10002, null, "jtoomey_temp", "fake_password");
				// Create a node pointing to local machine
				node = new NodeImpl(HOST);

				// Establish a session by connecting to the node
				try {
					session = node.connect(spec);
				} catch (Exception e) {
					e.printStackTrace(consolePrintStream);
				}

However, I tried hard coding the username and password into the ConnectorService.java class (which, suspiciously is in the org.eclipse.hyades.ui plugin), and the code path still ended up calling into the ConnectUIUtil class and trying to pop up a username and password dialog.  This dialog is also brought up via syncExec, which caused my test plugin to deadlock.  But the root issue is that we should be able to programmatically connect to a secure agent controller if we specify a username and password, without drawing in a UI dependency.  One obvious use case is in running tests from ant or command line, where the UI is not available.

Feel free to change components if you think this is miscategorized.  I see that some of this code was refactored in 4.2, and it looks like a step in the right direction.
Comment 1 Valentina Popescu CLA 2006-10-26 16:41:37 EDT
Joe, this is a valid issue and I agree it should be done post 4.3
Assigning to Ali for further review
Comment 2 amehrega CLA 2006-10-26 16:53:38 EDT
Ideally this code should be moved to org.eclipse.tptp.platform.common, which is not depedent on any UI plug-ins.  I will take a look at this in 4.4.

Setting priority to P2.
Comment 3 Eugene Chan CLA 2007-01-31 18:32:17 EST
Target to future. Cannot be contained in 4.4 due to limitation of resource.
Comment 4 Joe Toomey CLA 2007-02-01 06:48:30 EST
Eugene,

This defect is blocking a critical test defect that needs to be fixed in 4.4.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=171840

Can we reconsider keeping it in 4.4?

Comment 5 Eugene Chan CLA 2007-02-01 10:07:39 EST
Joanna, There is a need to fix this for test defect, can you reconsider this in the 4.4 list with the resource available?
Comment 6 Eugene Chan CLA 2007-02-02 19:41:47 EST
Re-target to 4.4 base on a dependency of bug 171840.
Comment 7 Eugene Chan CLA 2007-05-03 11:31:01 EDT
Hi Joe,

Have you try

BaseConnectUtil connectUtil = new BaseConnectUtil(host, port, user,this);
int result = connectUtil.connect(password, false);

where BaseConnectUtil is org.eclipse.hyades.security.internal.util.BaseConnectUtil.
Comment 8 Joe Toomey CLA 2007-05-03 17:26:47 EDT
Hi Eugene,

It looks like this code is closer to what we need, but it still doesn't work the way I'd like it to.

I'm trying to connect to the agent controller securely from an ant script, so UI is not a possibility.  I had to make a couple of changes in the ant adapter code to the username and password are passed along as they should be, but even now that they are, BaseConnectUtil.connect is trying to bring up UI to ask me if I want to accept a new certificate for this connection.  I don't know if it would work if I had already done so or not.  I will attach a screenshot of the stack trace of where we are hung waiting for the UI.

Thanks.
Comment 9 Joe Toomey CLA 2007-05-03 17:28:46 EDT
Created attachment 65853 [details]
stack trace showing where we try to bring up UI even when username & password are specified
Comment 10 Eugene Chan CLA 2007-05-03 17:56:13 EDT
Joe. I am not sure if you are using the latest version of ConnectorService, the latest version creates an instance of ConnectUtil. If it creates an instance of BaseConnectUtil instead, if will not prompt any UI as the call of openQuestionDialog will return org.eclipse.hyades.security.internal.util.NullConnectUtilUI.openQuestionDialog() which skip the UI and return value 0 all the time.

Do you have to use ConnectorService? Could you try in your code make a direct call of 
BaseConnectUtil connectUtil = new BaseConnectUtil(host, port, user,this);
int result = connectUtil.connect(password, false);
instead?
Comment 11 Eugene Chan CLA 2007-05-03 18:00:02 EDT
It seems that if you want to skip UI, you cannot use org.eclipse.hyades.ui.services.ConnectorService, and it explains why it's under hyades.ui =)
It doens't seem like there is a non-UI equivalent of ConnectorService API.
Comment 12 Joe Toomey CLA 2007-05-04 09:41:01 EDT
Thanks for looking into this further, Eugene.

ConnectorService was designed to work headless, but when it was written, there was no BaseConnectUtil class (or even a org.eclipse.tptp.platform.common plugin at all).  Scott originally put the service in the org.eclipse.hyades.test.core plugin, but he had to add a dependency on org.eclipse.hyades.ui to pick up ConnectUtil, and that was obviously wrong.  So he ended up moving the service directly into org.eclipse.hyades.ui.

Since then, it appears a lot of good work has happened here, especially the refactoring that Ali did under 134531.

Based on your suggestion, I have modified the ConnectorService so that is uses BaseConnectUtil if we are running headless, but continues to use ConnectUtil if we are running in a workbench.

					// Use headless version if the PlatformUI workbench is not running.
					if (PlatformUI.isWorkbenchRunning())
						connectUtil = new ConnectUtil(host, port, user, ConnectorService.this);
					else
						connectUtil = new BaseConnectUtil(host, port, user, ConnectorService.this);
					int result = connectUtil.connect(password, showErrors);

I'm not certaın ıf thıs can be done easily, but it would be cool if ConnectUtil could make this determination on its own.  As it stands today, the ConnectorService still needs to remain in a plugin with a direct dependency on a UI plugin (now org.eclipse.tptp.platform.common.ui.)  I don't think this is a very big deal -- it may actually be a appropriate location for the service.  In any case, we can now use secure AC from headless ASF services, so that is cool indeed.

Thanks for your help.
Comment 13 Joe Toomey CLA 2007-07-10 15:59:33 EDT
Verified in 4.4.  Closing.