User: starksm 
  Date: 01/06/12 21:55:50

  Modified:    src/main/org/jboss/test/security/test
                        TestProjRepository.java
  Added:       src/main/org/jboss/test/security/test TestSecurityProxy.java
  Log:
  Initial tests of the custom security proxy layer
  
  Revision  Changes    Path
  1.2       +1 -1      
jbosstest/src/main/org/jboss/test/security/test/TestProjRepository.java
  
  Index: TestProjRepository.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/security/test/TestProjRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestProjRepository.java   2001/03/05 10:11:08     1.1
  +++ TestProjRepository.java   2001/06/13 04:55:50     1.2
  @@ -26,13 +26,13 @@
   or fail based on whether the user can do what they should be able
   to do and are stopped from not doing what they should not do. A failure
   of the test only occurs if a user sees a SecurityException when they
  -should not, or a user does not see a SecurityException when they do.
  +should not, or a user does not see a SecurityException when they should.
   This requires that this test module's accessTest ecpected values
   be kept in synch with the resources/security/sample_policy.xml that
   is deployed.
   
   @author [EMAIL PROTECTED]
  -@version $Revision: 1.1 $
  +@version $Revision: 1.2 $
   */
   public class TestProjRepository extends junit.framework.TestCase
   {
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/security/test/TestSecurityProxy.java
  
  Index: TestSecurityProxy.java
  ===================================================================
  package org.jboss.test.security.test;
  
  import java.io.IOException;
  import java.rmi.RemoteException;
  import javax.ejb.CreateException;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.rmi.PortableRemoteObject;
  import javax.security.auth.login.*;
  
  import org.jboss.test.security.interfaces.Entity;
  import org.jboss.test.security.interfaces.EntityHome;
  import org.jboss.test.security.interfaces.IOSession;
  import org.jboss.test.security.interfaces.IOSessionHome;
  
  /** Simple tests of security stateless, stateful and entity beans via custom
  security proxies.
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class TestSecurityProxy extends junit.framework.TestCase
  {
      static String username = "scott";
      static char[] password = "echoman".toCharArray();
  
      LoginContext lc;
      boolean loggedIn;
  
      public TestSecurityProxy(String name)
      {
          super(name);
      }
  
      protected void setUp() throws Exception
      {
          Deploy.deploy("security-proxy.jar");
      }
  
      public void testProxiedStatelessBean() throws Exception
      {
          login();
          InitialContext jndiContext = new InitialContext();
          Object obj = jndiContext.lookup("ProxiedStatelessBean");
          obj = PortableRemoteObject.narrow(obj, IOSessionHome.class);
          IOSessionHome home = (IOSessionHome) obj;
          System.out.println("Found ProxiedStatelessBean");
          IOSession bean = home.create();
          System.out.println("Created ProxiedStatelessBean");
          System.out.println("ProxiedStatelessBean.read() -> 
"+bean.read("/user/scott/.password"));
          bean.write("/user/scott/.password");
          System.out.println("ProxiedStatelessBean.write()");
          bean.remove();
          logout();
      }
  
      public void testProxiedStatefulBean() throws Exception
      {
          login();
          InitialContext jndiContext = new InitialContext();
          Object obj = jndiContext.lookup("ProxiedStatefulBean");
          obj = PortableRemoteObject.narrow(obj, IOSessionHome.class);
          IOSessionHome home = (IOSessionHome) obj;
          System.out.println("Found ProxiedStatefulBean");
          IOSession bean = home.create();
          System.out.println("Created ProxiedStatefulBean");
          System.out.println("ProxiedStatefulBean.read() -> 
"+bean.read("/user/scott/.password"));
          bean.write("/user/scott/.password");
          System.out.println("ProxiedStatefulBean.write()");
          bean.remove();
          logout();
      }
  
      /** Login as user scott using the conf.name login config or
          'spec-test' if conf.name is not defined.
       */
      private void login() throws Exception
      {
          login(username, password);
      }
      private void login(String username, char[] password) throws Exception
      {
          if( loggedIn )
              return;
  
          lc = null;
          String confName = System.getProperty("conf.name", "spec-test");
          AppCallbackHandler handler = new AppCallbackHandler(username, password);
          System.out.println("Creating LoginContext("+confName+")");
          lc = new LoginContext(confName, handler);
          lc.login();
          System.out.println("Created LoginContext, subject="+lc.getSubject());
          loggedIn = true;
      }
      private void logout() throws Exception
      {
          if( loggedIn )
          {
              loggedIn = false;
              lc.logout();
          }
      }
  }
  
  
  

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

Reply via email to