1 45 package org.openejb.test.entity.cmp; 46 47 import java.rmi.RemoteException ; 48 import java.util.Hashtable ; 49 import java.util.Properties ; 50 import java.util.StringTokenizer ; 51 52 import javax.ejb.EJBException ; 53 import javax.ejb.EntityContext ; 54 import javax.ejb.RemoveException ; 55 56 import org.openejb.test.object.OperationsPolicy; 57 58 63 public class AllowedOperationsCmpBean implements javax.ejb.EntityBean { 64 65 public static int key = 20; 66 67 public int primaryKey; 68 public String firstName; 69 public String lastName; 70 public EntityContext ejbContext; 71 public Hashtable allowedOperationsTable = new Hashtable (); 72 73 74 78 88 public int ejbHomeSum(int x, int y) { 89 testAllowedOperations("ejbHome"); 90 return x+y; 91 } 92 93 101 public Integer ejbCreate(String name) 102 throws javax.ejb.CreateException { 103 testAllowedOperations("ejbCreate"); 104 StringTokenizer st = new StringTokenizer (name, " "); 105 firstName = st.nextToken(); 106 lastName = st.nextToken(); 107 this.primaryKey = key++; 108 return new Integer (primaryKey); 109 } 110 111 public void ejbPostCreate(String name) 112 throws javax.ejb.CreateException { 113 } 114 115 119 120 124 130 public String businessMethod(String text){ 131 testAllowedOperations("businessMethod"); 132 StringBuffer b = new StringBuffer (text); 133 return b.reverse().toString(); 134 } 135 136 140 public void throwApplicationException() throws org.openejb.test.ApplicationException{ 141 throw new org.openejb.test.ApplicationException("Don't Panic"); 142 } 143 144 151 public void throwSystemException_NullPointer() { 152 throw new NullPointerException ("Panic"); 153 } 154 155 156 165 public Properties getPermissionsReport(){ 166 167 return null; 168 } 169 170 180 public OperationsPolicy getAllowedOperationsReport(String methodName){ 181 return (OperationsPolicy) allowedOperationsTable.get(methodName); 182 } 183 184 188 189 193 198 public void ejbLoad() throws EJBException ,RemoteException { 199 testAllowedOperations("ejbLoad"); 200 } 201 202 206 public void setEntityContext(EntityContext ctx) throws EJBException ,RemoteException { 207 ejbContext = ctx; 208 testAllowedOperations("setEntityContext"); 209 } 210 211 215 public void unsetEntityContext() throws EJBException ,RemoteException { 216 testAllowedOperations("unsetEntityContext"); 217 } 218 219 224 public void ejbStore() throws EJBException ,RemoteException { 225 testAllowedOperations("ejbStore"); 226 } 227 228 236 public void ejbRemove() throws RemoveException ,EJBException ,RemoteException { 237 testAllowedOperations("ejbRemove"); 238 } 239 240 246 public void ejbActivate() throws EJBException ,RemoteException { 247 testAllowedOperations("ejbActivate"); 248 } 249 250 256 public void ejbPassivate() throws EJBException ,RemoteException { 257 258 testAllowedOperations("ejbPassivate"); 259 } 260 264 protected void testAllowedOperations(String methodName){ 265 OperationsPolicy policy = new OperationsPolicy(); 266 267 268 try{ 269 ejbContext.getEJBHome(); 270 policy.allow(policy.Context_getEJBHome); 271 }catch(IllegalStateException ise){} 272 273 274 try{ 275 ejbContext.getCallerPrincipal(); 276 policy.allow( policy.Context_getCallerPrincipal ); 277 }catch(IllegalStateException ise){} 278 279 280 try{ 281 ejbContext.isCallerInRole("ROLE"); 282 policy.allow( policy.Context_isCallerInRole ); 283 }catch(IllegalStateException ise){} 284 285 286 try{ 287 ejbContext.getRollbackOnly(); 288 policy.allow( policy.Context_getRollbackOnly ); 289 }catch(IllegalStateException ise){} 290 291 292 try{ 293 ejbContext.setRollbackOnly(); 294 policy.allow( policy.Context_setRollbackOnly ); 295 }catch(IllegalStateException ise){} 296 297 298 try{ 299 ejbContext.getUserTransaction(); 300 policy.allow( policy.Context_getUserTransaction ); 301 }catch(Exception e){} 302 303 304 try{ 305 ejbContext.getEJBObject(); 306 policy.allow( policy.Context_getEJBObject ); 307 }catch(IllegalStateException ise){} 308 309 310 try{ 311 ejbContext.getPrimaryKey(); 312 policy.allow( policy.Context_getPrimaryKey ); 313 }catch(IllegalStateException ise){} 314 315 320 allowedOperationsTable.put(methodName, policy); 321 } 322 323 } 324 | Popular Tags |