民间
我在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 - 安全文件
谢谢,
路易斯
答案 0 :(得分: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脚本从命令行运行所有单元测试。