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.annotation.security.RolesAllowed; 29 import javax.ejb.EJBException ; 30 import javax.ejb.Remote ; 31 import javax.ejb.SessionContext ; 32 import javax.ejb.Stateless ; 33 import javax.naming.InitialContext ; 34 import org.jboss.annotation.ejb.RemoteBinding; 35 import org.jboss.annotation.security.SecurityDomain; 36 import org.jboss.ejb3.Container; 37 import org.jboss.logging.Logger; 38 39 45 @Stateless (name="StatelessSession2") 46 @Remote (org.jboss.ejb3.test.security.StatelessSession.class) 47 @RemoteBinding(jndiBinding = "spec.StatelessSession2") 48 @RolesAllowed({"Echo"}) 49 @SecurityDomain("spec-test") 50 @EJBs ({@EJB (name="Session", beanInterface=org.jboss.ejb3.test.security.StatelessSession.class, beanName="StatelessSession")}) 51 public class StatelessSessionBean2 52 { 53 private static final Logger log = Logger 54 .getLogger(StatelessSessionBean2.class); 55 56 @Resource SessionContext sessionContext; 57 58 public void testGetBusinessObject() 59 { 60 StatelessSession ss = (StatelessSession)sessionContext.getBusinessObject(org.jboss.ejb3.test.security.StatelessSession.class); 61 ss.noop(); 62 } 63 64 public String echo(String arg) 65 { 66 log.info("echo, arg="+arg); 67 68 Principal p = sessionContext.getCallerPrincipal(); 70 log.info("echo, callerPrincipal="+p); 71 72 String echo = null; 73 try 74 { 75 InitialContext ctx = new InitialContext (); 76 StatefulSession bean = (StatefulSession) ctx.lookup("spec.StatefulSession"); 77 echo = bean.echo(arg); 78 } 79 catch(Exception e) 80 { 81 throw new EJBException ("Stateful.echo failed", e); 82 } 83 84 return echo; 85 } 86 87 public String forward(String echoArg) 88 { 89 log.info("forward, echoArg="+echoArg); 90 String echo = null; 91 try 92 { 93 InitialContext ctx = new InitialContext (); 94 StatelessSession bean = (StatelessSession)ctx.lookup(Container.ENC_CTX_NAME + "/env/ejb/Session"); 95 echo = bean.echo(echoArg); 96 } 97 catch(Exception e) 98 { 99 log.info("StatelessSession.echo failed", e); 100 throw new EJBException ("StatelessSession.echo failed", e); 101 } 102 return echo; 103 } 104 105 public void noop() 106 { 107 log.info("noop"); 108 } 109 110 public void npeError() 111 { 112 log.info("npeError"); 113 Object obj = null; 114 obj.toString(); 115 } 116 public void unchecked() 117 { 118 Principal p = sessionContext.getCallerPrincipal(); 119 log.info("StatelessSessionBean.unchecked, callerPrincipal="+p); 120 } 121 122 public void excluded() 123 { 124 throw new EJBException ("StatelessSessionBean.excluded, no access should be allowed"); 125 } 126 } 127 | Popular Tags |