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