final EjbServer ejbServer = new EjbServer();
OpenEJB.init(new PropertiesBuilder().p(DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY, "false").build(), new ServerFederation());
ejbServer.init(new Properties());
final ServiceDaemon serviceDaemon = new ServiceDaemon(ejbServer, 0, "localhost");
serviceDaemon.start();
final int port = serviceDaemon.getPort();
final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
final ConfigurationFactory config = new ConfigurationFactory();
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(RemoteWithSecurity.class));
assembler.createApplication(config.configureApplication(ejbJar));
try {
final Context context = new InitialContext(new PropertiesBuilder()
.p(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName())
.p(Context.PROVIDER_URL, "ejbd://127.0.0.1:" + port)
.p(JNDIContext.AUTHENTICATE_WITH_THE_REQUEST, "true")
.p("java.naming.security.principal", "foo")
.p("java.naming.security.credentials", "bar")
.p("openejb.authentication.realmName", "LM")
.build());
final AnInterfaceRemote client = AnInterfaceRemote.class.cast(context.lookup("RemoteWithSecurityRemote"));
assertNotNull(client);
assertEquals("foo", client.call());
} finally {
serviceDaemon.stop();
OpenEJB.destroy();
}
}