Home » Modeling » EMF » [CDO] open a client session when running a security manager
|
Re: [CDO] open a client session when running a security manager [message #1229541 is a reply to message #1229533] |
Thu, 09 January 2014 17:12 |
|
Am 09.01.2014 17:46, schrieb Laurent Le Moux:
> Hi all,
>
> I followed the security manager wiki and now I would like my CDO client to open a session using a login / password.
You mean programmatically? Or via the CDO Sessions view?
> I tried to use the following URL : tcp://Administrator:0000@localhost:2036.
This URL can be used with the older Net4j authentication that is negotiator based. The wiki page mentioned above refers
to the newer CDO authentication. In many possible client configurations it would work out of the box. If it doesn't,
please tell us what you've tried.
In the CDO Sessions view's Open Session dialog you would enter:
tcp://localhost
repoName
If you followed the Security Manager tutorial a second dialog for the user credentials would pop up then.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
> But I get the following exception :
> java.lang.IllegalStateException: A user ID on this connector requires a negotiator
>
> Is it the right way to connect to my repository ?
> What negociator should be added to the acceptor declared in my cdo-server.xml, if any (none is actually declared in
> the security manager wiki...) ?
>
> I tried to have a look to the sessions view code in CDO Git but could not find my way...
>
> Kind regards,
>
> Laurent
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: [CDO] open a client session when running a security manager [message #1229794 is a reply to message #1229541] |
Fri, 10 January 2014 08:22 |
Laurent Le Moux Messages: 184 Registered: September 2011 |
Senior Member |
|
|
Hi Eike,
I indeed want to connect to the repository programmatically, trying to achieve something similar to the CDO Sessions view behaviour (which works fine !).
With the security manager activated on the server side, I get a NotAuthenticatedException if I try to use the classical URL (tcp://localhost) without providing somehow the expected user login and password.
So my RCP application now starts with a login dialog but I don't know how to pass the login & password parameters now that the former authentication mecanism is not to be used anymore.
Please find hereafter the code of my LoginDialog#okPressed method that fails with an IllegalStateException : A user ID on this connector requires a negotiator.
@Override
protected void okPressed() {
user = txtUser.getText();
password = txtPassword.getText();
Preferences preferences = DefaultScope.INSTANCE
.getNode("AdministrationTool");
try {
if (!preferences.nodeExists("/default/AdministrationTool")) {
ILog logger = Activator.getDefault().getLog();
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Configuration file 'AdministrationTool.ini' not found.");
logger.log(status);
super.cancelPressed();
} else {
String cdoServerURI = preferences.get("Protocol", "") + "://"
+ user + ":" + password + "@"
+ preferences.get("ServerName", "") + ":"
+ preferences.get("ServerPort", "");
connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE,
cdoServerURI);
CDONet4jSessionConfiguration sessionConfig = CDONet4jUtil
.createNet4jSessionConfiguration();
sessionConfig.setConnector(connector);
sessionConfig.setRepositoryName(preferences.get("Repository",
""));
session = sessionConfig.openNet4jSession();
context = EclipseContextFactory.getServiceContext(Activator
.getContext());
context.set("openedCDOSession", session);
super.okPressed();
}
} catch (Exception e) {
ILog logger = Activator.getDefault().getLog();
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
logger.log(status);
super.cancelPressed();
}
}
I also take the opportunity to wish you and the whole CDO team a happy new year and to thank you all for the great job you achieve.
Laurent
|
|
|
Re: [CDO] open a client session when running a security manager [message #1229818 is a reply to message #1229794] |
Fri, 10 January 2014 09:39 |
|
Am 10.01.2014 09:22, schrieb Laurent Le Moux:
> Hi Eike,
>
> I indeed want to connect to the repository programmatically, trying to achieve something similar to the CDO Sessions
> view behaviour (which works fine !).
That is because it uses CDONet4jSessionFactory ;-)
>
> With the security manager activated on the server side, I get a NotAuthenticatedException if I try to use the
> classical URL (tcp://localhost) without providing somehow the expected user login and password.
>
> So my RCP application now starts with a login dialog but I don't know how to pass the login & password parameters now
> that the former authentication mecanism is not to be used anymore.
>
> Please find hereafter the code of my LoginDialog#okPressed method that fails with an IllegalStateException : A user ID
> on this connector requires a negotiator.
>
>
> @Override
> protected void okPressed() {
> user = txtUser.getText();
> password = txtPassword.getText();
>
> Preferences preferences = DefaultScope.INSTANCE
> .getNode("AdministrationTool");
> try {
> if (!preferences.nodeExists("/default/AdministrationTool")) {
> ILog logger = Activator.getDefault().getLog();
> IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
> "Configuration file 'AdministrationTool.ini' not found.");
> logger.log(status);
> super.cancelPressed();
> } else {
> String cdoServerURI = preferences.get("Protocol", "") + "://"
> + user + ":" + password + "@"
You shouldn't embed the password into this URL.
> + preferences.get("ServerName", "") + ":"
> + preferences.get("ServerPort", "");
> connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE,
> cdoServerURI);
> CDONet4jSessionConfiguration sessionConfig = CDONet4jUtil
> .createNet4jSessionConfiguration();
> sessionConfig.setConnector(connector);
> sessionConfig.setRepositoryName(preferences.get("Repository",
> ""));
You should add this to get a popup dialog for the credentials (when they're needed):
IPasswordCredentialsProvider credentialsProvider =
(IPasswordCredentialsProvider)IPluginContainer.INSTANCE.getElement(CredentialsProviderFactory.PRODUCT_GROUP,
"interactive", null);
sessionConfig.setCredentialsProvider(credentialsProvider);
Or this for fixed credentials:
IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(user, password);
sessionConfig.setCredentialsProvider(credentialsProvider);
> session = sessionConfig.openNet4jSession();
> context = EclipseContextFactory.getServiceContext(Activator
> .getContext());
> context.set("openedCDOSession", session);
>
> super.okPressed();
> }
> } catch (Exception e) {
> ILog logger = Activator.getDefault().getLog();
> IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
> logger.log(status);
> super.cancelPressed();
> }
> }
>
>
> I also take the opportunity to wish you and the whole CDO team a happy new year and to thank you all for the great job
> you achieve.
Thanks a lot in the name of the team ;-)
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Re: [CDO] open a client session when running a security manager [message #1229910 is a reply to message #1229818] |
Fri, 10 January 2014 14:22 |
Laurent Le Moux Messages: 184 Registered: September 2011 |
Senior Member |
|
|
Following your tips, my login dialog with fixed credentials is now working.
But I decided to use CDO popup dialog instead.
So I removed mine and changed Application#start the following way :
public Object start(IApplicationContext context) throws Exception {
Preferences preferences = DefaultScope.INSTANCE.getNode("AdministrationTool");
if (!preferences.get("Repository", "").isEmpty()) {
Display display = PlatformUI.createDisplay();
String cdoServerURI = preferences.get("Protocol", "") + "://"
+ preferences.get("ServerName", "") + ":" + preferences.get("ServerPort", "");
connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, cdoServerURI);
CDONet4jSessionConfiguration sessionConfig = CDONet4jUtil.createNet4jSessionConfiguration();
sessionConfig.setConnector(connector);
sessionConfig.setRepositoryName(preferences.get("Repository", ""));
IPasswordCredentialsProvider credentialsProvider =
(IPasswordCredentialsProvider)IPluginContainer.INSTANCE.getElement(CredentialsProviderFactory.PRODUCT_GROUP,
"interactive", null);
//IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider("Administrator", "0000");
sessionConfig.setCredentialsProvider(credentialsProvider);
session = sessionConfig.openNet4jSession();
IEclipseContext ctx = EclipseContextFactory.getServiceContext(Activator.getContext());
ctx.set("openedCDOSession", session);
try {
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART)
return IApplication.EXIT_RESTART;
} finally {
display.dispose();
}
} else {
ILog logger = Activator.getDefault().getLog();
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID,
"Problem occured while loading configuration file 'AdministrationTool.ini'.");
logger.log(status);
}
return IApplication.EXIT_OK;
}
With fixed and hardcoded credentials, it still works.
But, using the interactive credentials provider factory, the application immediately hangs at startup. No window opens, no message at all in the console, not even the workspace directory "runtime-AdministrationTool.product" is created.
The factory has been declared in plugin.xml as well as the org.eclipse.net4j.util.ui dependency :
<extension
point="org.eclipse.net4j.util.factories">
<factory
class="org.eclipse.net4j.util.internal.ui.InteractiveCredentialsProviderFactory"
productGroup="org.eclipse.net4j.util.security.credentialsProviders"
type="interactive">
</factory>
</extension>
Any idea why this is happening ?
|
|
| | | | | |
Re: [CDO] open a client session when running a security manager [message #1242261 is a reply to message #1233836] |
Sun, 09 February 2014 08:30 |
|
Am 20.01.2014 16:58, schrieb Laurent Le Moux:
> Hi Eike,
>
> I guess you're right...
> I wanted to set a breakpoint but unfortunately I was not able to specify where to find the attached source code...
>
> So I decided to install Eclipse Modeling Luna 4.4 M4 and tried a simple test RCP application (see attached zip file) but I still get the same problem.
>
> I wonder if there's something wrong with my installation / configuration ?
No, the bug is in your Application.start() method. If you move the PlatformUI.createDisplay() call *after* the
sessionConfig.openNet4jSession() call it works perfectly.
Explanation: The openNet4jSession() blocks the current thread until the server has sent the response to the
OpenSessionRequest. But with authentication the server first sends an AuthenticationRequest (Challenge) back to the
client, where it is executed on a background thread. If this execution involves the InteractiveCredentialsProvider, or
any other Display.syncExec() calls, you end up in a deadlock if the thread of the original OpenSessionRequest is the UI
thread.
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
| |
Goto Forum:
Current Time: Wed May 08 05:51:48 GMT 2024
Powered by FUDForum. Page generated in 0.05675 seconds
|