Programmatic remote ejb call issue with WildFly Naming Client?
valsaraj007 Jun 19, 2019 10:14 AMIs wildfly-config.xml is mandatory for WildFly Naming Client?
I have removed it and used the Programmatic Approach because of this:
wildfly-config.xml contains user creds which will be available as principal in EJB. We have multiple users using same client. Also using a custom security realm. So user creds will change each time.
But the lookup fails with Programmatic Approach but works with wildfly-config.xml approach.
Here is wildfly-config.xml:
<configuration>
<authentication-client xmlns="urn:elytron:1.0">
<authentication-rules>
<rule use-configuration="default"/>
</authentication-rules>
<authentication-configurations>
<configuration name="default">
<sasl-mechanism-selector selector="PLAIN"/>
<providers>
<use-service-loader />
</providers>
<set-user-name name="ejbuser1"/>
<credentials>
<clear-password password="*****"/>
</credentials>
<set-mechanism-realm name="SSLRealm" />
</configuration>
</authentication-configurations>
</authentication-client>
<jboss-ejb-client xmlns="urn:jboss:wildfly-client-ejb:3.0">
<connections>
<connection uri="remote+http://localhost:8080" />
</connections>
</jboss-ejb-client>
</configuration>
After working this, I removed this file and added code for Programmatic Approach:
// create your authentication configuration
AuthenticationConfiguration namingConfig = AuthenticationConfiguration.empty()
.setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("PLAIN"))
.useRealm("SSLRealm")
.useName(username)
.usePassword(password);
// create your authentication context
AuthenticationContext context = AuthenticationContext.empty()
.with(MatchRule.ALL.matchHost("localhost"), namingConfig);
// create a callable that creates and uses an InitialContext
Callable<Void> callable = () -> {
Properties properties1 = new Properties();
properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
properties1.put(Context.PROVIDER_URL, ejbProperties.get("java.naming.provider.url"));
ctx = new InitialContext(properties1);
return null;
};
// use your authentication context to run your callable
try {
context.runCallable(callable);
// ERROR HERE
appBean = (AppRemote) ctx.lookup(getJNDIPrefix() + "AppBean!" + AppRemote.class.getName());
} catch (NamingException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
}
Then got following error:
Caused by: javax.security.sasl.SaslException: Authentication failed: none of the mechanisms presented by the server (PLAIN) are supported
at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:444)
at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:242)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
at ...asynchronous invocation...(Unknown Source)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:571)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:537)
at org.jboss.remoting3.ConnectionInfo$None.getConnection(ConnectionInfo.java:82)
at org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:55)
at org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:488)
at org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:434)
at org.jboss.remoting3.UncloseableEndpoint.getConnectedIdentity(UncloseableEndpoint.java:52)
at org.jboss.remoting3.Endpoint.getConnectedIdentity(Endpoint.java:123)
at org.jboss.ejb.protocol.remote.RemoteEJBReceiver.lambda$getConnection$2(RemoteEJBReceiver.java:185)
at java.security.AccessController.doPrivileged(Native Method)
Any guess what may be wrong?