Set user credentials for test methods in junit test using OpenEJB @ApplicationComposer

When I set up a test using @ApplicationComposer, it does not create a SessionContext inside my enterprise beans with the appropriate properties. It always uses PropertiesLogin no matter what I entered into the configuration.

I always get

javax.ejb.EJBException: User not found for login guest 

Exception Here is my junit test class and bean example.

 @RunWith(ApplicationComposer.class) public class OpenEJBTest { @EJB UserUtil uu; @Configuration public Properties properties() { Properties p=new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory"); p.put(Context.SECURITY_PRINCIPAL, "test"); p.put(Context.SECURITY_CREDENTIALS, "test"); p.put("openejb.authentication.realmName", "mylogmodule"); return p; } @Test public void testSth() { uu.getUserlogin(); } 

}

 @Stateless public class UserUtilBean implements UserUtil { @Resource private SessionContext ctx; public String getUserLogin() { return ctx.getCallerPrincipal().getName(); } } 

I tried using a custom LogModule (mylogmodule defined in login.config), the default module (PropertiesLogin), starting InitialContext using the properties inside the testing method, but to no avail. Thanks for any suggestions.

+4
source share
1 answer

Check this box to configure user login configuration and

open ejb security this may help

0
source

Source: https://habr.com/ru/post/1416693/


All Articles