0
votes

I have standalone application which is connecting to Wildfly server in order to get EJB proxy. This is maven project, as a dependency I have:

<dependency>
    <groupId>org.wildfly</groupId>
    <artifactId>wildfly-ejb-client-bom</artifactId>
    <version>8.0.0.Final</version>
    <type>pom</type>
</dependency>

To get the EJB I am using:

final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
env.put("jboss.naming.client.ejb.context", true);
InitialContext remoteContext = new InitialContext(env);

String jndi = "jndi";
RemoteInterface lookup = (RemoteInterface) remoteContext.lookup(jndi);

Everything works fine, but the server is not asking for username and password. How to add authentication?

1

1 Answers

0
votes

This works for you because you are testing on localhost probably. If you try to hit any remote server, then it will fail. WildFLy remote EJB calls need to be authenticated by default, AFAIK.

You need to add these properties:

env.put("java.naming.security.principal", "user");      
env.put("java.naming.security.credentials", "pass");

You need to add this user for WildFly as well.