001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.security.test;
023:
024: import java.rmi.RemoteException;
025: import java.lang.reflect.Method;
026: import javax.security.jacc.EJBMethodPermission;
027: import javax.ejb.CreateException;
028: import javax.ejb.EJBHome;
029: import javax.ejb.EJBObject;
030:
031: import junit.framework.TestCase;
032:
033: /** Tests of the JAAC EJB*Permissions
034: *
035: * @author Scott.Stark@jboss.org
036: * @version $Revision: 57211 $
037: */
038: public class EJBPermissionUnitTestCase extends TestCase {
039: static interface AHome extends EJBHome {
040: public void create() throws CreateException, RemoteException;
041: }
042:
043: static interface ARemote extends EJBObject {
044: public void methodX() throws RemoteException;
045:
046: public void methodX(int x) throws RemoteException;
047: }
048:
049: public EJBPermissionUnitTestCase(String name) {
050: super (name);
051: }
052:
053: /** Tests of the EJBMethodPermission(String name, String actions)
054: * @throws Exception
055: */
056: public void testCtor1() throws Exception {
057: EJBMethodPermission p = new EJBMethodPermission("someEJB", null);
058: String actions = p.getActions();
059: assertTrue("actions(" + actions + ") == null", actions == null);
060:
061: p = new EJBMethodPermission("someEJB", "methodX");
062: actions = p.getActions();
063: assertTrue("actions(" + actions + ") == methodX", actions
064: .equals("methodX"));
065:
066: p = new EJBMethodPermission("someEJB", "methodX,,int");
067: actions = p.getActions();
068: assertTrue("actions(" + actions + ") == methodX,,int", actions
069: .equals("methodX,,int"));
070:
071: p = new EJBMethodPermission("someEJB",
072: "methodX,ServiceEndpoint,int");
073: actions = p.getActions();
074: assertTrue("actions(" + actions
075: + ") == methodX,ServiceEndpoint,int", actions
076: .equals("methodX,ServiceEndpoint,int"));
077:
078: p = new EJBMethodPermission("someEJB",
079: "methodX,ServiceEndpoint,");
080: actions = p.getActions();
081: assertTrue("actions(" + actions
082: + ") == methodX,ServiceEndpoint,", actions
083: .equals("methodX,ServiceEndpoint,"));
084: }
085:
086: /** Tests of EJBMethodPermission(String ejbName, String methodInterface, Method method)
087: *
088: * @throws Exception
089: */
090: public void testCtor2() throws Exception {
091: Class[] createSig = {};
092: Method method = AHome.class.getMethod("create", createSig);
093: EJBMethodPermission p = new EJBMethodPermission("someEJB",
094: "Home", method);
095: String actions = p.getActions();
096: assertTrue("actions(" + actions + ") == create,Home,", actions
097: .equals("create,Home,"));
098:
099: Class[] methodXSig = { int.class };
100: Method methodX = ARemote.class.getMethod("methodX", methodXSig);
101: p = new EJBMethodPermission("someEJB", "Remote", methodX);
102: actions = p.getActions();
103: assertTrue("actions(" + actions + ") == create,Home,", actions
104: .equals("methodX,Remote,int"));
105: }
106:
107: /** Tests of EJBMethodPermission(String ejbName, String methodName,
108: String methodInterface, String[] methodParams)
109: @throws Exception
110: */
111: public void testCtor3() throws Exception {
112: String methodName = null;
113: String methodInterface = null;
114: String[] methodParams = null;
115: EJBMethodPermission p = new EJBMethodPermission("someEJB",
116: methodName, methodInterface, methodParams);
117: String actions = p.getActions();
118: assertTrue("actions(" + actions + ") == null", actions == null);
119:
120: methodName = "methodX";
121: methodInterface = null;
122: methodParams = null;
123: p = new EJBMethodPermission("someEJB", methodName,
124: methodInterface, methodParams);
125: actions = p.getActions();
126: assertTrue("actions(" + actions + ") == methodX", actions
127: .equals("methodX"));
128:
129: methodName = "methodX";
130: methodInterface = null;
131: methodParams = new String[0];
132: p = new EJBMethodPermission("someEJB", methodName,
133: methodInterface, methodParams);
134: actions = p.getActions();
135: assertTrue("actions(" + actions + ") == methodX,,", actions
136: .equals("methodX,,"));
137:
138: methodName = "methodX";
139: methodInterface = null;
140: methodParams = new String[] { "int" };
141: p = new EJBMethodPermission("someEJB", methodName,
142: methodInterface, methodParams);
143: actions = p.getActions();
144: assertTrue("actions(" + actions + ") == methodX,,int", actions
145: .equals("methodX,,int"));
146:
147: methodName = "methodX";
148: methodInterface = "ServiceEndpoint";
149: methodParams = new String[] { "int" };
150: p = new EJBMethodPermission("someEJB", methodName,
151: methodInterface, methodParams);
152: actions = p.getActions();
153: assertTrue("actions(" + actions
154: + ") == methodX,ServiceEndpoint,int", actions
155: .equals("methodX,ServiceEndpoint,int"));
156: }
157:
158: public void testImpliesPermission() throws Exception {
159: EJBMethodPermission p0 = new EJBMethodPermission("someEJB",
160: null);
161: EJBMethodPermission p1 = new EJBMethodPermission("someEJB",
162: "methodX");
163: assertTrue("p0.implies(p1)", p0.implies(p1));
164:
165: p0 = new EJBMethodPermission("someEJB", "methodX");
166: assertTrue("p0.implies(p1)", p0.implies(p1));
167:
168: p0 = new EJBMethodPermission("someEJB", null);
169: p1 = new EJBMethodPermission("someEJB", "methodX,Remote");
170: assertTrue("p0.implies(p1)", p0.implies(p1));
171:
172: p1 = new EJBMethodPermission("someEJB", "methodX,Remote,");
173: assertTrue("p0.implies(p1)", p0.implies(p1));
174:
175: p0 = new EJBMethodPermission("someEJB", "methodX");
176: assertTrue("p0.implies(p1)", p0.implies(p1));
177:
178: p0 = new EJBMethodPermission("someEJB", "methodX,Remote");
179: assertTrue("p0.implies(p1)", p0.implies(p1));
180:
181: p0 = new EJBMethodPermission("someEJB", null);
182: p1 = new EJBMethodPermission("someEJB",
183: "methodX,Local,int,java.lang.String");
184: assertTrue("p0.implies(p1)", p0.implies(p1));
185:
186: p0 = new EJBMethodPermission("someEJB", "methodX");
187: assertTrue("p0.implies(p1)", p0.implies(p1));
188:
189: p0 = new EJBMethodPermission("someEJB",
190: "methodX,,int,java.lang.String");
191: assertTrue("p0.implies(p1)", p0.implies(p1));
192:
193: p0 = new EJBMethodPermission("someEJB", "methodX,Local");
194: assertTrue("p0.implies(p1)", p0.implies(p1));
195:
196: p0 = new EJBMethodPermission("someEJB",
197: ",,int,java.lang.String");
198: assertTrue("p0.implies(p1)", p0.implies(p1));
199:
200: p0 = new EJBMethodPermission("someEJB",
201: "methodX,Local,int,java.lang.String");
202: assertTrue("p0.implies(p1)", p0.implies(p1));
203:
204: p0 = new EJBMethodPermission("someEJB",
205: "methodX,Local,int,java.lang.String");
206: assertTrue("p0.implies(p1)", p0.implies(p1));
207: }
208:
209: public void testNotImpliesPermission() throws Exception {
210: EJBMethodPermission p0 = new EJBMethodPermission("someEJB",
211: "methodX");
212: EJBMethodPermission p1 = new EJBMethodPermission("someEJB",
213: null);
214: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
215:
216: p0 = new EJBMethodPermission("someEJB", "methodX");
217: p1 = new EJBMethodPermission("someEJB", "methodY");
218: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
219:
220: p0 = new EJBMethodPermission("someEJB", "methodX,,");
221: p1 = new EJBMethodPermission("someEJB", "methodX");
222: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
223:
224: p0 = new EJBMethodPermission("someEJB", "methodX,Local");
225: p1 = new EJBMethodPermission("someEJB", "methodX,Remote");
226: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
227:
228: p0 = new EJBMethodPermission("someEJB", "methodX,,int");
229: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
230:
231: p0 = new EJBMethodPermission("someEJB", "methodX,Remote");
232: p1 = new EJBMethodPermission("someEJB",
233: "methodX,Local,int,java.lang.String");
234: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
235:
236: p0 = new EJBMethodPermission("someEJB", "methodX,Local,int");
237: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
238:
239: p0 = new EJBMethodPermission("someEJB",
240: "methodX,,float,java.lang.String");
241: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
242:
243: p0 = new EJBMethodPermission("someEJB",
244: ",,int,java.lang.String2");
245: assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
246: }
247: }
|