KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import javax.annotation.Resource;
27 import javax.ejb.CreateException JavaDoc;
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.Remote JavaDoc;
30 import javax.ejb.SessionBean JavaDoc;
31 import javax.ejb.SessionContext JavaDoc;
32 import javax.ejb.Stateless JavaDoc;
33
34 import org.jboss.logging.Logger;
35 import org.jboss.annotation.ejb.RemoteBinding;
36 import org.jboss.annotation.security.SecurityDomain;
37 import javax.annotation.security.PermitAll;
38 import javax.annotation.security.RolesAllowed;
39
40 /** A simple session bean for testing unchecked declarative security.
41
42  @author Scott.Stark@jboss.org
43  @version $Revision: 58110 $
44  */

45 @Stateless JavaDoc(name="UncheckedSessionRemoteFirst")
46 @Remote JavaDoc(org.jboss.ejb3.test.security.StatelessSession.class)
47 @RemoteBinding(jndiBinding = "spec.UncheckedSessionRemoteFirst")
48 @SecurityDomain("spec-test")
49 @PermitAll
50 public class UncheckedSessionBeanFirst
51 {
52    Logger log = Logger.getLogger(getClass());
53    
54    @Resource SessionContext JavaDoc sessionContext;
55
56    @RolesAllowed({"Echo"})
57    public String JavaDoc echo(String JavaDoc arg)
58    {
59       log.debug("echo, arg=" + arg);
60       Principal JavaDoc p = sessionContext.getCallerPrincipal();
61       log.debug("echo, callerPrincipal=" + p);
62       boolean isCaller = sessionContext.isCallerInRole("EchoCaller");
63       log.debug("echo, isCallerInRole('EchoCaller')=" + isCaller);
64       return arg;
65    }
66
67    public String JavaDoc forward(String JavaDoc echoArg)
68    {
69       log.debug("forward, echoArg=" + echoArg);
70       return echo(echoArg);
71    }
72
73    public void noop()
74    {
75       log.debug("noop");
76    }
77
78    public void npeError()
79    {
80       log.debug("npeError");
81       Object JavaDoc obj = null;
82       obj.toString();
83    }
84
85    public void unchecked()
86    {
87       Principal JavaDoc p = sessionContext.getCallerPrincipal();
88       log.debug("unchecked, callerPrincipal=" + p);
89    }
90
91    @RolesAllowed({"InternalRole"})
92    public void excluded()
93    {
94       throw new EJBException JavaDoc("excluded, no access should be allowed");
95    }
96
97 }
98
Popular Tags