KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > test > EJBPermissionUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.security.test;
23
24 import java.rmi.RemoteException JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import javax.security.jacc.EJBMethodPermission JavaDoc;
27 import javax.ejb.CreateException JavaDoc;
28 import javax.ejb.EJBHome JavaDoc;
29 import javax.ejb.EJBObject JavaDoc;
30
31 import junit.framework.TestCase;
32
33 /** Tests of the JAAC EJB*Permissions
34  *
35  * @author Scott.Stark@jboss.org
36  * @version $Revision: 37406 $
37  */

38 public class EJBPermissionUnitTestCase
39    extends TestCase
40 {
41    static interface AHome extends EJBHome JavaDoc
42    {
43       public void create() throws CreateException JavaDoc, RemoteException JavaDoc;
44    }
45    static interface ARemote extends EJBObject JavaDoc
46    {
47       public void methodX() throws RemoteException JavaDoc;
48       public void methodX(int x) throws RemoteException JavaDoc;
49    }
50
51    public EJBPermissionUnitTestCase(String JavaDoc name)
52    {
53       super(name);
54    }
55
56    /** Tests of the EJBMethodPermission(String name, String actions)
57     * @throws Exception
58     */

59    public void testCtor1() throws Exception JavaDoc
60    {
61       EJBMethodPermission JavaDoc p = new EJBMethodPermission JavaDoc("someEJB", null);
62       String JavaDoc actions = p.getActions();
63       assertTrue("actions("+actions+") == null", actions == null);
64
65       p = new EJBMethodPermission JavaDoc("someEJB", "methodX");
66       actions = p.getActions();
67       assertTrue("actions("+actions+") == methodX", actions.equals("methodX"));
68
69       p = new EJBMethodPermission JavaDoc("someEJB", "methodX,,int");
70       actions = p.getActions();
71       assertTrue("actions("+actions+") == methodX,,int",
72          actions.equals("methodX,,int"));
73
74       p = new EJBMethodPermission JavaDoc("someEJB", "methodX,ServiceEndpoint,int");
75       actions = p.getActions();
76       assertTrue("actions("+actions+") == methodX,ServiceEndpoint,int",
77          actions.equals("methodX,ServiceEndpoint,int"));
78
79       p = new EJBMethodPermission JavaDoc("someEJB", "methodX,ServiceEndpoint,");
80       actions = p.getActions();
81       assertTrue("actions("+actions+") == methodX,ServiceEndpoint,",
82          actions.equals("methodX,ServiceEndpoint,"));
83    }
84
85    /** Tests of EJBMethodPermission(String ejbName, String methodInterface, Method method)
86     *
87     * @throws Exception
88     */

89    public void testCtor2() throws Exception JavaDoc
90    {
91       Class JavaDoc[] createSig = {};
92       Method JavaDoc method = AHome.class.getMethod("create", createSig);
93       EJBMethodPermission JavaDoc p = new EJBMethodPermission JavaDoc("someEJB", "Home", method);
94       String JavaDoc actions = p.getActions();
95       assertTrue("actions("+actions+") == create,Home,",
96          actions.equals("create,Home,"));
97
98       Class JavaDoc[] methodXSig = {int.class};
99       Method JavaDoc methodX = ARemote.class.getMethod("methodX", methodXSig);
100       p = new EJBMethodPermission JavaDoc("someEJB", "Remote", methodX);
101       actions = p.getActions();
102       assertTrue("actions("+actions+") == create,Home,",
103          actions.equals("methodX,Remote,int"));
104    }
105
106    /** Tests of EJBMethodPermission(String ejbName, String methodName,
107       String methodInterface, String[] methodParams)
108     @throws Exception
109     */

110    public void testCtor3() throws Exception JavaDoc
111    {
112       String JavaDoc methodName = null;
113       String JavaDoc methodInterface = null;
114       String JavaDoc[] methodParams = null;
115       EJBMethodPermission JavaDoc p = new EJBMethodPermission JavaDoc("someEJB", methodName,
116          methodInterface, methodParams);
117       String JavaDoc actions = p.getActions();
118       assertTrue("actions("+actions+") == null", actions == null);
119
120       methodName = "methodX";
121       methodInterface = null;
122       methodParams = null;
123       p = new EJBMethodPermission JavaDoc("someEJB", methodName,
124          methodInterface, methodParams);
125       actions = p.getActions();
126       assertTrue("actions("+actions+") == methodX", actions.equals("methodX"));
127
128       methodName = "methodX";
129       methodInterface = null;
130       methodParams = new String JavaDoc[0];
131       p = new EJBMethodPermission JavaDoc("someEJB", methodName,
132          methodInterface, methodParams);
133       actions = p.getActions();
134       assertTrue("actions("+actions+") == methodX,,", actions.equals("methodX,,"));
135
136       methodName = "methodX";
137       methodInterface = null;
138       methodParams = new String JavaDoc[]{"int"};
139       p = new EJBMethodPermission JavaDoc("someEJB", methodName,
140          methodInterface, methodParams);
141       actions = p.getActions();
142       assertTrue("actions("+actions+") == methodX,,int",
143          actions.equals("methodX,,int"));
144
145       methodName = "methodX";
146       methodInterface = "ServiceEndpoint";
147       methodParams = new String JavaDoc[]{"int"};
148       p = new EJBMethodPermission JavaDoc("someEJB", methodName,
149          methodInterface, methodParams);
150       actions = p.getActions();
151       assertTrue("actions("+actions+") == methodX,ServiceEndpoint,int",
152          actions.equals("methodX,ServiceEndpoint,int"));
153    }
154
155    public void testImpliesPermission() throws Exception JavaDoc
156    {
157       EJBMethodPermission JavaDoc p0 = new EJBMethodPermission JavaDoc("someEJB", null);
158       EJBMethodPermission JavaDoc p1 = new EJBMethodPermission JavaDoc("someEJB", "methodX");
159       assertTrue("p0.implies(p1)", p0.implies(p1));
160
161       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX");
162       assertTrue("p0.implies(p1)", p0.implies(p1));
163       
164       p0 = new EJBMethodPermission JavaDoc("someEJB", null);
165       p1 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Remote");
166       assertTrue("p0.implies(p1)", p0.implies(p1));
167
168       p1 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Remote,");
169       assertTrue("p0.implies(p1)", p0.implies(p1));
170
171       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX");
172       assertTrue("p0.implies(p1)", p0.implies(p1));
173
174       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Remote");
175       assertTrue("p0.implies(p1)", p0.implies(p1));
176
177       p0 = new EJBMethodPermission JavaDoc("someEJB", null);
178       p1 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Local,int,java.lang.String");
179       assertTrue("p0.implies(p1)", p0.implies(p1));
180
181       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX");
182       assertTrue("p0.implies(p1)", p0.implies(p1));
183
184       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,,int,java.lang.String");
185       assertTrue("p0.implies(p1)", p0.implies(p1));
186
187       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Local");
188       assertTrue("p0.implies(p1)", p0.implies(p1));
189
190       p0 = new EJBMethodPermission JavaDoc("someEJB", ",,int,java.lang.String");
191       assertTrue("p0.implies(p1)", p0.implies(p1));
192
193       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Local,int,java.lang.String");
194       assertTrue("p0.implies(p1)", p0.implies(p1));
195
196       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Local,int,java.lang.String");
197       assertTrue("p0.implies(p1)", p0.implies(p1));
198    }
199
200    public void testNotImpliesPermission() throws Exception JavaDoc
201    {
202       EJBMethodPermission JavaDoc p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX");
203       EJBMethodPermission JavaDoc p1 = new EJBMethodPermission JavaDoc("someEJB", null);
204       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
205
206       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX");
207       p1 = new EJBMethodPermission JavaDoc("someEJB", "methodY");
208       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
209
210       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,,");
211       p1 = new EJBMethodPermission JavaDoc("someEJB", "methodX");
212       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
213
214       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Local");
215       p1 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Remote");
216       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
217
218       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,,int");
219       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
220
221       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Remote");
222       p1 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Local,int,java.lang.String");
223       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
224
225       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,Local,int");
226       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
227
228       p0 = new EJBMethodPermission JavaDoc("someEJB", "methodX,,float,java.lang.String");
229       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
230
231       p0 = new EJBMethodPermission JavaDoc("someEJB", ",,int,java.lang.String2");
232       assertTrue("! p0.implies(p1)", p0.implies(p1) == false);
233    }
234 }
235
Popular Tags