1

乡亲

我在 Netbeans 中设置了 OpenEJB,以便我们可以使用 Embedded 配置运行和调试它。在我们尝试添加身份验证之前,它运行良好。

当我们将它作为独立服务器运行时,我们可以编辑安全用户和组列表并且它可以工作:

${openejb.base}/conf/login.config
${openejb.base}/conf/users.properties
${openejb.base}/conf/groups.properties

但是,当使用 OpenEJB 嵌入式配置(Netbeans 项目)时,我们找不到指定这 3 个文件的方法。OpenEJB 似乎在放置它们的任何地方都看不到它们。方法调用总是失败:

*javax.security.auth.login.FailedLoginException: User does not exist*

有谁知道如何指定 OpenEJB 在嵌入式模式下运行时应该使用哪些用户和组?

这是Netbeans项目结构

projectName/src - 所有源文件 projectName/lib - jars:数据库驱动程序,所有 OpenEJB 库 projectName/lib/conf - 安全文件

谢谢,

路易斯

4

1 回答 1

1

您应该使用 LocalInitialContext 属性来告诉 OpenEJB 配置文件在哪里。在我们的设置中,我们将 ant 脚本配置为在编译项目后将以下文件复制到 projectName/build:

conf/users.properties
conf/openejb.xml
conf/logs
conf/logs/logs.txt
conf/groups.properties

然后你必须告诉 OpenEJB 在哪里可以找到它们:

Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");

//Here are the important properties that you were missing
properties.setProperty("openejb.home", "../build");
properties.setProperty("openejb.configuration", "conf/openejb.xml");

//User and password for tests
properties.put(Context.SECURITY_PRINCIPAL, "userName");
properties.put(Context.SECURITY_CREDENTIALS, "thePassword");

InitialContext initialContext = new InitialContext(properties);

EJBRemote ejb = (EJBRemote) initialContext.lookup("EJBRemote");

现在您可以在 NetBeans、Eclipse 或任何 IDE 中运行 OpenEJB。此外,您也可以使用 ant 脚本从命令行运行所有单元测试。

于 2011-02-03T12:50:52.917 回答