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.StatelessSessionLocal; 35 import org.jboss.test.security.interfaces.StatelessSessionLocalHome; 36 37 42 public class FacadeTargetBean implements SessionBean 43 { 44 private static Logger log = Logger.getLogger(FacadeTargetBean.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 84 if (isEchoCaller == false) 85 throw new SecurityException ("isEchoCaller == false"); 86 try 87 { 88 InitialContext ic = new InitialContext (); 89 Context enc = (Context ) ic.lookup("java:comp/env"); 90 Object ref = enc.lookup("ejb/local/StatelessSessionLocalHome"); 91 StatelessSessionLocalHome localHome = (StatelessSessionLocalHome) PortableRemoteObject.narrow(ref, 92 StatelessSessionLocalHome.class); 93 StatelessSessionLocal localBean = localHome.create(); 94 String echo2 = localBean.echo(arg); 95 log.debug("echo#1, callee.echo=" + echo2); 96 echo2 = localBean.echo(arg); 97 log.debug("echo#2, callee.echo=" + echo2); 98 } 99 catch (Exception e) 100 { 101 log.error("Failed to invoke Callee.echo", e); 102 throw new EJBException ("Failed to invoke Callee.echo", e); 103 } 104 105 isEchoCaller = sessionContext.isCallerInRole("EchoCaller"); 106 log.debug("echo, post calls isCallerInRole('EchoCaller')=" + isEchoCaller); 107 if (isEchoCaller == false) 108 throw new SecurityException ("isEchoCaller == false post calls"); 109 110 return arg; 111 } 112 113 116 public String callLocalEcho(String arg) 117 { 118 return arg; 119 } 120 121 } 122 | Popular Tags |