KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > common > ejbs > stateful > containermanaged > security > SecurityPermissionTester


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: SecurityPermissionTester.java 897 2006-07-20 11:43:13Z pinheirg $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.security;
26
27 import static org.testng.Assert.fail;
28
29 import javax.annotation.security.RunAs;
30 import javax.ejb.EJBAccessException JavaDoc;
31
32 import org.objectweb.easybeans.log.JLog;
33 import org.objectweb.easybeans.log.JLogFactory;
34 import org.objectweb.easybeans.tests.common.ejbs.base.security.ItfSecurityRoles;
35
36 /**
37  * Test if the policies work property.
38  * @author Gisele Pinheiro Souza
39  * @author Eduardo Studzinski Estima de Castro
40  *
41  */

42 @RunAs("secondaryrole")
43 public abstract class SecurityPermissionTester implements ItfSecurityPermissionTester {
44
45     /**
46      * Logger.
47      */

48     private static JLog logger = JLogFactory.getLog(SecurityPermissionTester.class);
49
50
51    /**
52      * The bean used to test the roles.
53      * @return the bean.
54      */

55     public abstract ItfSecurityRoles getBean();
56
57
58     /**
59      * Verifies if the permitAll police works.
60      */

61     public void testPermitAll() {
62         getBean().permitAllAttribute();
63     }
64
65     /**
66      * Verifies if the denyAll police works.
67      */

68     public void testDenyAll() {
69         try{
70             getBean().denyAllAttribute();
71             fail("The method has a denyAll annotation, so the bean cannot call this method.");
72         }catch(EJBAccessException JavaDoc e){
73             logger.debug("The bean threw an expected exception {0}", e);
74         }
75     }
76
77     /**
78      * Verifies if the allowedRoles police for two roles(the role specified in
79      * the RunAs and other role) works.
80      */

81     public void testAllowedRolesWithTwoRoles() {
82         getBean().permitTwoRoles();
83     }
84
85     /**
86      * Verifies if the allowedRoles police for one role(the role that is not
87      * defined in the RunAs) works. The method must throw an exception.
88      */

89     public void testAllowedRolesWithOneRole() {
90         try {
91             getBean().permitOneRole();
92             fail("The method has an allowsRoles annotation that does not contains the value "
93                     + "in secondaryrole defined, so the bean cannot call this method.");
94         } catch (EJBAccessException JavaDoc e) {
95             logger.debug("The bean threw an expected exception {0}", e);
96         }
97     }
98
99
100 }
101
Popular Tags