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 31 36 public class StatelessSessionBean implements SessionBean 37 { 38 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 39 40 private SessionContext sessionContext; 41 42 public void ejbCreate() throws CreateException 43 { 44 log.debug("ejbCreate() called"); 45 } 46 47 public void ejbActivate() 48 { 49 log.debug("ejbActivate() called"); 50 } 51 52 public void ejbPassivate() 53 { 54 log.debug("ejbPassivate() called"); 55 } 56 57 public void ejbRemove() 58 { 59 log.debug("ejbRemove() called"); 60 } 61 62 public void setSessionContext(SessionContext context) 63 { 64 sessionContext = context; 65 } 66 67 public String echo(String arg) 68 { 69 log.debug("echo, arg="+arg); 70 Principal p = sessionContext.getCallerPrincipal(); 71 log.debug("echo, callerPrincipal="+p); 72 boolean isCaller = sessionContext.isCallerInRole("EchoCaller"); 73 log.debug("echo, isCallerInRole('EchoCaller')="+isCaller); 74 if( isCaller == false ) 75 throw new SecurityException ("Caller does not have EchoCaller role"); 76 return arg; 77 } 78 public String forward(String echoArg) 79 { 80 log.debug("forward, echoArg="+echoArg); 81 return echo(echoArg); 82 } 83 84 public void noop() 85 { 86 log.debug("noop"); 87 } 88 public void npeError() 89 { 90 log.debug("npeError"); 91 Object obj = null; 92 obj.toString(); 93 } 94 95 public void unchecked() 96 { 97 Principal p = sessionContext.getCallerPrincipal(); 98 log.debug("unchecked, callerPrincipal="+p); 99 } 100 101 public void excluded() 102 { 103 throw new EJBException ("excluded, no access should be allowed"); 104 } 105 106 } 107 | Popular Tags |