1 22 package org.jboss.test.security.ejb; 23 24 import java.security.Principal ; 25 import javax.ejb.CreateException ; 26 import javax.ejb.EJBException ; 27 import javax.ejb.SessionBean ; 28 import javax.ejb.SessionContext ; 29 import javax.naming.Context ; 30 import javax.naming.InitialContext ; 31 import javax.rmi.PortableRemoteObject ; 32 33 import org.jboss.logging.Logger; 34 import org.jboss.test.security.interfaces.CalledSessionLocalHome; 35 import org.jboss.test.security.interfaces.CalledSessionLocal; 36 37 42 public class CallerFacadeBean implements SessionBean 43 { 44 private static Logger log = Logger.getLogger(CallerFacadeBean.class); 45 private SessionContext sessionContext; 46 47 public void ejbCreate() throws CreateException 48 { 49 log.debug("ejbCreate() called"); 50 } 51 52 public void ejbActivate() 53 { 54 log.debug("ejbActivate() called"); 55 } 56 57 public void ejbPassivate() 58 { 59 log.debug("ejbPassivate() called"); 60 } 61 62 public void ejbRemove() 63 { 64 log.debug("ejbRemove() called"); 65 } 66 67 public void setSessionContext(SessionContext context) 68 { 69 sessionContext = context; 70 } 71 72 76 public String invokeEcho(String arg) 77 { 78 log.debug("echo, arg=" + arg); 79 Principal p = sessionContext.getCallerPrincipal(); 80 log.debug("echo, callerPrincipal=" + p); 81 boolean isEchoCaller = sessionContext.isCallerInRole("EchoCaller"); 82 log.debug("echo, isCallerInRole('EchoCaller')=" + isEchoCaller); 83 boolean isInternalRole = sessionContext.isCallerInRole("InternalRole"); 84 log.debug("echo, isCallerInRole('InternalRole')=" + isInternalRole); 85 86 try 87 { 88 InitialContext ic = new InitialContext (); 89 Context enc = (Context ) ic.lookup("java:comp/env"); 90 Object ref = enc.lookup("ejb/CalledSessionLocalHome"); 91 CalledSessionLocalHome home = (CalledSessionLocalHome) PortableRemoteObject.narrow(ref, 92 CalledSessionLocalHome.class); 93 CalledSessionLocal localBean = home.create(); 94 String echo2 = localBean.invokeEcho(arg); 95 log.debug("echo#1, callee.invokeEcho=" + echo2); 96 echo2 = localBean.invokeEcho(arg); 97 log.debug("echo#2, callee.invokeEcho=" + echo2); 98 } 99 catch (Exception e) 100 { 101 log.error("Failed to invoke CalledSession.invokeEcho", e); 102 throw new EJBException ("Failed to invoke Callee.echo", e); 103 } 104 return arg; 105 } 106 107 110 public void callEcho() 111 { 112 try 113 { 114 InitialContext ic = new InitialContext (); 115 Context enc = (Context ) ic.lookup("java:comp/env"); 116 Object ref = enc.lookup("ejb/CalledSessionLocalHome"); 117 CalledSessionLocalHome home = (CalledSessionLocalHome) PortableRemoteObject.narrow(ref, 118 CalledSessionLocalHome.class); 119 CalledSessionLocal bean = home.create(); 120 bean.callLocalEcho("callEcho#2"); 121 log.debug("echo, callee.callLocalEcho#1"); 122 bean.callLocalEcho("callEcho#2"); 123 log.debug("echo, callee.callLocalEcho#2"); 124 } 125 catch (Exception e) 126 { 127 log.error("Failed to invoke Callee.invokeEcho", e); 128 throw new EJBException ("Failed to invoke Callee.invokeEcho", e); 129 } 130 131 } 132 133 public void noop() 134 { 135 log.debug("noop"); 136 } 137 138 } 139 | Popular Tags |