1 22 package org.jboss.test.security.ejb.jbas1852; 23 24 import java.security.Principal ; 25 import javax.ejb.CreateException ; 26 import javax.ejb.SessionBean ; 27 import javax.ejb.SessionContext ; 28 import javax.naming.InitialContext ; 29 30 36 public class PublicSessionBean implements SessionBean 37 { 38 private SessionContext sessionContext; 39 40 public void ejbCreate() throws CreateException 41 { 42 System.out.println("PublicSessionBean.ejbCreate() called"); 43 } 44 45 public void ejbActivate() 46 { 47 System.out.println("PublicSessionBean.ejbActivate() called"); 48 } 49 50 public void ejbPassivate() 51 { 52 System.out.println("PublicSessionBean.ejbPassivate() called"); 53 } 54 55 public void ejbRemove() 56 { 57 System.out.println("PublicSessionBean.ejbRemove() called"); 58 } 59 60 public void setSessionContext(SessionContext context) 61 { 62 sessionContext = context; 63 } 64 65 public String echo(String arg) 66 { 67 System.out.println("PublicSessionBean.echo, arg="+arg); 68 Principal p = sessionContext.getCallerPrincipal(); 69 System.out.println("PublicSessionBean.echo, callerPrincipal="+p); 70 System.out.println("PublicSessionBean.echo, isCallerInRole('EchoUser')="+sessionContext.isCallerInRole("EchoUser")); 71 try 72 { 73 InitialContext ctx = new InitialContext (); 74 SessionHome home = (SessionHome) ctx.lookup("java:comp/env/ejb/PrivateSession"); 75 Session bean = home.create(); 76 System.out.println("PublicSessionBean.echo, created PrivateSession"); 77 arg = bean.echo(arg); 78 } 79 catch(Exception e) 80 { 81 } 82 return arg; 83 } 84 public void noop() 85 { 86 System.out.println("PublicSessionBean.noop"); 87 Principal p = sessionContext.getCallerPrincipal(); 88 System.out.println("PublicSessionBean.noop, callerPrincipal="+p); 89 } 90 public void restricted() 91 { 92 System.out.println("PublicSessionBean.restricted"); 93 Principal p = sessionContext.getCallerPrincipal(); 94 System.out.println("PublicSessionBean.restricted, callerPrincipal="+p); 95 } 96 } 97 | Popular Tags |