开发者

How to specify UsersFile, GroupsFile and conf/login.config in OpenEJB Embedded configuration?

Folks

I've setup OpenEJB in Netbeans so that we can run it and debug it using the Embedded configuration. It worked fine until we tried to add authentication.

When we run it as a standalone server, we can edit the security users and groups lists and it works:

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

However, we couldn't find a way to specify those 3 files when using the OpenEJB embedded configuration (a Netbeans project). It seems that OpenEJB doesn't see them wherever they are placed. The method calls always fail with:

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

Does anybody know how to specify what users and groups OpenEJB should use when running in embedded mode?

Here is the N开发者_如何学Goetbeans project structure

projectName/src - all source files projectName/lib - jars: database driver, all OpenEJB libraries projectName/lib/conf - security files

Thanks,

Luís


You should use LocalInitialContext properties to tell OpenEJB where the configuration files are. In our setup we configured the ant script to copy the following files to projectName/build after compiling the project:

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

Then you have to tell OpenEJB where to find them:

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

Now you can run OpenEJB inside NetBeans, Eclipse or any IDE. Additionally, you can use the ant script to run all unit tests from the command line, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜