1 22 package org.jboss.ejb3.test.security; 23 24 import java.rmi.RemoteException ; 25 import java.security.Principal ; 26 27 import javax.annotation.Resource; 28 import javax.annotation.security.RunAs; 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 35 import org.jboss.annotation.ejb.RemoteBinding; 36 import org.jboss.annotation.security.SecurityDomain; 37 import org.jboss.ejb3.test.security.StatelessSession; 38 import org.jboss.logging.Logger; 39 40 41 49 @Stateless 50 @Remote (org.jboss.ejb3.test.security.StatelessSession.class) 51 @RemoteBinding(jndiBinding = "spec.RunAsStatelessSession") 52 @SecurityDomain("spec-test") 53 @RunAs("InternalRole") 54 public class StatelessSessionBean3 55 { 56 private static final Logger log = Logger 57 .getLogger(StatelessSessionBean3.class); 58 59 @Resource SessionContext sessionContext; 60 61 public void testGetBusinessObject() 62 { 63 StatelessSession ss = (StatelessSession)sessionContext.getBusinessObject(org.jboss.ejb3.test.security.StatelessSession.class); 64 ss.noop(); 65 } 66 67 72 public String echo(String arg) 73 { 74 log.debug("echo, arg="+arg); 75 Principal p = sessionContext.getCallerPrincipal(); 77 log.debug("echo, callerPrincipal="+p); 78 return p.getName(); 79 } 80 81 public String forward(String echoArg) 82 { 83 log.debug("forward, echoArg="+echoArg); 84 String echo = null; 85 try 86 { 87 InitialContext ctx = new InitialContext (); 88 StatelessSession bean = (StatelessSession) ctx.lookup("java:comp/env/ejb/Session"); 89 echo = bean.echo(echoArg); 90 } 91 catch(Exception e) 92 { 93 log.debug("failed", e); 94 throw new EJBException (e); 95 } 96 return echo; 97 } 98 99 103 public void noop() 104 { 105 log.debug("noop calling excluded..."); 106 excluded(); 107 } 108 109 public void npeError() 110 { 111 log.debug("npeError"); 112 Object obj = null; 113 obj.toString(); 114 } 115 public void unchecked() 116 { 117 Principal p = sessionContext.getCallerPrincipal(); 118 log.debug("StatelessSessionBean.unchecked, callerPrincipal="+p); 119 } 120 121 124 public void excluded() 125 { 126 log.debug("excluded, accessed"); 127 Principal p = sessionContext.getCallerPrincipal(); 129 log.debug("excluded, callerPrincipal="+p); 130 } 131 } 132 | Popular Tags |