2014-07-01 63 views
0

我有獨立的應用程序連接到Wildfly服務器以獲取EJB代理。這是Maven項目,作爲一個依賴我:Wildfly上的遠程EJB

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

爲了讓我使用EJB:

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); 

一切工作正常,但服務器不要求用戶名和密碼。如何添加身份驗證?

回答

0

這適用於你,因爲你可能在本地主機上測試。如果您嘗試擊中任何遠程服務器,則會失敗。 WildFLy遠程EJB調用需要默認AFAIK認證。

您需要添加這些屬性:

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

您需要添加該用戶爲WildFly爲好。