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 import org.jboss.logging.Logger; 38 39 47 public class StatelessSessionBean3 implements SessionBean 48 { 49 private static Logger log = Logger.getLogger(StatelessSessionBean3.class); 50 private SessionContext sessionContext; 51 52 public void ejbCreate() throws RemoteException , CreateException 53 { 54 log.debug("ejbCreate() called"); 55 } 56 57 public void ejbActivate() throws RemoteException 58 { 59 log.debug("ejbActivate() called"); 60 } 61 62 public void ejbPassivate() throws RemoteException 63 { 64 log.debug("ejbPassivate() called"); 65 } 66 67 public void ejbRemove() throws RemoteException 68 { 69 log.debug("ejbRemove() called"); 70 } 71 72 public void setSessionContext(SessionContext context) throws RemoteException 73 { 74 sessionContext = context; 75 } 76 77 82 public String echo(String arg) 83 { 84 log.debug("echo, arg="+arg); 85 Principal p = sessionContext.getCallerPrincipal(); 87 log.debug("echo, callerPrincipal="+p); 88 String echo = null; 89 try 90 { 91 InitialContext ctx = new InitialContext (); 92 EntityHome home = (EntityHome) ctx.lookup("java:comp/env/ejb/Entity"); 93 Entity bean = home.findByPrimaryKey(arg); 94 echo = bean.echo(arg); 95 } 96 catch(Exception e) 97 { 98 log.debug("failed", e); 99 e.fillInStackTrace(); 100 throw new EJBException (e); 101 } 102 return echo; 103 } 104 105 public String forward(String echoArg) 106 { 107 log.debug("forward, echoArg="+echoArg); 108 String echo = null; 109 try 110 { 111 InitialContext ctx = new InitialContext (); 112 StatelessSessionHome home = (StatelessSessionHome) ctx.lookup("java:comp/env/ejb/Session"); 113 StatelessSession bean = home.create(); 114 echo = bean.echo(echoArg); 115 } 116 catch(Exception e) 117 { 118 log.debug("failed", e); 119 e.fillInStackTrace(); 120 throw new EJBException (e); 121 } 122 return echo; 123 } 124 125 129 public void noop() 130 { 131 log.debug("noop calling excluded..."); 132 StatelessSession myEJB = (StatelessSession) sessionContext.getEJBObject(); 133 try 134 { 135 myEJB.excluded(); 136 } 137 catch(RemoteException e) 138 { 139 throw new EJBException ("Failed to access excluded: "+e.detail); 140 } 141 } 142 143 public void npeError() 144 { 145 log.debug("npeError"); 146 Object obj = null; 147 obj.toString(); 148 } 149 public void unchecked() 150 { 151 Principal p = sessionContext.getCallerPrincipal(); 152 log.debug("StatelessSessionBean.unchecked, callerPrincipal="+p); 153 } 154 155 158 public void excluded() 159 { 160 log.debug("excluded, accessed"); 161 Principal p = sessionContext.getCallerPrincipal(); 163 log.debug("excluded, callerPrincipal="+p); 164 } 165 } 166 | Popular Tags |