EJB jndi lookup with a custom login module
fpezzati Nov 8, 2015 7:18 AMHello,
I'm using Wildfly-9.0.1.Final and I'm facing a strange problem, when I try to invoke an EJB using jndilookup I got this error on Wildfly's log:
19:42:22,640 INFO [it.bytebear.jaas.mongo.module.MongoLoginModule] (EJB default - 4) Initializing MongoLoginModule.
19:42:22,640 INFO [it.bytebear.jaas.mongo.module.MongoLoginModule] (EJB default - 4) login requested.
19:42:27,347 INFO [it.bytebear.jaas.mongo.module.MongoLoginModule] (EJB default - 4) check credentials for: jim with passwd: org.jboss.as.security.remoting.RemotingConnectionCredential@1f6a2a8c
19:42:27,347 INFO [it.bytebear.jaas.mongo.module.MongoLoginModule] (EJB default - 4) abort!
19:42:27,349 ERROR [org.jboss.as.ejb3.invocation] (EJB default - 4) WFLYEJB0034: EJB Invocation failed on component UserServices for method public abstract java.lan
g.String it.bytebear.web.mongo.UserServiceRemote.postUserA(): javax.ejb.EJBAccessException: WFLYSEC0027: Invalid User
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:69)
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:49)
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:97)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.deployment.processors.EjbSuspendInterceptor.processInvocation(EjbSuspendInterceptor.java:53)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:66)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:634)
at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:195)
at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:331)
at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$100(MethodInvocationMessageHandler.java:69)
at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:202)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
As you can see password callback is returning this weird String value: org.jboss.as.security.remoting.RemotingConnectionCredential@1f6a2a8c. The EJB and the custom login works well. The EJB is exposed as a RESTful web service and I can access it as expected. This is my client, maybe there is something wrong in it:
public class EjbClientTest {
private Context jndiContext;
private Properties jndiProperties;
@Before
public void init() {
jndiProperties = new Properties();
jndiProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
jndiProperties.put("remote.connections", "default");
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,
org.jboss.naming.remote.client.InitialContextFactory.class
.getName());
jndiProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "true");
jndiProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
jndiProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProperties.put(Context.SECURITY_PRINCIPAL, "gino");
jndiProperties.put(Context.SECURITY_CREDENTIALS, "strada");
jndiProperties.put("jboss.naming.client.ejb.context", true);
}
@Test
public void test() {
try {
jndiContext = new InitialContext(jndiProperties);
UserServiceRemote usrv = (UserServiceRemote) jndiContext
.lookup("/MongoWebTest/UserServices!it.bytebear.web.mongo.UserServiceRemote");
System.out.println("Risultato: " + usrv.postUserA());
Assert.assertTrue(true);
} catch (NamingException e) {
e.printStackTrace();
Assert.fail();
} catch (Exception e) {
e.printStackTrace();
Assert.fail();
}
}
}