1 22 package org.jboss.test.security.ejb; 23 24 import java.lang.reflect.Method ; 25 import java.lang.reflect.InvocationTargetException ; 26 import java.rmi.RemoteException ; 27 import java.security.Principal ; 28 import javax.ejb.CreateException ; 29 import javax.ejb.EJBException ; 30 import javax.ejb.EntityBean ; 31 import javax.ejb.EntityContext ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 import javax.security.auth.Subject ; 35 36 44 public class EntityBeanImpl implements EntityBean 45 { 46 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 47 48 private String key; 49 private EntityContext context; 50 51 public void ejbActivate() 52 { 53 log.debug("EntityBean.ejbActivate() called"); 54 } 55 56 public void ejbPassivate() 57 { 58 log.debug("EntityBean.ejbPassivate() called"); 59 } 60 61 public void ejbRemove() 62 { 63 log.debug("EntityBean.ejbRemove() called"); 64 } 65 public void ejbLoad() 66 { 67 log.debug("EntityBean.ejbLoad() called"); 68 key = (String ) context.getPrimaryKey(); 69 } 70 public void ejbStore() 71 { 72 log.debug("EntityBean.ejbStore() called"); 73 } 74 75 public void setEntityContext(EntityContext context) 76 { 77 this.context = context; 78 } 79 public void unsetEntityContext() 80 { 81 this.context = null; 82 } 83 84 public String ejbCreate(String key) 85 throws CreateException 86 { 87 this.key = key; 88 return key; 89 } 90 public void ejbPostCreate(String key) 91 { 92 } 93 94 public String echo(String arg) 95 { 96 log.debug("EntityBean.echo, arg="+arg); 97 Principal p = context.getCallerPrincipal(); 98 boolean isInternalRole = context.isCallerInRole("InternalRole"); 99 log.debug("EntityBean.echo, callerPrincipal="+p); 100 log.debug("EntityBean.echo, isCallerInRole('InternalRole')="+isInternalRole); 101 try 103 { 104 InitialContext ctx = new InitialContext (); 105 Object securityMgr = ctx.lookup("java:comp/env/security/security-domain"); 106 log.debug("Checking java:comp/env/security/security-domain"); 107 if( securityMgr == null ) 108 throw new EJBException ("Failed to find security mgr under: java:comp/env/security/security-domain"); 109 log.debug("Found SecurityManager: "+securityMgr); 110 Subject activeSubject = (Subject ) ctx.lookup("java:comp/env/security/subject"); 111 log.debug("ActiveSubject: "+activeSubject); 112 } 113 catch(NamingException e) 114 { 115 log.debug("failed", e); 116 throw new EJBException ("Naming exception: "+e.toString(true)); 117 } 118 return p.getName(); 119 } 120 121 public String ejbFindByPrimaryKey(String key) 122 { 123 log.debug("EntityBean.ejbFindByPrimaryKey, key="+key); 124 return key; 125 } 126 } 127 | Popular Tags |