User: starksm 
  Date: 02/02/25 00:11:21

  Added:       src/main/org/jboss/test/securitymgr/test
                        EJBSpecUnitTestCase.java
  Log:
  Unit tests for running JBoss under a security manager
  
  Revision  Changes    Path
  1.1                  
jbosstest/src/main/org/jboss/test/securitymgr/test/EJBSpecUnitTestCase.java
  
  Index: EJBSpecUnitTestCase.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.test.securitymgr.test;
  
  import java.io.IOException;
  import java.rmi.RemoteException;
  import javax.ejb.CreateException;
  import javax.management.ObjectName;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  
  import org.jboss.test.securitymgr.interfaces.IOSession;
  import org.jboss.test.securitymgr.interfaces.IOSessionHome;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.jboss.test.JBossTestCase;
  import org.jboss.test.JBossTestSetup;
  
  /** Tests of the programming restrictions defined by the EJB spec. The JBoss
  server must be running under a security manager. The securitymgr-ejb.jar
  should be granted only the following permission:
  
  grant securitymgr-ejb.jar {
     permission java.util.PropertyPermission "*", "read";
     permission java.lang.RuntimePermission "queuePrintJob";
     permission java.net.SocketPermission "*", "connect";
   };
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
   */
  public class EJBSpecUnitTestCase
     extends JBossTestCase
  {
     org.apache.log4j.Category log = getLog();
  
     public EJBSpecUnitTestCase(String name)
     {
        super(name);
     }
  
     /** Test that a bean cannot access the filesystem using java.io.File
      */
     public void testFileIO() throws Exception
     {
        log.debug("+++ testFileIO()");
        Object obj = getInitialContext().lookup("secmgr.IOSessionHome");
        IOSessionHome home = (IOSessionHome) obj;
        log.debug("Found secmgr.IOSessionHome");
        IOSession bean = home.create();
        log.debug("Created IOSession");
  
        try
        {
           // This should fail because the bean calls File.exists()
           bean.read("nofile.txt");
           fail("Was able to call IOSession.read");
        }
        catch(RemoteException e)
        {
           log.debug("IOSession.read failed as expected");
        }
  
        try
        {
           // This should fail because the bean calls File.exists()
           bean.write("nofile.txt");
           fail("Was able to call IOSession.write");
        }
        catch(RemoteException e)
        {
           log.debug("IOSession.read failed as expected");
        }
        bean.remove();
     }
  
     /**
      * Setup the test suite.
      */
     public static Test suite() throws Exception
     {
        return getDeploySetup(EJBSpecUnitTestCase.class, "securitymgr-ejb.jar");
     }
  
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to