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