1
10package echo;
11
12import javax.ejb.CreateException;
13import javax.ejb.SessionBean;
14import javax.ejb.SessionContext;
15import javax.naming.InitialContext;
16import javax.naming.NamingException;
17
18public class EchoBean implements SessionBean {
19
20 private SessionContext ctx;
21
22 public void ejbActivate() {
23 System.out.println("EchoBean.ejbActivate called");
24 }
25
26 public void ejbRemove() {
27 System.out.println("EchoBean.ejbRemove called");
28 }
29
30 public void ejbPassivate() {
31 System.out.println("EchoBean.ejbPassivate called");
32 }
33
34 public void setSessionContext(SessionContext ctx) {
35 System.out.println("EchoBean.setSessionContext called");
36 this.ctx = ctx;
37
38 }
39
40 public void ejbCreate () throws CreateException {
41 System.out.println("EchoBean.ejbCreate called");
42 }
43
44 public String echo(String arg) {
45 System.out.println("--- BEGIN EchoBean.echo(\"" + arg + "\") ---");
46 java.security.Principal caller = ctx.getCallerPrincipal();
47 boolean inRole = ctx.isCallerInRole("echouser");
48 System.out.println("Caller Name: " + caller.getName());
49 System.out.println("Caller in role \"echouser\"? " + inRole);
50 System.out.println("--- END EchoBean.echo(\"" + arg + "\") ---");
51
52 return arg;
53 }
54}
55
56
57
58
59
60
61
62
63