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 import org.jboss.logging.Logger; 40 41 47 @Stateless (name="StatelessSessionInDomain") 48 @Remote (org.jboss.ejb3.test.security.StatelessSession.class) 49 @RemoteBinding(jndiBinding = "spec.StatelessSessionInDomain") 50 @SecurityDomain("spec-test-domain") 51 public class StatelessSessionBeanInDomain 52 { 53 private static final Logger log = Logger 54 .getLogger(StatelessSessionBean3.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); 84 } 85 86 return echo; 87 } 88 89 public String forward(String echoArg) 90 { 91 log.info("forward, echoArg="+echoArg); 92 String echo = null; 93 try 94 { 95 InitialContext ctx = new InitialContext (); 96 StatelessSession bean = (StatelessSession)ctx.lookup("java:comp/env/ejb/Session"); 97 echo = bean.echo(echoArg); 98 } 99 catch(Exception e) 100 { 101 log.info("StatelessSession.echo failed", e); 102 throw new EJBException ("StatelessSession.echo failed", e); 104 } 105 return echo; 106 } 107 108 public void noop() 109 { 110 log.info("noop"); 111 } 112 113 public void npeError() 114 { 115 log.info("npeError"); 116 Object obj = null; 117 obj.toString(); 118 } 119 public void unchecked() 120 { 121 Principal p = sessionContext.getCallerPrincipal(); 122 log.info("StatelessSessionBean.unchecked, callerPrincipal="+p); 123 } 124 125 @DenyAll 126 public void excluded() 127 { 128 throw new EJBException ("StatelessSessionBean.excluded, no access should be allowed"); 129 } 130 } 131 | Popular Tags |