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("EchoBean.echo(\"" + arg + "\") called");
46 System.out.println("Prinicpal = " + ctx.getCallerPrincipal());
47 java.security.AccessControlContext acc = java.security.AccessController.getContext();
48 if (acc != null){
49 System.out.println("Subject = " + javax.security.auth.Subject.getSubject(acc));
50 } else {
51 System.out.println("acc = " + acc);
52 }
53 return "Echo:: " + arg;
54 }
55}
56
57
58
59
60
61
62
63
64