001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: TestSFAnnotationSecurityRoles.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.security;
025:
026: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.security.ItfSecurityRolesTester;
027: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.security.SFSBSecurityRolesTester00;
028: import org.ow2.easybeans.tests.common.helper.EJBHelper;
029: import org.testng.annotations.BeforeMethod;
030: import org.testng.annotations.Test;
031:
032: /**
033: * Verifies if the container manages the security roles defined by annotation,
034: * as well as verifies the methods in the session context related with security.
035: * The bean used during the tests is stateless. The chapter verified is the 17.
036: * @reference JSR 220- FINAL RELEASE
037: * @requirement Application Server must be running; the bean
038: * SLSBSecurityRolesTester and SLSBSecurityRoles must be deployed.
039: * @setup gets the reference of SLSBSecurityRolesTester.
040: * @author Gisele Pinheiro Souza
041: * @author Eduardo Studzinski Estima de Castro
042: */
043: public class TestSFAnnotationSecurityRoles {
044:
045: /**
046: * Bean used during the tests.
047: */
048: private ItfSecurityRolesTester tester;
049:
050: /**
051: * Creates the stateful bean used during the tests.
052: * @throws Exception if an error occurs during the lookup.
053: */
054: @BeforeMethod
055: public void setup() throws Exception {
056: tester = EJBHelper.getBeanRemoteInstance(
057: SFSBSecurityRolesTester00.class,
058: ItfSecurityRolesTester.class);
059: }
060:
061: /**
062: * Test if the permit all role works. The bean call a method with the
063: * annotation permitAll.
064: * @input -
065: * @output the correct method execution.
066: */
067: @Test
068: public void testPermitAll() {
069: tester.testPermitAll();
070: }
071:
072: /**
073: * Test if the deny all role works. The bean call a method with the
074: * annotation denyAll.
075: * @input -
076: * @output the correct method execution. The EJBAccessException is verified
077: * in the server site.
078: */
079: @Test
080: public void testDenyAll() {
081: tester.testDenyAll();
082: }
083:
084: /**
085: * Verifies if the role defined in the roles allowed can access the method. The annotation has only the role defined.
086: * @input -
087: * @output the correct method execution.
088: */
089: @Test
090: public void testAllowedRolesWithOneRole() {
091: tester.testAllowedRolesWithOneRole();
092: }
093:
094: /**
095: * Verifies if the role defined in the roles allowed at bean level can access the method.
096: * The annotation has only the role defined.
097: * @input -
098: * @output the correct method execution.
099: */
100: @Test
101: public void testAllowedRolesDeclaredAtBeanLevel() {
102: tester.testAllowedRolesDeclaredAtBeanLevel();
103: }
104:
105: /**
106: * Verifies if the role defined in the roles allowed can access the method. The annotation has two roles defined.
107: * @input -
108: * @output the correct method execution.
109: */
110: @Test
111: public void testAllowedRolesWithTwoRoles() {
112: tester.testAllowedRolesWithTwoRoles();
113: }
114:
115: /**
116: * Verifies if the correct exception(Runtime or subclass) is thrown when the deprecated method getCallerIdentity is called.
117: * @input -
118: * @output the correct method execution, the exception is verified in the server side.
119: *
120: */
121: @Test
122: public void testGetCallerIdentity() {
123: tester.testGetCallerIdentity();
124: }
125:
126: /**
127: * Verifies if the annotation RunAs does not change the current caller for a
128: * class the has the RunAs(bean1). The bean1 call a method in other bean
129: * that returns the caller principal, this caller must be different of the
130: * current bean1 caller.
131: * @input -
132: * @output the correct method execution.
133: */
134: @Test
135: public void testGetCallerPrincipalDifferentCaller() {
136: tester.testGetCallerPrincipalDifferentCaller();
137: }
138:
139: /**
140: * Verifies if the caller is propagated among the beans. The bean1(that has
141: * not the annotation RunAs) call the bean2, the both caller principal must
142: * be the same.
143: * @input -
144: * @output the correct method execution.
145: */
146: @Test
147: public void testGetCallerPrincipalSameCaller() {
148: tester.testGetCallerPrincipalSameCaller();
149: }
150:
151: /**
152: * Verifies if the isCallerInRole returns true when the correct role name is
153: * used. The bean1 has the annotation RunAs(role1) and call the bean2 that
154: * verifies if the isCallerInRoleMethod(role1) returns true.
155: * @input -
156: * @output the correct method execution.
157: */
158: @Test
159: public void testIsCallerInRoleCorrect() {
160: tester.testIsCallerInRoleCorrect();
161: }
162:
163: /**
164: * Verifies if the correct exception(Runtime or subclass) is thrown when the
165: * deprecated method getCallerInRole(Identity identity) is called.
166: * @input -
167: * @output the correct method execution, the exception is verified in the
168: * server side.
169: */
170: @Test
171: public void testIsCallerInRoleDeprecated() {
172: tester.testIsCallerInRoleDeprecated();
173: }
174:
175: /**
176: * Verifies if the isCallerInRole returns false when the incorrect role name is
177: * used. The bean1 has the annotation RunAs(role1) and call the bean2 that
178: * verifies if the isCallerInRoleMethod(roleX) returns false.
179: * @input -
180: * @output the correct method execution.
181: */
182: @Test
183: public void testIsCallerInRoleIncorrect() {
184: tester.testIsCallerInRoleIncorrect();
185: }
186: }
|