2014-12-19 132 views
1

我正在编写一个独立的程序来调用EJB。而EJB被部署到我的本地JBoss服务器。我按照指引在这里: http://www.mastertheboss.com/jboss-server/jboss-as-7/jboss-as-7-remote-ejb-client-tutorial?showall=远程EJB调用

当我执行我的主要问题,它抛出

javax.ejb.EJBAccessException: JBAS013323: Invalid User 
javax.ejb.EJBAccessException: JBAS013323: Invalid User 
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:54) 
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:45) 
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:78) 

有谁知道我错过了什么?谢谢您的帮助。

我的主要程序:

private void start() throws Exception { 

    logger.info("----------------------program start--------------------------");  
    Context context = null;   
    try { 
     init();   
     final Hashtable<String, Object> jndiProperties = new Hashtable<>(); 
     jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
     jndiProperties.put("jboss.naming.client.ejb.context",true); 
     jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
     jndiProperties.put(Context.PROVIDER_URL,"remote://localhost:4447"); 

     context = new InitialContext(jndiProperties); 

     GrainReportManagerRemote grainReportManagerRemote = (GrainReportManagerRemote) context.lookup("java:GrainEar/GrainEJB/GrainReportManager!"+ GrainReportManagerRemote.class.getName()); 
     grainReportManagerRemote.export(); 

    } catch (Exception e) { 
     logger.error(e, e); 
    } finally { 
     if (context != null) 
      context.close(); 
    } 

    logger.info("----------------------program end--------------------------"); 
} 

jboss-ejb-client.properties:

endpoint.name = client-endpoint 
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS = false 
remote.connection.default.host              = localhost 
remote.connection.default.port              = 4447 
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED    = false 
remote.connections                 = default 
remote.connection.default.username=appuser 
remote.connection.default.password=appuser`123 
+0

你不需要重申有关JNDI的信息在你的代码,如果你正在使用JBoss的EJB -client.properties。你是否检查过ejb-client.properties是否在客户端的类路径中? – 2014-12-19 08:13:38

+0

我发现密码和用户名可以传递给我的自定义领域。但是,每次运行程序时都会返回随机密码。此外,我已经删除了ejb-clioent-properties并在程序中配置了jndi设置。 我的问题类似于这个问题(http://stackoverflow.com/questions/18181141/jboss7-custom-login-module-not-working),但我按照他的jndi配置,它仍然返回随机密码 – PrimaryChicken 2014-12-19 09:37:01

回答

1

我测试在JBoss 7.1.1您的代码,它给了我另一个异常:SaslException: Authentication failed

请尝试两件对我有效的事情。

要么添加:

jndiProperties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false"); 

删除那些3线:

jndiProperties.put("jboss.naming.client.ejb.context",true); 
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
jndiProperties.put(Context.PROVIDER_URL,"remote://localhost:4447"); 
+0

我的程序现在可以查找EJB并跳转到我的自定义登录模块。但是,即使我在jndi属性中设置了密码,密码也会返回随机值。 jndiProperties.put(Context.SECURITY_CREDENTIALS,“password”); 你有什么想法来解决这个问题吗? – PrimaryChicken 2014-12-23 03:19:45

+0

我不知道你有一个自定义登录模块。我认为这会带来另一个问题 - 你能否提出一个新问题? – zbig 2014-12-23 10:09:42