KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestSFAnnotationSecurityRoles.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.SFSBSecurityRolesTester00;
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 TestSFAnnotationSecurityRoles {
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(SFSBSecurityRolesTester00.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      * Verifies if the role defined in the roles allowed can access the method. The annotation has only the role defined.
85      * @input -
86      * @output the correct method execution.
87      */

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

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

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

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

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

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

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

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