1 2 Previous Next 16 Replies Latest reply on Jul 2, 2012 8:42 AM by Mats Lindström

    Embedded Glassfish and security issues

    Nick de Graeve Newbie

      I'm trying to test my EJB3 on an embedded Glassfish with Arquillian from Maven.

       

      I need to test security and I understand Arquillian doesn't provide a direct way to do that. But I found a discussion (http://community.jboss.org/message/580290) on how it can be done. I followed the instructions but I still got issues:

       

      1. my arquillian.xml isn't picked up;
      2. I got warnings about @Resource SessionContext;
      3. I can't get to the running server's instance; maybe as a result of the previous problems

       

      Any help is greatly appreciated.

       

      My EJB:

      @Stateless
      @Local(FileBrowser.class)
      public class FileBrowserBean implements FileBrowser {
      
          @Resource
          private SessionContext sessionContext;
      
          @Override
          public Set<Application> loadConfiguration() throws FileBrowserException {
              return ConfigurationHelper.loadConfiguration(this.sessionContext);
          }
      
      }
      

       

      My JUnit test:

      @RunWith(Arquillian.class)
      public class ArquillianTestCase {
      
          @Deployment
          public static JavaArchive createDeployment() {
              final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar")
                      .addClasses(FileBrowser.class, FileBrowserBean.class).addAsResource("META-INF/ejb-jar.xml")
                      .addAsResource("META-INF/glassfish-ejb-jar.xml");
              return jar;
          }
      
          @EJB
          private FileBrowser fileBrowser;
      
          @Test
          public void setupSecurity() throws Exception {
              GlassfishTestHelper.createFileUser("user1", "xxx", "role1");
          }
      
          @Test
          public void testLoadConfiguration() throws Exception {
              final boolean loggedIn = GlassfishTestHelper.loginFileUser("user1", "xxx");
              Assert.assertEquals(true, loggedIn);
              this.fileBrowser.loadConfiguration();
          }
      
      }
      

       

      GlassfishTestHelper.java:

      public final class GlassfishTestHelper {
      
          private GlassfishTestHelper() {}
      
          public static void createFileUser(final String username, final String password, final String groups) throws Exception {
              // get the running Arquillian embedded Glassfish server
              final Server server = Server.getServer(Server.getServerNames().get(0));
              final String command = "create-file-user";
              final ParameterMap params = new ParameterMap();
              params.add("userpassword", password);
              params.add("groups", groups);
              params.add("username", username);
              final CommandRunner runner = server.getHabitat().getComponent(CommandRunner.class);
              final ActionReport report = server.getHabitat().getComponent(ActionReport.class);
              runner.getCommandInvocation(command, report).parameters(params).execute();
      
              if (report.getMessage() != null) {
                  throw new Exception(String.format("Failed to create user : %s - message %s", username, report.getMessage()),
                          report.getFailureCause());
              }
          }
      
          public static boolean loginFileUser(final String username, final String password) throws Exception {
              final ProgrammaticLogin login = new ProgrammaticLogin();
              return login.login(username, password.toCharArray(), "fileRealm", true);
          }
      
      }
      

       

      My deployment descriptors with the security are located in src/test/resources/META-INF/.

      ejb-jar.xml:

      <javaee:ejb-jar version="3.0" 
                      xmlns:javaee="http://java.sun.com/xml/ns/javaee" 
                      xmlns:xml="http://www.w3.org/XML/1998/namespace" 
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd ">
      
          <javaee:enterprise-beans>
              <javaee:session>
                  <javaee:ejb-name>FileBrowser</javaee:ejb-name>
                  <javaee:ejb-class>com.jnj.gtsc.services.filebrowser.ejb.FileBrowserBean</javaee:ejb-class>
                  <javaee:session-type>Stateless</javaee:session-type>
                  <javaee:security-role-ref>
                      <javaee:role-name>role1</javaee:role-name>
                  </javaee:security-role-ref>
              </javaee:session>
          </javaee:enterprise-beans>
      
          <javaee:assembly-descriptor>
              <javaee:security-role>
                  <javaee:role-name>role1</javaee:role-name>
              </javaee:security-role>
          </javaee:assembly-descriptor>
      
      </javaee:ejb-jar>
      

       

      glassfish-ejb-jar.xml:

      <!DOCTYPE glassfish-ejb-jar PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 EJB 3.1//EN" "http://glassfish.org/dtds/glassfish-ejb-jar_3_1-1.dtd">
      <glassfish-ejb-jar>
          <security-role-mapping>
              <role-name>role1</role-name>
              <group-name>role1</group-name>
          </security-role-mapping>
      
          <enterprise-beans></enterprise-beans>
      
      </glassfish-ejb-jar>
      

       

      My arquillian.xml is located at src/test/resources and contains:

      <arquillian xmlns="http://jboss.com/arquillian"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:glassfish="urn:arq:org.jboss.arquillian.container.glassfish.embedded_3">
      
          <glassfish:container>
              <glassfish:bindHttpPort>9090</glassfish:bindHttpPort>
              <glassfish:instanceRoot>src/test/glassfish</glassfish:instanceRoot>
              <glassfish:autoDelete>true</glassfish:autoDelete>
          </glassfish:container>
      
      </arquillian>
      

       

      Relevant Maven dependencies:

       

      org.jboss.arquillian:arquillian-junit:1.0.0.Alpha5:test

      org.jboss.arquillian.container:arquillian-glassfish-embedded-3.1:1.0.0.Alpha5:test

      org.glassfish.extras:glassfish-embedded-all:3.1:test

       

       

      When I run my test I get this output:

       

      -------------------------------------------------------

      T E S T S

      -------------------------------------------------------

      Running com.jnj.gtsc.services.filebrowser.ArquillianTestCase

      19-Apr-2011 10:12:54 org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration

      INFO: Could not read active container configuration: null

      19-Apr-2011 10:12:55 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient

      INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.

      19-Apr-2011 10:12:55 org.hibernate.validator.util.Version <clinit>

      INFO: Hibernate Validator null

      19-Apr-2011 10:12:55 org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA

      INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.

      19-Apr-2011 10:12:56 com.sun.enterprise.v3.services.impl.GrizzlyService createNetworkProxy

      INFO: Network listener https-listener on port 0 disabled per domain.xml

      19-Apr-2011 10:12:56 com.sun.enterprise.v3.server.AppServerStartup run

      INFO: GlassFish Server Open Source Edition 3.1 (java_re-private) startup time : Embedded (1,014ms), startup services(699ms), total(1,713ms)

      19-Apr-2011 10:12:56 com.sun.enterprise.v3.services.impl.GrizzlyProxy$2$1 onReady

      INFO: Grizzly Framework 1.9.31 started in: 138ms - bound to [0.0.0.0:8181]

      19-Apr-2011 10:12:56 org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run

      INFO: JMXStartupService: JMXConnector system is disabled, skipping.

      19-Apr-2011 10:12:59 com.sun.enterprise.security.SecurityLifecycle <init>

      INFO: SEC1002: Security Manager is OFF.

      19-Apr-2011 10:12:59 com.sun.enterprise.security.SecurityLifecycle onInitialization

      INFO: SEC1010: Entering Security Startup Service

      19-Apr-2011 10:12:59 com.sun.enterprise.security.PolicyLoader loadPolicy

      INFO: SEC1143: Loading policy provider com.sun.enterprise.security.jacc.provider.SimplePolicyProvider.

      19-Apr-2011 10:12:59 com.sun.enterprise.security.auth.realm.Realm doInstantiate

      INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.

      19-Apr-2011 10:12:59 com.sun.enterprise.security.auth.realm.Realm doInstantiate

      INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.

      19-Apr-2011 10:12:59 com.sun.enterprise.security.auth.realm.Realm doInstantiate

      INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.

      19-Apr-2011 10:12:59 com.sun.enterprise.security.SecurityLifecycle onInitialization

      INFO: SEC1011: Security Service(s) Started Successfully

      19-Apr-2011 10:13:00 com.sun.enterprise.web.WebContainer createHttpListener

      INFO: WEB0169: Created HTTP listener [http-listener] on host/port [0.0.0.0:8181]

      19-Apr-2011 10:13:00 com.sun.enterprise.web.WebContainer createHosts

      INFO: WEB0171: Created virtual server [server]

      19-Apr-2011 10:13:00 com.sun.enterprise.web.WebContainer loadSystemDefaultWebModules

      INFO: WEB0172: Virtual server [server] loaded default web module []

      19-Apr-2011 10:13:02 org.glassfish.apf.impl.DefaultErrorHandler warning

       

      WARNING: Incorrect @Resource annotation class definition - missing lookup attribute

      symbol: FIELD

      location: private javax.ejb.SessionContext com.jnj.gtsc.services.filebrowser.ejb.FileBrowserBean.sessionContext

       

      19-Apr-2011 10:13:02 org.glassfish.apf.impl.DefaultErrorHandler warning

      WARNING: Incorrect @Resource annotation class definition - missing lookup attribute

      symbol: FIELD

      location: private javax.ejb.SessionContext com.jnj.gtsc.services.filebrowser.ejb.FileBrowserBean.sessionContext

       

       

      classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)

      SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@14e5d57

      19-Apr-2011 10:13:02 com.sun.ejb.containers.BaseContainer initializeHome

      INFO: Portable JNDI names for EJB FileBrowserBean : [java:global/test/FileBrowserBean!com.jnj.gtsc.services.filebrowser.ejb.FileBrowser, java:global/t

      est/FileBrowserBean]

      19-Apr-2011 10:13:02 com.sun.enterprise.web.WebApplication start

      INFO: WEB0671: Loading application [test] at [/test]

      19-Apr-2011 10:13:02 org.glassfish.deployment.admin.DeployCommand execute

      PlainTextActionReporterSUCCESSDescription: deploy AdminCommandApplication deployed with name test.

      INFO: test was successfully deployed in 4,856 milliseconds.

          [name=test

      19-Apr-2011 10:13:03 org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher injectClass

      INFO: BeanManager cannot be located at java:comp/BeanManager. Either you are using an archive with no beans.xml, or the BeanManager has not been bound

      to that location in JNDI.

      19-Apr-2011 10:13:03 org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher injectClass

      INFO: BeanManager cannot be located at java:comp/BeanManager. Either you are using an archive with no beans.xml, or the BeanManager has not been bound

      to that location in JNDI.

      19-Apr-2011 10:13:03 com.sun.appserv.security.ProgrammaticLogin login

      SEVERE: SEC9050: Programmatic login failed

      com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Unable to locate a login configuration

              at com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver.java:394)

              at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:240)

              at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:153)

              at com.sun.appserv.security.ProgrammaticLogin$1.run(ProgrammaticLogin.java:174)

              at java.security.AccessController.doPrivileged(Native Method)

              at com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:168)

              at com.jnj.gtsc.services.filebrowser.util.GlassfishTestHelper.loginFileUser(GlassfishTestHelper.java:67)

              at com.jnj.gtsc.services.filebrowser.ArquillianTestCase.testLoadConfiguration(ArquillianTestCase.java:71)

             [...]

      Caused by: java.lang.SecurityException: Unable to locate a login configuration

              at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:93)

                     [...]

      Caused by: java.io.IOException: Unable to locate a login configuration

              at com.sun.security.auth.login.ConfigFile.init(ConfigFile.java:250)

              at com.sun.security.auth.login.ConfigFile.<init>(ConfigFile.java:91)

              ... 122 more

      classLoader = WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)

      SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@14e5d57

      PlainTextActionReporterSUCCESSNo monitoring data to report.

      Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 9.612 sec <<< FAILURE!

       

      Results :

       

      Tests in error:

        setupSecurity(com.jnj.gtsc.services.filebrowser.ArquillianTestCase)

        testLoadConfiguration(com.jnj.gtsc.services.filebrowser.ArquillianTestCase)

       

      Tests run: 2, Failures: 0, Errors: 2, Skipped: 0

       

      The Maven Surefire report:

       

      -------------------------------------------------------------------------------

      Test set: com.jnj.gtsc.services.filebrowser.ArquillianTestCase

      -------------------------------------------------------------------------------

      Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 6.581 sec <<< FAILURE!

      setupSecurity(com.jnj.gtsc.services.filebrowser.ArquillianTestCase)  Time elapsed: 0.265 sec  <<< ERROR!

      java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

          at java.util.ArrayList.RangeCheck(ArrayList.java:547)

          at java.util.ArrayList.get(ArrayList.java:322)

          at com.jnj.gtsc.services.filebrowser.util.GlassfishTestHelper.createFileUser(GlassfishTestHelper.java:38)

          at com.jnj.gtsc.services.filebrowser.ArquillianTestCase.setupSecurity(ArquillianTestCase.java:65)

         [...]

       

      testLoadConfiguration(com.jnj.gtsc.services.filebrowser.ArquillianTestCase)  Time elapsed: 0.18 sec  <<< ERROR!

      com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Unable to locate a login configuration

          at com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver.java:394)

          at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:240)

          at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:153)

          at com.sun.appserv.security.ProgrammaticLogin$1.run(ProgrammaticLogin.java:174)

          at java.security.AccessController.doPrivileged(Native Method)

          at com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:168)

          at com.jnj.gtsc.services.filebrowser.util.GlassfishTestHelper.loginFileUser(GlassfishTestHelper.java:67)

          at com.jnj.gtsc.services.filebrowser.ArquillianTestCase.testLoadConfiguration(ArquillianTestCase.java:70)

          [...]

        • 1. Embedded Glassfish and security issues
          Aslak Knutsen Master

          The configuration XML has changed a bit in Alpha5, look at this example: https://gist.github.com/883946

           

          And you probably want to use addAsManifestResource("META-INF/...") so they end up in META-INF in your deployment

           

           

          Not sure why it would complain about the @Resource annotaiton tho.

          1 of 1 people found this helpful
          • 2. Embedded Glassfish and security issues
            Nick de Graeve Newbie

            I changed arquilian.xml to

             

            <arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

            xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian-1.0.xsd">

             

                <container qualifier="glassfish" default="true">

                </container>

            </arquillian>

             

            I'll use the defaults, so this should be the minimal. Correct?

             

            I also updated my test to use addAsManifestResource().

             

            Everything's the same though:

             

            19-Apr-2011 13:02:49 org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration

            INFO: Could not read active container configuration: null

            [...]

            19-Apr-2011 13:02:54 org.glassfish.apf.impl.DefaultErrorHandler warning

            WARNING: Incorrect @Resource annotation class definition - missing lookup attribute

            symbol: FIELD

            location: private javax.ejb.SessionContext com.jnj.gtsc.services.filebrowser.ejb.FileBrowserBean.sessionContext

            [...]

             

            I'll try with Alpha4.SP1...

            • 3. Embedded Glassfish and security issues
              Aslak Knutsen Master

              If you use only defaults, you don't need the arquillian.xml file at all.

               

              And don't use the Alpha4.SPX releases, they are internal to the OSGi team. Alpha4 won't work with GlassFish 3.1.

               

              The @Resource warning your getting, is probably due to some classpath issues. You have a @Resource annotation included on your appclasspath from a previous version it seems. It complains it can't find @Resource.lookup.

              1 of 1 people found this helpful
              • 4. Embedded Glassfish and security issues
                Nick de Graeve Newbie

                WIth the Alpha4.SP1 I got a lot further though. The arquillian.xml got picked up, no @Resource errors and I could add users to the realm and login. It didn't recignize my rolemapping though. But I'll abandon that quest and I'll try getting Alpha 5 to work.

                 

                Just to be sure, which dependencies and versions do I need? I now got

                 

                org.jboss.arquillian:arquillian-junit:1.0.0.Aplha5:provided and

                org.glassfish.extras:glassfish-embedded-all:3.1.1-b01:provided

                 

                I had javax:javaee-api:6.0:provided but I removed it and set the arquillian and glassfish deps from test to provided.

                 

                The result is the same, though: the @Resource issue and can't lookup the server.

                 

                If I check in Eclipse, @Resource indeed doesn't have a "lookup" attribute. Where do I get the correct one?

                • 5. Embedded Glassfish and security issues
                  Aslak Knutsen Master

                  The correct one should be pulled in via the glassfish-embedded-all dep ?

                  • 6. Re: Embedded Glassfish and security issues
                    Nick de Graeve Newbie

                    Ok, progress.

                     

                    1. the issue of @Resource: the problem was that Glassfish used the @Resource from the JDK which doesn't have the " lookup" attribute. Setting the java.endorsed.dirs for compiler and Surefire to a copied dependecy fixed it.

                     

                    2. it still won't work though. See Surefire report below.

                     

                    I attached a project that illustrates what I want to achieve and that doesn't work.

                     

                    -------------------------------------------------------------------------------

                    Test set: test.ejb.TestCase

                    -------------------------------------------------------------------------------

                    Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 5.988 sec <<< FAILURE!

                    setupSecurity(test.ejb.TestCase)  Time elapsed: 0.016 sec  <<< ERROR!

                    java.lang.IllegalArgumentException: ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.

                        at org.jboss.arquillian.protocol.servlet.ServletUtil.determineBaseURI(ServletUtil.java:63)

                        at org.jboss.arquillian.protocol.servlet.BaseServletProtocol.getExecutor(BaseServletProtocol.java:56)

                        at org.jboss.arquillian.protocol.servlet.BaseServletProtocol.getExecutor(BaseServletProtocol.java:30)

                        at org.jboss.arquillian.impl.execution.RemoteTestExecuter.getContainerMethodExecutor(RemoteTestExecuter.java:105)

                        at org.jboss.arquillian.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:96)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)

                        at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)

                        at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:106)

                        at org.jboss.arquillian.impl.core.EventImpl.fire(EventImpl.java:67)

                        at org.jboss.arquillian.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:65)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)

                        at org.jboss.arquillian.impl.client.ContainerDeploymentContextHandler.createContext(ContainerDeploymentContextHandler.java:133)

                        at org.jboss.arquillian.impl.client.ContainerDeploymentContextHandler.createTestContext(ContainerDeploymentContextHandler.java:120)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.TestContextHandler.createTestContext(TestContextHandler.java:82)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.TestContextHandler.createClassContext(TestContextHandler.java:68)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:54)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)

                        at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:101)

                        at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:251)

                        at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:214)

                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)

                        at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)

                        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:228)

                        at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

                        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

                        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

                        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

                        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

                        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

                        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:173)

                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)

                        at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)

                        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:187)

                        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

                        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)

                        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)

                        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:119)

                        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:101)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)

                        at $Proxy0.invoke(Unknown Source)

                        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)

                        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)

                        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

                     

                    testUserHasRole(test.ejb.TestCase)  Time elapsed: 0.003 sec  <<< ERROR!

                    java.lang.IllegalArgumentException: ArquillianServletRunner not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.

                        at org.jboss.arquillian.protocol.servlet.ServletUtil.determineBaseURI(ServletUtil.java:63)

                        at org.jboss.arquillian.protocol.servlet.BaseServletProtocol.getExecutor(BaseServletProtocol.java:56)

                        at org.jboss.arquillian.protocol.servlet.BaseServletProtocol.getExecutor(BaseServletProtocol.java:30)

                        at org.jboss.arquillian.impl.execution.RemoteTestExecuter.getContainerMethodExecutor(RemoteTestExecuter.java:105)

                        at org.jboss.arquillian.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:96)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)

                        at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)

                        at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:106)

                        at org.jboss.arquillian.impl.core.EventImpl.fire(EventImpl.java:67)

                        at org.jboss.arquillian.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:65)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)

                        at org.jboss.arquillian.impl.client.ContainerDeploymentContextHandler.createContext(ContainerDeploymentContextHandler.java:133)

                        at org.jboss.arquillian.impl.client.ContainerDeploymentContextHandler.createTestContext(ContainerDeploymentContextHandler.java:120)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.TestContextHandler.createTestContext(TestContextHandler.java:82)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.TestContextHandler.createClassContext(TestContextHandler.java:68)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:54)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)

                        at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)

                        at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)

                        at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:101)

                        at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:251)

                        at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:214)

                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)

                        at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)

                        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:228)

                        at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)

                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)

                        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)

                        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

                        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

                        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

                        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

                        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

                        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:173)

                        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)

                        at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)

                        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:187)

                        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

                        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)

                        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)

                        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:119)

                        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:101)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                        at java.lang.reflect.Method.invoke(Method.java:597)

                        at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)

                        at $Proxy0.invoke(Unknown Source)

                        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)

                        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)

                        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

                    • 7. Re: Embedded Glassfish and security issues
                      Aslak Knutsen Master

                      Could you try glassfish-embedded-all:3.1, I havn't verified 3.1.1 yet, might be some changes.

                      • 8. Re: Embedded Glassfish and security issues
                        Nick de Graeve Newbie

                        Ok, with glassfish-embedded-all:3.1 I'm getting further: the tests run; they still fail though.

                         

                        The problem seems that I can't get hold of the running server's instance: final Server server = Server.getServer(Server.getServerNames().get(0)) throws an ArrayIndexOutOfBoundException.

                         

                        I attached the updated project as well as the full Maven and Surefire logs.

                         

                        Any more ideas?

                        • 9. Embedded Glassfish and security issues
                          Nick de Graeve Newbie

                          Can anybody reproduce my results?

                          • 10. Embedded Glassfish and security issues
                            Magnus Smith Newbie

                            Regarding the problem with getting hold of the running embedded glassfish server instance.

                             

                            The embedded api is no longer available in embedded glassfish 3.1.  They are now using org.glassfish.embeddable which has the new simplified CommandRunner that you use like this

                             

                            CommandRunner runner = glassfish.getCommandRunner();

                            CommandResult result = runner.run("create-file-user", "userpassword" , userPassword, "groups", userGroups, "username", username);

                             

                            The problem is though that there is no way to get the currenlty running glassfish they only offer the following to start a new instance

                             

                            GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(...)

                             

                            I tried to file an issue here but it seems very quiet.

                             

                            But if you use glassfish 3.1-b09 (This has the embedded api) with Arquillian 1.00.Alpha4 then it should work ok.

                            • 11. Re: Embedded Glassfish and security issues
                              Magnus Smith Newbie

                              I've found another approach to creating your users that works with glassfish 3.1 and Arquillian 1.00.Alpha5

                               

                              If you have a normal glassfish 3.1 server then you can add users and roles to the file realm in the glassfish administrator web interface under

                              Configurations -> Security -> Realms -> file  where you have an option to mangae users.

                               

                              Then if you add the instanceRoot property to arquillian.xml

                               

                              <container qualifier="glassfish" default="true">

                                      <configuration>

                                   .......

                                        <property name="instanceRoot">glassfish server domain file path</property>

                                    </configuration>

                              </container>

                               

                              You can now use the programmatic login

                               

                              public static boolean loginFileUser(String userName, String userPassword) throws Exception {

                                      ProgrammaticLogin pgLogin = new ProgrammaticLogin();

                                      return pgLogin.login(userName, userPassword.toCharArray(), "fileRealm", true);

                                  }

                               

                              This should allow you to test a secure ejb application with arquillian which is pretty cool

                              • 12. Re: Embedded Glassfish and security issues
                                Michael Grom Newbie

                                Hi Magnus!

                                Can you give me your configuration? I'm struggling with embedded glassfish / arquillian and the GlassFishTestHelper class doesn't work for me (Server Name's list is empty). However, pointing arquillian to the local domain.xml causes a GlassFishException complaining about "No configuration found for server.network-config.network-listeners.network-listener.http-listener"

                                 

                                Anyway, shouldn't arquillian be able to return a reference to the Server Instance started? One could then use the CommandRunner from there.

                                 

                                Kind regards

                                Michael

                                • 13. Re: Embedded Glassfish and security issues
                                  Magnus Smith Newbie

                                  Using the approach for Arquillian 1.00.Alpha5 with Glassfish 3.1

                                   

                                  As discussed earlier you can no longer create users in the file realm programatically with the GlassFishTestHelper as the api changed in later builds of GlassFish 3.0 with the method to get a reference to a started instance now removed.

                                   

                                  What we can do though is to create the users outside of embedded glassfish and point embedded glassfish instance to the file realm so that we can login test users.

                                   

                                  To do this we need to have Glassfish 3.1 server installed. once this is done create the users in the file realm

                                   

                                  editRealm1.png

                                   

                                  Notice that the JASS context must match the one in GlassFishTestHelper.

                                   

                                  Now go to manage users and create the users that you want to use in your tests

                                   

                                  editRealm2.png

                                   

                                  Once we have the fileRealm created with the desired users in the GlassFish fileRealm then in arquillian.xml we need to point arquillian to use the

                                  instance root of the GlassFish server.

                                   

                                  Below I've used maven parameters for the configuration properties

                                   

                                   

                                  {code:xml}

                                  <arquillian.configuration.xml>file:///C:/workspace/ccms/ccms-test/ccms-test-ejb/src/test/resources/domain-31.xml</arquillian.configuration.xml>

                                  <arquillian.instance-root>C:/glassfish-3.1-b41/glassfish-3.1-b41/glassfish/domains/domain1</arquillian.instance-root>

                                  <arquillian.bind-http-port>7070</arquillian.bind-http-port>

                                  {code}

                                   

                                  and then set

                                   

                                  {code:xml}

                                  <testResource>

                                      <directory>src/test/resources</directory>

                                      <filtering>true</filtering>

                                  </testResource>

                                  {code}

                                   

                                   

                                  Its worth noting that the configuration xml is referenced via a uri and the instance-root is simply a file path.

                                   

                                   

                                  {code:xml}

                                  <?xml version="1.0" encoding="UTF-8"?>

                                  <arquillian

                                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                                      xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian-1.0.xsd">

                                   

                                      <engine>

                                           <!-- test archives exported to the file system for inspection -->

                                          <property name="deploymentExportPath">C:\\tmp</property>

                                      </engine>

                                   

                                      <container qualifier="glassfish" default="true">

                                          <configuration>

                                              <property name="configurationXml">${arquillian.configuration.xml}</property>

                                              <property name="bindHttpPort">${arquillian.bind-http-port}</property>

                                              <property name="instanceRoot">${arquillian.instance-root}</property>

                                          </configuration>

                                      </container>

                                  </arquillian>

                                  {code}

                                   

                                   

                                  I've included my domain.xml as an attachment.

                                   

                                  I came across a bug in arquillian that means that in domain.xml I needed to rename http-listener-1 to http-listener to keep arquillian happy

                                   

                                   

                                  The GlassFishTestHelper now becomes

                                   

                                   

                                  {code:java}

                                  /**

                                  * Helper class to login file users to GlassFish.

                                  * The users must already exist in the GlassFish 'fileRealm'

                                  *

                                  * @author Magnus.Smith

                                  */

                                  public class GlassFishTestHelper {

                                   

                                     /**

                                       * Login a user to the GlassFish file realm. 

                                       * @param username

                                       * @param password

                                       * @return true for successful login otherwise false

                                       */

                                      public static boolean loginFileUser(String username, String password) throws Exception {

                                          ProgrammaticLogin pgLogin = new ProgrammaticLogin();

                                          return pgLogin.login(username, password.toCharArray(), "fileRealm", true);

                                      }

                                  }

                                  {code}

                                   

                                   

                                  You should now be able to login your users in tests like this

                                   

                                   

                                  {code:java}

                                  assertEquals(GlassFishTestHelper.loginFileUser("toy", "toy"),

                                                  true, "Failed to login 'toy'!");

                                  {code}

                                  • 14. Re: Embedded Glassfish and security issues
                                    Michael Grom Newbie

                                    Hi Magnus!

                                     

                                    thank you very much for the detailed example. I'll give it a try. My local Glassfish is a release 3.1, not a b41. Hope this doesn't make too much of a difference!

                                     

                                    Thanks again!

                                     

                                    Michael

                                    1 2 Previous Next