We're using remote EJBs to connect two parts of our application with each other. We run into trouble when multiple users (threads) try to access the remote beans at the same time. It appears as though the EJBClientContext is not thread aware and the different users end up using each others credentials. We've been searching and trying all kinds of different ways of configuring the initial context to get the lookup working with the right credentials, but we've not been able to figure it out.
This is what we have right now. Our test calls this code twice on two seperate threads. One with correct user credentials and one with incorrect user credentials. This should consistently succeed and fail once, but sometimes they both fail, and other times they both succeed. Clearly the configuration is somehow leaking to other threads.
final Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); final Properties ejbProperties = new Properties(); ejbProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); ejbProperties.put("remote.connections", "1"); ejbProperties.put("remote.connection.1.host", "localhost"); ejbProperties.put("remote.connection.1.port", "8080"); ejbProperties.put("remote.connection.1.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER"); // needed for forcing authentication over remoting (i.e. if you have a custom login module) ejbProperties.put("remote.connection.1.username", userName); ejbProperties.put("remote.connection.1.password", password); ejbProperties.put("org.jboss.ejb.client.scoped.context", "true"); final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(ejbProperties); final ConfigBasedEJBClientContextSelector selector = new ConfigBasedEJBClientContextSelector(ejbClientConfiguration); final Context context; EJBClientContext.setSelector(selector); context = new InitialContext(jndiProperties); final HelloRemote remote = (HelloRemote) context.lookup("ejb:SecurityTestEAR/SecurityTestEJB/HelloBean!" + HelloRemote.class.getName()); SimpleMessage result = remote.helloSimple("xxx"); System.out.println(result.getMessage());
Note: we have already tried EJBClientContext.getCurrent().setSelector(selector) but this does not seem to change anything. The source code of EJBClientContext shows that getCurrent() returns a static reference.... I don't know if thats a bug or we just don't understand the right way of doing it.
Any help to get this working would be very much appreciated!