KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > security > TestSLAnnotationSecurityRoles


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: TestSLAnnotationSecurityRoles.java 979 2006-07-28 13:19:50Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.security;
26
27 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.security.ItfSecurityRolesTester;
28 import org.objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.security.SFSBSecurityRolesTester01;
29 import org.objectweb.easybeans.tests.common.helper.EJBHelper;
30 import org.testng.annotations.BeforeMethod;
31 import org.testng.annotations.Test;
32
33 /**
34  * Verifies if the container manages the security roles defined by annotation,
35  * as well as verifies the methods in the session context related with security.
36  * The bean used during the tests is stateless. The chapter verified is the 17.
37  * @reference JSR 220- FINAL RELEASE
38  * @requirement Application Server must be running; the bean
39  * SLSBSecurityRolesTester and SLSBSecurityRoles must be deployed.
40  * @setup gets the reference of SLSBSecurityRolesTester.
41  * @author Gisele Pinheiro Souza
42  * @author Eduardo Studzinski Estima de Castro
43  */

44 public class TestSLAnnotationSecurityRoles {
45
46     /**
47      * Bean used during the tests.
48      */

49     private ItfSecurityRolesTester tester;
50
51     /**
52      * Creates the stateful bean used during the tests.
53      * @throws Exception if an error occurs during the lookup.
54      */

55     @BeforeMethod
56     public void setup() throws Exception JavaDoc {
57         tester = EJBHelper.getBeanRemoteInstance(SFSBSecurityRolesTester01.class, ItfSecurityRolesTester.class);
58     }
59
60     /**
61      * Test if the permit all role works. The bean call a method with the
62      * annotation permitAll.
63      * @input -
64      * @output the correct method execution.
65      */

66     @Test
67     public void testPermitAll() {
68         tester.testPermitAll();
69     }
70
71     /**
72      * Test if the deny all role works. The bean call a method with the
73      * annotation denyAll.
74      * @input -
75      * @output the correct method execution. The EJBAccessException is verified
76      * in the server site.
77      */

78     @Test
79     public void testDenyAll() {
80         tester.testDenyAll();
81     }
82
83
84     /**
85      * Verifies if the role defined in the roles allowed can access the method. The annotation has only the role defined.
86      * @input -
87      * @output the correct method execution.
88      */

89     @Test
90     public void testAllowedRolesWithOneRole() {
91         tester.testAllowedRolesWithOneRole();
92     }
93
94     /**
95      * Verifies if the role defined in the roles allowed can access the method. The annotation has two roles defined.
96      * @input -
97      * @output the correct method execution.
98      */

99     @Test
100     public void testAllowedRolesWithTwoRoles() {
101         tester.testAllowedRolesWithTwoRoles();
102     }
103
104     /**
105      * Verifies if the correct exception(Runtime or subclass) is thrown when the deprecated method getCallerIdentity is called.
106      * @input -
107      * @output the correct method execution, the exception is verified in the server side.
108      *
109      */

110     @Test
111     public void testGetCallerIdentity() {
112         tester.testGetCallerIdentity();
113     }
114
115     /**
116      * Verifies if the annotation RunAs does not change the current caller for a
117      * class the has the RunAs(bean1). The bean1 call a method in other bean
118      * that returns the caller principal, this caller must be different of the
119      * current bean1 caller.
120      * @input -
121      * @output the correct method execution.
122      */

123     @Test
124     public void testGetCallerPrincipalDifferentCaller() {
125         tester.testGetCallerPrincipalDifferentCaller();
126     }
127
128     /**
129      * Verifies if the caller is propagated among the beans. The bean1(that has
130      * not the annotation RunAs) call the bean2, the both caller principal must
131      * be the same.
132      * @input -
133      * @output the correct method execution.
134      */

135     @Test
136     public void testGetCallerPrincipalSameCaller() {
137         tester.testGetCallerPrincipalSameCaller();
138     }
139
140     /**
141      * Verifies if the isCallerInRole returns true when the correct role name is
142      * used. The bean1 has the annotation RunAs(role1) and call the bean2 that
143      * verifies if the isCallerInRoleMethod(role1) returns true.
144      * @input -
145      * @output the correct method execution.
146      */

147     @Test
148     public void testIsCallerInRoleCorrect() {
149         tester.testIsCallerInRoleCorrect();
150     }
151
152     /**
153      * Verifies if the correct exception(Runtime or subclass) is thrown when the
154      * deprecated method getCallerInRole(Identity identity) is called.
155      * @input -
156      * @output the correct method execution, the exception is verified in the
157      * server side.
158      */

159     @Test
160     public void testIsCallerInRoleDeprecated() {
161         tester.testIsCallerInRoleDeprecated();
162     }
163
164     /**
165      * Verifies if the isCallerInRole returns false when the incorrect role name is
166      * used. The bean1 has the annotation RunAs(role1) and call the bean2 that
167      * verifies if the isCallerInRoleMethod(roleX) returns false.
168      * @input -
169      * @output the correct method execution.
170      */

171     @Test
172     public void testIsCallerInRoleIncorrect() {
173         tester.testIsCallerInRoleIncorrect();
174     }
175 }
176
Popular Tags