KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > ejb > StatelessSessionBean2


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.ejb;
23
24 import java.rmi.RemoteException JavaDoc;
25 import java.security.Principal JavaDoc;
26 import javax.ejb.CreateException JavaDoc;
27 import javax.ejb.EJBException JavaDoc;
28 import javax.ejb.SessionBean JavaDoc;
29 import javax.ejb.SessionContext JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31
32 import org.jboss.test.security.interfaces.Entity;
33 import org.jboss.test.security.interfaces.EntityHome;
34 import org.jboss.test.security.interfaces.StatelessSession;
35 import org.jboss.test.security.interfaces.StatelessSessionHome;
36
37 /** A SessionBean that access the Entity bean to test Principal
38 identity propagation.
39
40 @author Scott.Stark@jboss.org
41 @version $Revision: 58115 $
42 */

43 public class StatelessSessionBean2 implements SessionBean JavaDoc
44 {
45    org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
46    
47     private SessionContext JavaDoc sessionContext;
48
49     public void ejbCreate() throws RemoteException JavaDoc, CreateException JavaDoc
50     {
51         log.debug("ejbCreate() called");
52     }
53
54     public void ejbActivate() throws RemoteException JavaDoc
55     {
56         log.debug("ejbActivate() called");
57     }
58
59     public void ejbPassivate() throws RemoteException JavaDoc
60     {
61         log.debug("ejbPassivate() called");
62     }
63
64     public void ejbRemove() throws RemoteException JavaDoc
65     {
66         log.debug("ejbRemove() called");
67     }
68
69     public void setSessionContext(SessionContext JavaDoc context) throws RemoteException JavaDoc
70     {
71         sessionContext = context;
72     }
73
74     public String JavaDoc echo(String JavaDoc arg)
75     {
76         log.debug("echo, arg="+arg);
77         // This call should fail if the bean is not secured
78
Principal JavaDoc p = sessionContext.getCallerPrincipal();
79         log.debug("echo, callerPrincipal="+p);
80         String JavaDoc echo = null;
81         try
82         {
83             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
84             EntityHome home = (EntityHome) ctx.lookup("java:comp/env/ejb/Entity");
85             Entity bean = home.findByPrimaryKey(arg);
86             echo = bean.echo(arg);
87         }
88         catch(Exception JavaDoc e)
89         {
90             log.debug("Entity.echo failed", e);
91             e.fillInStackTrace();
92             throw new EJBException JavaDoc("Entity.echo failed", e);
93         }
94         return echo;
95     }
96
97     public String JavaDoc forward(String JavaDoc echoArg)
98     {
99         log.debug("forward, echoArg="+echoArg);
100         String JavaDoc echo = null;
101         try
102         {
103             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
104             StatelessSessionHome home = (StatelessSessionHome) ctx.lookup("java:comp/env/ejb/Session");
105             StatelessSession bean = home.create();
106             echo = bean.echo(echoArg);
107         }
108         catch(Exception JavaDoc e)
109         {
110             log.debug("StatelessSession.echo failed", e);
111             e.fillInStackTrace();
112             throw new EJBException JavaDoc("StatelessSession.echo failed", e);
113         }
114         return echo;
115     }
116
117     public void noop()
118     {
119         log.debug("noop");
120     }
121
122     public void npeError()
123     {
124         log.debug("npeError");
125         Object JavaDoc obj = null;
126         obj.toString();
127     }
128     public void unchecked()
129     {
130         Principal JavaDoc p = sessionContext.getCallerPrincipal();
131         log.debug("StatelessSessionBean.unchecked, callerPrincipal="+p);
132     }
133
134     public void excluded()
135     {
136         throw new EJBException JavaDoc("StatelessSessionBean.excluded, no access should be allowed");
137     }
138 }
139
Popular Tags