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