Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Adding CDO authentication to offline example
[CDO] Adding CDO authentication to offline example [message #1014850] Tue, 26 February 2013 15:34 Go to next message
Ricky de Klerck is currently offline Ricky de KlerckFriend
Messages: 295
Registered: January 2011
Senior Member
We're using the CDO offline/clone example as a base for our application, but we're trying to add file based CDO authentication (http://wiki.eclipse.org/CDO/Net4j_Authentication#Property-File_based_Authentication).

All examples I can find online have a cdo-server.xml, but the example doesn't. It's creating a repository through code..

How can we add the authentication part to the server side? This is our code which starts the repository:

JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:db/server");

IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(true, true);
IDBAdapter dbAdapter = new H2Adapter();
IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(dataSource);
IStore store = CDODBUtil.createStore(mappingStrategy, dbAdapter, dbConnectionProvider);

Map<String, String> props = new HashMap<String, String>();
props.put(IRepository.Props.OVERRIDE_UUID, REPOSITORY_NAME);
props.put(IRepository.Props.SUPPORTING_AUDITS, "true");
props.put(IRepository.Props.SUPPORTING_BRANCHES, "true");
props.put(IRepository.Props.ID_GENERATION_LOCATION, "CLIENT");

IRepository repository = createRepository(node, store, props);
    
repository.setInitialPackages(ModelPackage.eINSTANCE);
CDOServerUtil.addRepository(IPluginContainer.INSTANCE, repository);


I assume the UserManager has to be created here somehow..?

Thanks in advance.
Re: [CDO] Adding CDO authentication to offline example [message #1014880 is a reply to message #1014850] Tue, 26 February 2013 16:30 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 26.02.2013 16:34, schrieb Ricky de Klerck:
> We're using the CDO offline/clone example as a base for our application, but we're trying to add file based CDO
> authentication (http://wiki.eclipse.org/CDO/Net4j_Authentication#Property-File_based_Authentication).
>
> All examples I can find online have a cdo-server.xml, but the example doesn't. It's creating a repository through code..
>
> How can we add the authentication part to the server side? This is our code which starts the repository:
>
> JdbcDataSource dataSource = new JdbcDataSource();
> dataSource.setURL("jdbc:h2:db/server");
>
> IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(true, true);
> IDBAdapter dbAdapter = new H2Adapter();
> IDBConnectionProvider dbConnectionProvider = DBUtil.createConnectionProvider(dataSource);
> IStore store = CDODBUtil.createStore(mappingStrategy, dbAdapter, dbConnectionProvider);
>
> Map<String, String> props = new HashMap<String, String>();
> props.put(IRepository.Props.OVERRIDE_UUID, REPOSITORY_NAME);
> props.put(IRepository.Props.SUPPORTING_AUDITS, "true");
> props.put(IRepository.Props.SUPPORTING_BRANCHES, "true");
> props.put(IRepository.Props.ID_GENERATION_LOCATION, "CLIENT");
>
> IRepository repository = createRepository(node, store, props);
> repository.setInitialPackages(ModelPackage.eINSTANCE);
> CDOServerUtil.addRepository(IPluginContainer.INSTANCE, repository);
>
> I assume the UserManager has to be created here somehow..?
Authentication is set up in the session manager of a repository. Please note that
InternalSessionManager.setUserManager() has been deprecated as of CDO 4.2 in favour of ISessionManager.setAuthenticator():

299275: Flexible Approach for an Authentication Mechanism
https://bugs.eclipse.org/bugs/show_bug.cgi?id=299275

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Adding CDO authentication to offline example [message #1015391 is a reply to message #1014880] Thu, 28 February 2013 13:16 Go to previous messageGo to next message
Ricky de Klerck is currently offline Ricky de KlerckFriend
Messages: 295
Registered: January 2011
Senior Member
I've enhanced our application with an Authenticator:

 public void start(Node node)
  {
    IRepository repository = createRepository(node);

    // add authenticate to sessionmanager
    final ISessionManager sessionManager = repository.getSessionManager();
    sessionManager.setAuthenticator(new CustomAuthenticator());

    node.setObject(IRepository.class, repository);

    IAcceptor acceptor = createAcceptor(node);
    node.setObject(IAcceptor.class, acceptor);

    String browserPort = node.getSetting(BROWSER_PROPERTY);
    if (browserPort != null && browserPort.length() != 0)
    {
      CDOServerBrowser browser = (CDOServerBrowser)IPluginContainer.INSTANCE.getElement(
          "org.eclipse.emf.cdo.server.browsers", "default", browserPort);
      node.setObject(CDOServerBrowser.class, browser);
    }
  }


The clients passes a PasswordCredentialsProvider:

PasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider("test", "test");
CDONet4jSessionConfiguration configuration;

IConnector connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, "tcp", serverAddress);

configuration = CDONet4jUtil.createNet4jSessionConfiguration();
configuration.setConnector(connector);
configuration.setCredentialsProvider(credentialsProvider);


But when the authentication failes I receive a SecurityException on the server side thrown by the Authenticator. This exception is not caught anywhere else and is not visible in the client.. The client receives a TimeoutException.. How can I solve this? I want the SecurityException to appear in the client.
Re: [CDO] Adding CDO authentication to offline example [message #1015523 is a reply to message #1015391] Fri, 01 March 2013 05:34 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 28.02.2013 14:16, schrieb Ricky de Klerck:
> I've enhanced our application with an Authenticator:
>
>
> public void start(Node node)
> {
> IRepository repository = createRepository(node);
>
> // add authenticate to sessionmanager
> final ISessionManager sessionManager = repository.getSessionManager();
> sessionManager.setAuthenticator(new CustomAuthenticator());
>
> node.setObject(IRepository.class, repository);
>
> IAcceptor acceptor = createAcceptor(node);
> node.setObject(IAcceptor.class, acceptor);
>
> String browserPort = node.getSetting(BROWSER_PROPERTY);
> if (browserPort != null && browserPort.length() != 0)
> {
> CDOServerBrowser browser = (CDOServerBrowser)IPluginContainer.INSTANCE.getElement(
> "org.eclipse.emf.cdo.server.browsers", "default", browserPort);
> node.setObject(CDOServerBrowser.class, browser);
> }
> }
>
>
> The clients passes a PasswordCredentialsProvider:
>
>
> PasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider("test", "test");
> CDONet4jSessionConfiguration configuration;
>
> IConnector connector = Net4jUtil.getConnector(IPluginContainer.INSTANCE, "tcp", serverAddress);
>
> configuration = CDONet4jUtil.createNet4jSessionConfiguration();
> configuration.setConnector(connector);
> configuration.setCredentialsProvider(credentialsProvider);
>
>
> But when the authentication failes I receive a SecurityException on the server side thrown by the Authenticator. This
> exception is not caught anywhere else and is not visible in the client.. The client receives a TimeoutException.. How
> can I solve this? I want the SecurityException to appear in the client.
That's strange because we test that in org.eclipse.emf.cdo.tests.SessionTest:

public void testWithAuthenticationWrongCredentials() throws Exception
{
UserManager userManager = new UserManager();
userManager.activate();
userManager.addUser(USER_ID, PASSWORD1);

getTestProperties().put(RepositoryConfig.PROP_TEST_AUTHENTICATOR, userManager);
getRepository("authrepo5");

getTestProperties().put(SessionConfig.PROP_TEST_CREDENTIALS_PROVIDER,
new PasswordCredentialsProvider(new PasswordCredentials(USER_ID, PASSWORD2)));

try
{
openSession("authrepo5");
fail("SecurityException expected");
}
catch (SecurityException expected)
{
// SUCCESS
}
}

The test passes. Is it possible that you provide me with code that I can execute to reproduce the problem?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Re: [CDO] Adding CDO authentication to offline example [message #1015576 is a reply to message #1015523] Fri, 01 March 2013 09:23 Go to previous message
Ricky de Klerck is currently offline Ricky de KlerckFriend
Messages: 295
Registered: January 2011
Senior Member
I've enhanced your offline example with the authentication (NodeType.java enclosed). Just create a server and client and you see the exception is thrown on the server side..

Can you reproduce it?
  • Attachment: NodeType.java
    (Size: 25.91KB, Downloaded 350 times)
Previous Topic:EMF Logical Structure when debugging
Next Topic:[Teneo] Entity JPA Annotation Issue
Goto Forum:
  


Current Time: Tue Mar 19 11:32:37 GMT 2024

Powered by FUDForum. Page generated in 0.02061 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top