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.annotation.security.RolesAllowed; 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 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 @Stateless (name="CallerFacadeBean-testRunAsSFSB") 45 @Remote (org.jboss.ejb3.test.security.CalledSession.class) 46 @RemoteBinding(jndiBinding = "spec.CallerFacadeBean-testRunAsSFSB") 47 @SecurityDomain("spec-test") 48 @RolesAllowed({"Echo"}) 49 @EJBs ({@EJB (name="CalledSessionLocal", beanInterface=org.jboss.ejb3.test.security.CalledSessionLocal.class, beanName="CallerFacadeTargetSFSB")}) 50 public class CallerFacadeBean 51 { 52 private static Logger log = Logger.getLogger(CallerFacadeBean.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("EchoCaller"); 65 log.debug("echo, isCallerInRole('EchoCaller')=" + isEchoCaller); 66 boolean isInternalRole = sessionContext.isCallerInRole("InternalRole"); 67 log.debug("echo, isCallerInRole('InternalRole')=" + isInternalRole); 68 69 try 70 { 71 InitialContext ic = new InitialContext (); 72 CalledSessionLocal localBean = (CalledSessionLocal)ic.lookup(Container.ENC_CTX_NAME + "/env/CalledSessionLocal"); 73 String echo2 = localBean.invokeEcho(arg); 74 log.debug("echo#1, callee.invokeEcho=" + echo2); 75 echo2 = localBean.invokeEcho(arg); 76 log.debug("echo#2, callee.invokeEcho=" + echo2); 77 } 78 catch (Exception e) 79 { 80 e.printStackTrace(); 81 log.error("Failed to invoke CalledSession.invokeEcho", e); 82 throw new EJBException ("Failed to invoke Callee.echo", e); 83 } 84 return arg; 85 } 86 87 90 public void callEcho() 91 { 92 try 93 { 94 InitialContext ic = new InitialContext (); 95 CalledSessionLocal bean = (CalledSessionLocal)ic.lookup(Container.ENC_CTX_NAME + "/env/CalledSessionLocal"); 96 bean.callLocalEcho("callEcho#2"); 97 log.debug("echo, callee.callLocalEcho#1"); 98 bean.callLocalEcho("callEcho#2"); 99 log.debug("echo, callee.callLocalEcho#2"); 100 } 101 catch (Exception e) 102 { 103 log.error("Failed to invoke Callee.invokeEcho", e); 104 throw new EJBException ("Failed to invoke Callee.invokeEcho", e); 105 } 106 107 } 108 109 public void noop() 110 { 111 log.debug("noop"); 112 } 113 114 } 115 | Popular Tags |