1 22 package org.jboss.test.security.test; 23 24 import java.rmi.RemoteException ; 25 import java.lang.reflect.Method ; 26 import javax.security.jacc.EJBMethodPermission ; 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBHome ; 29 import javax.ejb.EJBObject ; 30 31 import junit.framework.TestCase; 32 33 38 public class EJBPermissionUnitTestCase 39 extends TestCase 40 { 41 static interface AHome extends EJBHome 42 { 43 public void create() throws CreateException , RemoteException ; 44 } 45 static interface ARemote extends EJBObject 46 { 47 public void methodX() throws RemoteException ; 48 public void methodX(int x) throws RemoteException ; 49 } 50 51 public EJBPermissionUnitTestCase(String name) 52 { 53 super(name); 54 } 55 56 59 public void testCtor1() throws Exception 60 { 61 EJBMethodPermission p = new EJBMethodPermission ("someEJB", null); 62 String actions = p.getActions(); 63 assertTrue("actions("+actions+") == null", actions == null); 64 65 p = new EJBMethodPermission ("someEJB", "methodX"); 66 actions = p.getActions(); 67 assertTrue("actions("+actions+") == methodX", actions.equals("methodX")); 68 69 p = new EJBMethodPermission ("someEJB", "methodX,,int"); 70 actions = p.getActions(); 71 assertTrue("actions("+actions+") == methodX,,int", 72 actions.equals("methodX,,int")); 73 74 p = new EJBMethodPermission ("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 ("someEJB", "methodX,ServiceEndpoint,"); 80 actions = p.getActions(); 81 assertTrue("actions("+actions+") == methodX,ServiceEndpoint,", 82 actions.equals("methodX,ServiceEndpoint,")); 83 } 84 85 89 public void testCtor2() throws Exception 90 { 91 Class [] createSig = {}; 92 Method method = AHome.class.getMethod("create", createSig); 93 EJBMethodPermission p = new EJBMethodPermission ("someEJB", "Home", method); 94 String actions = p.getActions(); 95 assertTrue("actions("+actions+") == create,Home,", 96 actions.equals("create,Home,")); 97 98 Class [] methodXSig = {int.class}; 99 Method methodX = ARemote.class.getMethod("methodX", methodXSig); 100 p = new EJBMethodPermission ("someEJB", "Remote", methodX); 101 actions = p.getActions(); 102 assertTrue("actions("+actions+") == create,Home,", 103 actions.equals("methodX,Remote,int")); 104 } 105 106 110 public void testCtor3() throws Exception 111 { 112 String methodName = null; 113 String methodInterface = null; 114 String [] methodParams = null; 115 EJBMethodPermission p = new EJBMethodPermission ("someEJB", methodName, 116 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.equals("methodX")); 127 128 methodName = "methodX"; 129 methodInterface = null; 130 methodParams = new String [0]; 131 p = new EJBMethodPermission ("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 []{"int"}; 139 p = new EJBMethodPermission ("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 []{"int"}; 148 p = new EJBMethodPermission ("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 156 { 157 EJBMethodPermission p0 = new EJBMethodPermission ("someEJB", null); 158 EJBMethodPermission p1 = new EJBMethodPermission ("someEJB", "methodX"); 159 assertTrue("p0.implies(p1)", p0.implies(p1)); 160 161 p0 = new EJBMethodPermission ("someEJB", "methodX"); 162 assertTrue("p0.implies(p1)", p0.implies(p1)); 163 164 p0 = new EJBMethodPermission ("someEJB", null); 165 p1 = new EJBMethodPermission ("someEJB", "methodX,Remote"); 166 assertTrue("p0.implies(p1)", p0.implies(p1)); 167 168 p1 = new EJBMethodPermission ("someEJB", "methodX,Remote,"); 169 assertTrue("p0.implies(p1)", p0.implies(p1)); 170 171 p0 = new EJBMethodPermission ("someEJB", "methodX"); 172 assertTrue("p0.implies(p1)", p0.implies(p1)); 173 174 p0 = new EJBMethodPermission ("someEJB", "methodX,Remote"); 175 assertTrue("p0.implies(p1)", p0.implies(p1)); 176 177 p0 = new EJBMethodPermission ("someEJB", null); 178 p1 = new EJBMethodPermission ("someEJB", "methodX,Local,int,java.lang.String"); 179 assertTrue("p0.implies(p1)", p0.implies(p1)); 180 181 p0 = new EJBMethodPermission ("someEJB", "methodX"); 182 assertTrue("p0.implies(p1)", p0.implies(p1)); 183 184 p0 = new EJBMethodPermission ("someEJB", "methodX,,int,java.lang.String"); 185 assertTrue("p0.implies(p1)", p0.implies(p1)); 186 187 p0 = new EJBMethodPermission ("someEJB", "methodX,Local"); 188 assertTrue("p0.implies(p1)", p0.implies(p1)); 189 190 p0 = new EJBMethodPermission ("someEJB", ",,int,java.lang.String"); 191 assertTrue("p0.implies(p1)", p0.implies(p1)); 192 193 p0 = new EJBMethodPermission ("someEJB", "methodX,Local,int,java.lang.String"); 194 assertTrue("p0.implies(p1)", p0.implies(p1)); 195 196 p0 = new EJBMethodPermission ("someEJB", "methodX,Local,int,java.lang.String"); 197 assertTrue("p0.implies(p1)", p0.implies(p1)); 198 } 199 200 public void testNotImpliesPermission() throws Exception 201 { 202 EJBMethodPermission p0 = new EJBMethodPermission ("someEJB", "methodX"); 203 EJBMethodPermission p1 = new EJBMethodPermission ("someEJB", null); 204 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 205 206 p0 = new EJBMethodPermission ("someEJB", "methodX"); 207 p1 = new EJBMethodPermission ("someEJB", "methodY"); 208 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 209 210 p0 = new EJBMethodPermission ("someEJB", "methodX,,"); 211 p1 = new EJBMethodPermission ("someEJB", "methodX"); 212 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 213 214 p0 = new EJBMethodPermission ("someEJB", "methodX,Local"); 215 p1 = new EJBMethodPermission ("someEJB", "methodX,Remote"); 216 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 217 218 p0 = new EJBMethodPermission ("someEJB", "methodX,,int"); 219 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 220 221 p0 = new EJBMethodPermission ("someEJB", "methodX,Remote"); 222 p1 = new EJBMethodPermission ("someEJB", "methodX,Local,int,java.lang.String"); 223 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 224 225 p0 = new EJBMethodPermission ("someEJB", "methodX,Local,int"); 226 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 227 228 p0 = new EJBMethodPermission ("someEJB", "methodX,,float,java.lang.String"); 229 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 230 231 p0 = new EJBMethodPermission ("someEJB", ",,int,java.lang.String2"); 232 assertTrue("! p0.implies(p1)", p0.implies(p1) == false); 233 } 234 } 235 | Popular Tags |