1 22 package org.jboss.ejb3.test.security; 23 24 import java.security.Principal ; 25 26 import javax.annotation.Resource; 27 import javax.ejb.EJBException ; 28 import javax.ejb.EntityContext ; 29 import javax.ejb.SessionContext ; 30 import javax.naming.InitialContext ; 31 import javax.naming.NamingException ; 32 import javax.persistence.Entity; 33 import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; 34 import javax.persistence.Id; 35 import javax.persistence.Table; 36 import javax.security.auth.Subject ; 37 38 46 @Entity 47 @Table(name = "ENTITY_BEAN") 48 public class EntityBean 49 { 50 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 51 52 private Long key; 53 54 @Id @GeneratedValue(strategy=GenerationType.IDENTITY) 55 public Long getKey() 56 { 57 return key; 58 } 59 60 public void setKey(Long key) 61 { 62 this.key = key; 63 } 64 65 public String echo(String arg) 66 { 67 log.debug("EntityBean.echo, arg="+arg); 68 try 70 { 71 InitialContext ctx = new InitialContext (); 72 Object securityMgr = ctx.lookup("java:comp/env/security/security-domain"); 73 log.debug("Checking java:comp/env/security/security-domain"); 74 if( securityMgr == null ) 75 throw new EJBException ("Failed to find security mgr under: java:comp/env/security/security-domain"); 76 log.debug("Found SecurityManager: "+securityMgr); 77 Subject activeSubject = (Subject ) ctx.lookup("java:comp/env/security/subject"); 78 log.debug("ActiveSubject: "+activeSubject); 79 } 80 catch(NamingException e) 81 { 82 log.debug("failed", e); 83 throw new EJBException ("Naming exception: "+e.toString(true)); 84 } 85 return null; 86 } 87 } 88 | Popular Tags |