Home » Modeling » EMF » [CDO] open a client session when running a security manager
[CDO] open a client session when running a security manager [message #1229533] |
Thu, 09 January 2014 11:46  |
Eclipse User |
|
|
|
Hi all,
I followed the security manager wiki and now I would like my CDO client to open a session using a login / password.
I tried to use the following URL : tcp://Administrator:0000@localhost:2036.
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
|
|
| |
Re: [CDO] open a client session when running a security manager [message #1229794 is a reply to message #1229541] |
Fri, 10 January 2014 03:22   |
Eclipse User |
|
|
|
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 04:39   |
Eclipse User |
|
|
|
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
|
|
|
Re: [CDO] open a client session when running a security manager [message #1229910 is a reply to message #1229818] |
Fri, 10 January 2014 09:22   |
Eclipse User |
|
|
|
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 ?
|
|
| | | | | | | |
Goto Forum:
Current Time: Wed Jul 23 18:27:23 EDT 2025
Powered by FUDForum. Page generated in 0.04516 seconds
|