KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateless > containermanaged > security > SLSBSecurityInheritanceTester01


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SLSBSecurityInheritanceTester01.java 904 2006-07-20 14:26:37Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.security;
26
27 import static org.testng.Assert.fail;
28
29 import javax.annotation.security.RunAs;
30 import javax.ejb.EJB JavaDoc;
31 import javax.ejb.EJBAccessException JavaDoc;
32 import javax.ejb.Remote JavaDoc;
33 import javax.ejb.Stateless JavaDoc;
34
35 import org.objectweb.easybeans.log.JLog;
36 import org.objectweb.easybeans.log.JLogFactory;
37
38 /**
39  * Verifies the inheritance for security polices.
40  * @author Gisele Pinheiro Souza
41  * @author Eduardo Studzinski Estima de Castro
42  */

43 @RunAs("secondaryrole")
44 @Stateless JavaDoc
45 @Remote JavaDoc
46 public class SLSBSecurityInheritanceTester01 implements ItfSecurityInheritanceTester {
47
48     /**
49      * Logger.
50      */

51     private static JLog logger = JLogFactory.getLog(SLSBSecurityInheritanceTester01.class);
52
53     /**
54      * The bean used in the tests.
55      */

56     @EJB JavaDoc
57     private ItfSecurityInheritance bean;
58
59     /**
60      * Verifies if a method that has the deny all police defined cannot be
61      * called.
62      */

63     public void callMethodDenyAll() {
64         try {
65             bean.dummyMethod1();
66             fail("The method has a denyAll annotation, so the bean cannot call this method.");
67         } catch (EJBAccessException JavaDoc e) {
68             logger.debug("The bean threw an expected exception {0}", e);
69         }
70     }
71
72     /**
73      * Verifies if method that does not allow the role secondaryrole can be
74      * called by a bean with the annotation RunAs("secondaryrole").
75      */

76     public void callMethodMainRole() {
77         try {
78             bean.dummyMethod2();
79             fail("The method has a rolesAllowed annotation that does not "
80                     + "include the secondaryrole, so the bean cannot call this method.");
81         } catch (EJBAccessException JavaDoc e) {
82             logger.debug("The bean threw an expected exception {0}", e);
83         }
84     }
85
86     /**
87      * Verifies if a method with permitAll annotation can be called by everyone.
88      */

89     public void callMethodPermitAll() {
90         bean.dummyMethod3();
91     }
92 }
93
Popular Tags