User: stark   
  Date: 01/03/05 02:11:00

  Added:       src/main/org/jboss/test/security/ejb EntityBeanImpl.java
                        StatelessSessionBean.java
                        StatelessSessionBean2.java
  Log:
  Tests of the JBossSX security framework
  
  Revision  Changes    Path
  1.1                  
jbosstest/src/main/org/jboss/test/security/ejb/EntityBeanImpl.java
  
  Index: EntityBeanImpl.java
  ===================================================================
  package org.jboss.test.security.ejb;
  
  import java.rmi.RemoteException;
  import java.security.Principal;
  import javax.ejb.*;
  
  /** A BMP entity bean that creates beans on the fly with
  a key equal to that passed to findByPrimaryKey. Obviously
  not a real entity bean. It is used to test Principal propagation
  using the echo method. 
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class EntityBeanImpl implements EntityBean
  {
      private String key;
      private EntityContext context;
  
      public void ejbActivate()
      {
          System.out.println("EntityBean.ejbActivate() called");
      }
  
      public void ejbPassivate()
      {
          System.out.println("EntityBean.ejbPassivate() called");
      }
  
      public void ejbRemove()
      {
          System.out.println("EntityBean.ejbRemove() called");
      }
      public void ejbLoad()
      {
          System.out.println("EntityBean.ejbLoad() called");
          key = (String) context.getPrimaryKey();
      }
      public void ejbStore()
      {
          System.out.println("EntityBean.ejbStore() called");
      }
  
      public void setEntityContext(EntityContext context)
      {
          this.context = context;
      }
      public void unsetEntityContext()
      {
          this.context = null;
      }
  
      public String echo(String arg)
      {
          System.out.println("EntityBean.echo, arg="+arg);
          Principal p = context.getCallerPrincipal();
          System.out.println("EntityBean.echo, callerPrincipal="+p);
          return p.getName();
      }
  
      public String ejbFindByPrimaryKey(String key)
      {
          System.out.println("EntityBean.ejbFindByPrimaryKey, key="+key);
          return key;
      }
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/security/ejb/StatelessSessionBean.java
  
  Index: StatelessSessionBean.java
  ===================================================================
  package org.jboss.test.security.ejb;
  
  import java.rmi.RemoteException;
  import java.security.Principal;
  import javax.ejb.*;
  
  public class StatelessSessionBean implements SessionBean
  {
      private SessionContext sessionContext;
  
      public void ejbCreate() throws RemoteException, CreateException
      {
          System.out.println("StatelessSessionBean.ejbCreate() called");
      }
  
      public void ejbActivate() throws RemoteException
      {
          System.out.println("StatelessSessionBean.ejbActivate() called");
      }
  
      public void ejbPassivate() throws RemoteException
      {
          System.out.println("StatelessSessionBean.ejbPassivate() called");
      }
  
      public void ejbRemove() throws RemoteException
      {
          System.out.println("StatelessSessionBean.ejbRemove() called");
      }
  
      public void setSessionContext(SessionContext context) throws RemoteException
      {
          sessionContext = context;
      }
  
      public String echo(String arg)
      {
          System.out.println("StatelessSessionBean.echo, arg="+arg);
          Principal p = sessionContext.getCallerPrincipal();
          System.out.println("StatelessSessionBean.echo, callerPrincipal="+p);
          return arg;
      }
      public void noop()
      {
          System.out.println("StatelessSessionBean.noop");
      }
      public void npeError()
      {
          System.out.println("StatelessSessionBean.npeError");
          Object obj = null;
          obj.toString();
      }
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/security/ejb/StatelessSessionBean2.java
  
  Index: StatelessSessionBean2.java
  ===================================================================
  package org.jboss.test.security.ejb;
  
  import java.rmi.RemoteException;
  import java.security.Principal;
  import javax.ejb.*;
  import javax.naming.InitialContext;
  
  import org.jboss.test.security.interfaces.Entity;
  import org.jboss.test.security.interfaces.EntityHome;
  
  /** A SessionBean that access the Entity bean to test Principal
  identity propagation.
  
  @author [EMAIL PROTECTED]
  @version $Revision: 1.1 $
  */
  public class StatelessSessionBean2 implements SessionBean
  {
      private SessionContext sessionContext;
  
      public void ejbCreate() throws RemoteException, CreateException
      {
          System.out.println("StatelessSessionBean2.ejbCreate() called");
      }
  
      public void ejbActivate() throws RemoteException
      {
          System.out.println("StatelessSessionBean2.ejbActivate() called");
      }
  
      public void ejbPassivate() throws RemoteException
      {
          System.out.println("StatelessSessionBean2.ejbPassivate() called");
      }
  
      public void ejbRemove() throws RemoteException
      {
          System.out.println("StatelessSessionBean2.ejbRemove() called");
      }
  
      public void setSessionContext(SessionContext context) throws RemoteException
      {
          sessionContext = context;
      }
  
      public String echo(String arg)
      {
          System.out.println("StatelessSessionBean2.echo, arg="+arg);
          // This call should fail if the bean is not secured
          Principal p = sessionContext.getCallerPrincipal();
          System.out.println("StatelessSessionBean2.echo, callerPrincipal="+p);
          String echo = null;
          try
          {
              InitialContext ctx = new InitialContext();
              EntityHome home = (EntityHome) ctx.lookup("java:comp/env/Entity");
              Entity entity = home.findByPrimaryKey(arg);
              echo = entity.echo(arg);
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
          return echo;
      }
  
      public void noop()
      {
          System.out.println("StatelessSessionBean2.noop");
      }
  
      public void npeError()
      {
          System.out.println("StatelessSessionBean2.npeError");
          Object obj = null;
          obj.toString();
      }
  
  }
  
  
  

Reply via email to