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.ejb.EJBException ; 29 import javax.ejb.Local ; 30 import javax.ejb.Remote ; 31 import javax.ejb.SessionContext ; 32 import javax.ejb.Stateful ; 33 import javax.naming.InitialContext ; 34 import org.jboss.logging.Logger; 35 import org.jboss.annotation.ejb.RemoteBinding; 36 import org.jboss.annotation.security.SecurityDomain; 37 import org.jboss.ejb3.Container; 38 39 44 @Stateful (name="CallerFacadeTargetSFSB") 45 @Local (org.jboss.ejb3.test.security.CalledSessionLocal.class) 46 @Remote (org.jboss.ejb3.test.security.CalledSession.class) 47 @RemoteBinding(jndiBinding="spec.CallerFacadeTargetSFSB") 48 @SecurityDomain("spec-test") 49 @EJBs ({@EJB (name="StatelessSessionLocal", beanInterface=org.jboss.ejb3.test.security.StatelessSessionLocal.class, beanName="CalleeBean")}) 50 public class FacadeTargetBean 51 { 52 private static Logger log = Logger.getLogger(FacadeTargetBean.class); 53 @Resource SessionContext sessionContext; 54 55 59 public String invokeEcho(String arg) 60 { 61 log.debug("echo, arg=" + arg); 62 Principal p = sessionContext.getCallerPrincipal(); 63 log.debug("echo, callerPrincipal=" + p); 64 boolean isEchoCaller = sessionContext.isCallerInRole("Echo"); 65 log.debug("echo, isCallerInRole('Echo')=" + isEchoCaller); 66 67 if (isEchoCaller == false) 68 throw new SecurityException ("isEchoCaller == false"); 69 try 70 { 71 InitialContext ic = new InitialContext (); 72 StatelessSessionLocal localBean = (StatelessSessionLocal)ic.lookup(Container.ENC_CTX_NAME + "/env/StatelessSessionLocal"); 73 String echo2 = localBean.echo(arg); 74 log.debug("echo#1, callee.echo=" + echo2); 75 echo2 = localBean.echo(arg); 76 log.debug("echo#2, callee.echo=" + echo2); 77 } 78 catch (Exception e) 79 { 80 log.error("Failed to invoke Callee.echo", e); 81 throw new EJBException ("Failed to invoke Callee.echo", e); 82 } 83 84 isEchoCaller = sessionContext.isCallerInRole("Echo"); 85 log.debug("echo, post calls isCallerInRole('Echo')=" + isEchoCaller); 86 if (isEchoCaller == false) 87 throw new SecurityException ("isEchoCaller == false post calls"); 88 89 return arg; 90 } 91 92 95 public String callLocalEcho(String arg) 96 { 97 return arg; 98 } 99 100 } 101 | Popular Tags |