Search in sources :

Example 6 with EjbServer

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();
    }
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) JNDIContext(org.apache.openejb.client.JNDIContext) ServerFederation(org.apache.openejb.core.ServerFederation) Properties(java.util.Properties) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) InitialContext(javax.naming.InitialContext) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EjbServer(org.apache.openejb.server.ejbd.EjbServer) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) RemoteInitialContextFactory(org.apache.openejb.client.RemoteInitialContextFactory) LoginException(javax.security.auth.login.LoginException) Assembler(org.apache.openejb.assembler.classic.Assembler) EJBException(javax.ejb.EJBException) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Aggregations

EjbServer (org.apache.openejb.server.ejbd.EjbServer)6 Properties (java.util.Properties)5 ServerFederation (org.apache.openejb.core.ServerFederation)5 InitialContext (javax.naming.InitialContext)4 ServiceDaemon (org.apache.openejb.server.ServiceDaemon)4 Context (javax.naming.Context)3 Assembler (org.apache.openejb.assembler.classic.Assembler)3 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)3 EjbJar (org.apache.openejb.jee.EjbJar)3 StatelessBean (org.apache.openejb.jee.StatelessBean)3 JNDIContext (org.apache.openejb.client.JNDIContext)2 RemoteInitialContextFactory (org.apache.openejb.client.RemoteInitialContextFactory)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 EJBException (javax.ejb.EJBException)1 NamingException (javax.naming.NamingException)1 LoginException (javax.security.auth.login.LoginException)1 StandardServer (org.apache.catalina.core.StandardServer)1 Bootstrap (org.apache.catalina.startup.Bootstrap)1