1 22 package org.jboss.ejb3.test.security; 23 24 import java.security.Principal ; 25 import javax.ejb.EJB ; 26 import javax.ejb.EJBs ; 27 import javax.annotation.Resource; 28 import javax.ejb.EJBException ; 29 import javax.ejb.Remote ; 30 import javax.ejb.SessionContext ; 31 import javax.ejb.Stateless ; 32 import javax.naming.InitialContext ; 33 import org.jboss.annotation.ejb.RemoteBinding; 34 import org.jboss.ejb3.Container; 35 36 42 @Stateless 43 @Remote (org.jboss.ejb3.test.security.StatelessSession.class) 44 @RemoteBinding(jndiBinding = "spec.UnsecureStatelessSession2") 45 @EJBs ({@EJB (name="Session", beanInterface=org.jboss.ejb3.test.security.StatelessSession.class, beanName="StatelessSession")}) 46 public class UnsecuredStatelessSessionBean2 47 { 48 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 49 50 @Resource SessionContext sessionContext; 51 52 public String echo(String arg) 53 { 54 Principal p = sessionContext.getCallerPrincipal(); 56 String echo = null; 57 try 58 { 59 InitialContext ctx = new InitialContext (); 60 StatefulSession bean = (StatefulSession) ctx.lookup("spec.StatefulSession"); 61 echo = bean.echo(arg); 62 } 63 catch(Exception e) 64 { 65 e.fillInStackTrace(); 66 throw new EJBException ("Stateful.echo failed", e); 67 } 68 return echo; 69 } 70 71 public String forward(String echoArg) 72 { 73 log.info("forward, echoArg="+echoArg); 74 String echo = null; 75 try 76 { 77 InitialContext ctx = new InitialContext (); 78 StatelessSession bean = (StatelessSession)ctx.lookup(Container.ENC_CTX_NAME + "/env/Session"); 79 echo = bean.echo(echoArg); 80 } 81 catch(Exception e) 82 { 83 log.info("StatelessSession.echo failed", e); 84 e.fillInStackTrace(); 85 throw new EJBException ("StatelessSession.echo failed", e); 86 } 87 return echo; 88 } 89 90 public void noop() 91 { 92 log.info("noop"); 93 } 94 95 public void npeError() 96 { 97 log.info("npeError"); 98 Object obj = null; 99 obj.toString(); 100 } 101 public void unchecked() 102 { 103 Principal p = sessionContext.getCallerPrincipal(); 104 log.info("StatelessSessionBean.unchecked, callerPrincipal="+p); 105 } 106 107 public void excluded() 108 { 109 throw new EJBException ("StatelessSessionBean.excluded, no access should be allowed"); 110 } 111 } 112 | Popular Tags |