use of org.apache.openejb.server.ejbd.EjbServer in project tomee by apache.
the class AuthentWithRequestTest method invoke.
@Test
public void invoke() throws Exception {
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 {
{
// ok case
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());
}
{
// now the failing case
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", "wrong").p("java.naming.security.credentials", "wrong").p("openejb.authentication.realmName", "LM").build());
final AnInterfaceRemote client = AnInterfaceRemote.class.cast(context.lookup("RemoteWithSecurityRemote"));
try {
client.call();
} catch (final EJBException e) {
if (!LoginException.class.isInstance(e.getCause())) {
e.printStackTrace();
}
assertTrue(LoginException.class.isInstance(e.getCause()));
}
}
} finally {
serviceDaemon.stop();
OpenEJB.destroy();
}
}
Aggregations