1 22 package org.jboss.test.security.ejb; 23 24 import java.rmi.RemoteException ; 25 import java.security.Principal ; 26 import javax.ejb.CreateException ; 27 import javax.ejb.EJBException ; 28 import javax.ejb.SessionBean ; 29 import javax.ejb.SessionContext ; 30 import javax.naming.InitialContext ; 31 32 import org.jboss.test.security.interfaces.Entity; 33 import org.jboss.test.security.interfaces.EntityHome; 34 import org.jboss.test.security.interfaces.StatelessSession; 35 import org.jboss.test.security.interfaces.StatelessSessionHome; 36 37 43 public class StatelessSessionBean2 implements SessionBean 44 { 45 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 46 47 private SessionContext sessionContext; 48 49 public void ejbCreate() throws RemoteException , CreateException 50 { 51 log.debug("ejbCreate() called"); 52 } 53 54 public void ejbActivate() throws RemoteException 55 { 56 log.debug("ejbActivate() called"); 57 } 58 59 public void ejbPassivate() throws RemoteException 60 { 61 log.debug("ejbPassivate() called"); 62 } 63 64 public void ejbRemove() throws RemoteException 65 { 66 log.debug("ejbRemove() called"); 67 } 68 69 public void setSessionContext(SessionContext context) throws RemoteException 70 { 71 sessionContext = context; 72 } 73 74 public String echo(String arg) 75 { 76 log.debug("echo, arg="+arg); 77 Principal p = sessionContext.getCallerPrincipal(); 79 log.debug("echo, callerPrincipal="+p); 80 String echo = null; 81 try 82 { 83 InitialContext ctx = new InitialContext (); 84 EntityHome home = (EntityHome) ctx.lookup("java:comp/env/ejb/Entity"); 85 Entity bean = home.findByPrimaryKey(arg); 86 echo = bean.echo(arg); 87 } 88 catch(Exception e) 89 { 90 log.debug("Entity.echo failed", e); 91 e.fillInStackTrace(); 92 throw new EJBException ("Entity.echo failed", e); 93 } 94 return echo; 95 } 96 97 public String forward(String echoArg) 98 { 99 log.debug("forward, echoArg="+echoArg); 100 String echo = null; 101 try 102 { 103 InitialContext ctx = new InitialContext (); 104 StatelessSessionHome home = (StatelessSessionHome) ctx.lookup("java:comp/env/ejb/Session"); 105 StatelessSession bean = home.create(); 106 echo = bean.echo(echoArg); 107 } 108 catch(Exception e) 109 { 110 log.debug("StatelessSession.echo failed", e); 111 e.fillInStackTrace(); 112 throw new EJBException ("StatelessSession.echo failed", e); 113 } 114 return echo; 115 } 116 117 public void noop() 118 { 119 log.debug("noop"); 120 } 121 122 public void npeError() 123 { 124 log.debug("npeError"); 125 Object obj = null; 126 obj.toString(); 127 } 128 public void unchecked() 129 { 130 Principal p = sessionContext.getCallerPrincipal(); 131 log.debug("StatelessSessionBean.unchecked, callerPrincipal="+p); 132 } 133 134 public void excluded() 135 { 136 throw new EJBException ("StatelessSessionBean.excluded, no access should be allowed"); 137 } 138 } 139 | Popular Tags |