User: starksm 
  Date: 01/09/08 22:50:37

  Modified:    src/main/org/jboss/test/security/test Tag: Branch_2_4
                        TestEJBSpec.java
  Log:
  Add test of handle security
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.6.2.5   +51 -5     jbosstest/src/main/org/jboss/test/security/test/TestEJBSpec.java
  
  Index: TestEJBSpec.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/security/test/TestEJBSpec.java,v
  retrieving revision 1.6.2.4
  retrieving revision 1.6.2.5
  diff -u -r1.6.2.4 -r1.6.2.5
  --- TestEJBSpec.java  2001/07/29 16:32:43     1.6.2.4
  +++ TestEJBSpec.java  2001/09/09 05:50:37     1.6.2.5
  @@ -4,6 +4,7 @@
   import java.net.InetAddress;
   import java.rmi.RemoteException;
   import javax.ejb.CreateException;
  +import javax.ejb.Handle;
   import javax.management.ObjectName;
   import javax.naming.InitialContext;
   import javax.naming.NamingException;
  @@ -34,7 +35,7 @@
    deployment unit. These test the basic role based access model.
    
    @author [EMAIL PROTECTED]
  - @version $Revision: 1.6.2.4 $
  + @version $Revision: 1.6.2.5 $
    */
   public class TestEJBSpec
      extends TestCase
  @@ -243,7 +244,10 @@
         }
         bean.remove();
      }
  -   
  +
  +   /** Test that an MDB with a run-as identity is able to access secure EJBs
  +    that require the identity.
  +    */
      public void testMDBRunAs() throws Exception
      {
         System.out.println("+++ testMDBRunAs");
  @@ -267,6 +271,50 @@
         queueConn.close();
      }
   
  +   /** Test the security behavior of handles. To obtain secured bean from
  +      a handle that the handle be 
  +    */
  +   public void testHandle() throws Exception
  +   {
  +      System.out.println("+++ testHandle");
  +      login();
  +      InitialContext jndiContext = new InitialContext();
  +      Object obj = jndiContext.lookup("spec.StatelessSession");
  +      obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class);
  +      StatelessSessionHome home = (StatelessSessionHome) obj;
  +      System.out.println("Found StatelessSessionHome");
  +      StatelessSession bean = home.create();
  +      System.out.println("Created spec.StatelessSession");
  +      Handle h = bean.getHandle();
  +      System.out.println("Obtained handle: "+h);
  +      bean = (StatelessSession) h.getEJBObject();
  +      System.out.println("Obtained bean from handle: "+bean);
  +      System.out.println("Bean.echo('Hello') -> "+bean.echo("Hello"));
  +      logout();
  +
  +      /* Attempting to obtain the EJB fron the handle without security
  +       association present should fail
  +      */
  +      try
  +      {
  +         bean = (StatelessSession) h.getEJBObject();
  +         fail("Should not be able to obtain a bean without login info");
  +      }
  +      catch(Exception e)
  +      {
  +         System.out.println("Obtaining bean from handle failed as expected, 
e="+e.getMessage());
  +      }
  +
  +      // One should be able to obtain a handle without a login
  +      h = bean.getHandle();
  +      login();
  +      // Now we should be able to obtain and use the secure bean
  +      bean = (StatelessSession) h.getEJBObject();
  +      System.out.println("Obtained bean from handle: "+bean);
  +      System.out.println("Bean.echo('Hello') -> "+bean.echo("Hello"));
  +      logout();
  +   }
  +
      /** Login as user scott using the conf.name login config or
       'spec-test' if conf.name is not defined.
       */
  @@ -306,9 +354,7 @@
         // Ask the deployer for the getWarDeployerName
         Object[] params = {"other"};
         String[] signature = {"java.lang.String"};
  -      String warDeployerName = (String) server.invoke(jaasMgr,
  -         "flushAuthenticationCache", params, signature);
  -
  +      server.invoke(jaasMgr, "flushAuthenticationCache", params, signature);
      }
   
      /**
  
  
  

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

Reply via email to