| 1 22 package org.jboss.test.web.ejb; 23 24 import java.security.Principal ; 25 import java.rmi.RemoteException ; 26 import javax.ejb.CreateException ; 27 import javax.ejb.SessionBean ; 28 import javax.ejb.SessionContext ; 29 import javax.naming.InitialContext ; 30 31 import org.jboss.logging.Logger; 32 import org.jboss.test.web.interfaces.InternalEntityHome; 33 import org.jboss.test.web.interfaces.InternalEntity; 34 35 40 public class EntityFacadeBean implements SessionBean  41 { 42 static Logger log = Logger.getLogger(EntityFacadeBean.class); 43 44 private SessionContext sessionContext; 45 46 public void ejbCreate() throws CreateException  47 { 48 log.debug("ejbCreate() called"); 49 } 50 51 public void ejbActivate() 52 { 53 log.debug("ejbActivate() called"); 54 } 55 56 public void ejbPassivate() 57 { 58 log.debug("ejbPassivate() called"); 59 } 60 61 public void ejbRemove() 62 { 63 log.debug("ejbRemove() called"); 64 } 65 66 public void setSessionContext(SessionContext context) 67 { 68 sessionContext = context; 69 } 70 71 public void write(int value, boolean create) 72 throws RemoteException  73 { 74 log.info("write, value=" + value+", create="+create); 75 Principal p = sessionContext.getCallerPrincipal(); 76 log.debug("echo, callerPrincipal=" + p); 77 boolean isInternalUser = sessionContext.isCallerInRole("InternalUser"); 78 log.debug("Caller isInternalUser: "+isInternalUser); 79 try 80 { 81 InitialContext ctx = new InitialContext (); 82 InternalEntityHome home = (InternalEntityHome) ctx.lookup("java:comp/env/ejb/InternalEntity"); 83 InternalEntity bean; 84 if( create == true ) 85 { 86 bean = home.create(value, value); 87 } 88 else 89 { 90 Integer pk = new Integer (value); 91 bean = home.findByPrimaryKey(pk); 92 } 93 bean.setValue(value); 94 if( create == false ) 95 { 96 bean.remove(); 97 } 98 } 99 catch(Exception e) 100 { 101 throw new RemoteException ("Failed to access InternalEntity", e); 102 } 103 } 104 } 105 | Popular Tags |