KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > security > UnsecuredStatelessSessionBean2


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.ejb3.test.security;
23
24 import java.security.Principal JavaDoc;
25 import javax.ejb.EJB JavaDoc;
26 import javax.ejb.EJBs JavaDoc;
27 import javax.annotation.Resource;
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.Remote JavaDoc;
30 import javax.ejb.SessionContext JavaDoc;
31 import javax.ejb.Stateless JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import org.jboss.annotation.ejb.RemoteBinding;
34 import org.jboss.ejb3.Container;
35
36 /** A SessionBean that access the Entity bean to test Principal
37 identity propagation.
38
39 @author Scott.Stark@jboss.org
40 @version $Revision: 58110 $
41 */

42 @Stateless JavaDoc
43 @Remote JavaDoc(org.jboss.ejb3.test.security.StatelessSession.class)
44 @RemoteBinding(jndiBinding = "spec.UnsecureStatelessSession2")
45 @EJBs JavaDoc({@EJB JavaDoc(name="Session", beanInterface=org.jboss.ejb3.test.security.StatelessSession.class, beanName="StatelessSession")})
46 public class UnsecuredStatelessSessionBean2
47 {
48     org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
49     
50     @Resource SessionContext JavaDoc sessionContext;
51     
52     public String JavaDoc echo(String JavaDoc arg)
53     {
54         // This call should fail if the bean is not secured
55
Principal JavaDoc p = sessionContext.getCallerPrincipal();
56         String JavaDoc echo = null;
57         try
58         {
59             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
60             StatefulSession bean = (StatefulSession) ctx.lookup("spec.StatefulSession");
61             echo = bean.echo(arg);
62         }
63         catch(Exception JavaDoc e)
64         {
65             e.fillInStackTrace();
66             throw new EJBException JavaDoc("Stateful.echo failed", e);
67         }
68         return echo;
69     }
70
71     public String JavaDoc forward(String JavaDoc echoArg)
72     {
73         log.info("forward, echoArg="+echoArg);
74         String JavaDoc echo = null;
75         try
76         {
77             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
78             StatelessSession bean = (StatelessSession)ctx.lookup(Container.ENC_CTX_NAME + "/env/Session");
79             echo = bean.echo(echoArg);
80         }
81         catch(Exception JavaDoc e)
82         {
83             log.info("StatelessSession.echo failed", e);
84             e.fillInStackTrace();
85             throw new EJBException JavaDoc("StatelessSession.echo failed", e);
86         }
87         return echo;
88     }
89
90     public void noop()
91     {
92         log.info("noop");
93     }
94
95     public void npeError()
96     {
97         log.info("npeError");
98         Object JavaDoc obj = null;
99         obj.toString();
100     }
101     public void unchecked()
102     {
103         Principal JavaDoc p = sessionContext.getCallerPrincipal();
104         log.info("StatelessSessionBean.unchecked, callerPrincipal="+p);
105     }
106
107     public void excluded()
108     {
109         throw new EJBException JavaDoc("StatelessSessionBean.excluded, no access should be allowed");
110     }
111 }
112
Popular Tags