1 45 package org.openejb.test.entity.bmp; 46 47 import java.rmi.RemoteException ; 48 import java.util.Hashtable ; 49 import java.util.Properties ; 50 51 import javax.ejb.EJBException ; 52 import javax.ejb.EntityContext ; 53 import javax.ejb.RemoveException ; 54 import javax.naming.InitialContext ; 55 import javax.sql.DataSource ; 56 57 import org.openejb.test.object.OperationsPolicy; 58 59 64 public class AllowedOperationsBmpBean implements javax.ejb.EntityBean { 65 66 private int primaryKey; 67 private String firstName; 68 private String lastName; 69 private EntityContext ejbContext; 70 private Hashtable allowedOperationsTable = new Hashtable (); 71 72 73 77 87 public int ejbHomeSum(int x, int y) { 88 testAllowedOperations("ejbHome"); 89 return x+y; 90 } 91 92 98 public java.util.Collection ejbFindEmptyCollection() 99 throws javax.ejb.FinderException , java.rmi.RemoteException { 100 return new java.util.Vector (); 101 } 102 103 public java.util.Enumeration ejbFindEmptyEnumeration() 104 throws javax.ejb.FinderException 105 { 106 return (new java.util.Vector ()).elements(); 107 } 108 109 public java.util.Collection ejbFindByLastName(String lastName) 110 throws javax.ejb.FinderException { 111 return new java.util.Vector (); 112 } 113 114 121 public Integer ejbFindByPrimaryKey(Integer primaryKey) 122 throws javax.ejb.FinderException { 123 testAllowedOperations("ejbFind"); 124 return new Integer (-1); 125 } 126 127 134 public Integer ejbCreate(String name) 135 throws javax.ejb.CreateException { 136 testAllowedOperations("ejbCreate"); 137 138 return new Integer (-1); 139 } 140 141 public void ejbPostCreate(String name) 142 throws javax.ejb.CreateException { 143 } 144 145 149 150 154 159 public String businessMethod(String text){ 160 testAllowedOperations("businessMethod"); 161 StringBuffer b = new StringBuffer (text); 162 return b.reverse().toString(); 163 } 164 165 169 public void throwApplicationException() throws org.openejb.test.ApplicationException{ 170 throw new org.openejb.test.ApplicationException("Don't Panic"); 171 } 172 173 180 public void throwSystemException_NullPointer() { 181 throw new NullPointerException ("Panic"); 182 } 183 184 185 193 public Properties getPermissionsReport(){ 194 195 return null; 196 } 197 198 207 public OperationsPolicy getAllowedOperationsReport(String methodName){ 208 return (OperationsPolicy) allowedOperationsTable.get(methodName); 209 } 210 211 215 216 220 225 public void ejbLoad() throws EJBException ,RemoteException { 226 testAllowedOperations("ejbLoad"); 227 } 228 229 233 public void setEntityContext(EntityContext ctx) throws EJBException ,RemoteException { 234 ejbContext = ctx; 235 testAllowedOperations("setEntityContext"); 236 } 237 238 242 public void unsetEntityContext() throws EJBException ,RemoteException { 243 testAllowedOperations("unsetEntityContext"); 244 } 245 246 251 public void ejbStore() throws EJBException ,RemoteException { 252 testAllowedOperations("ejbStore"); 253 } 254 255 263 public void ejbRemove() throws RemoveException ,EJBException ,RemoteException { 264 testAllowedOperations("ejbRemove"); 265 } 266 267 273 public void ejbActivate() throws EJBException ,RemoteException { 274 testAllowedOperations("ejbActivate"); 275 } 276 277 283 public void ejbPassivate() throws EJBException ,RemoteException { 284 285 testAllowedOperations("ejbPassivate"); 286 } 287 291 protected void testAllowedOperations(String methodName) { 292 OperationsPolicy policy = new OperationsPolicy(); 293 294 295 try { 296 ejbContext.getEJBHome(); 297 policy.allow(policy.Context_getEJBHome); 298 } catch (IllegalStateException ise) { 299 } 300 301 302 try { 303 ejbContext.getCallerPrincipal(); 304 policy.allow( policy.Context_getCallerPrincipal ); 305 } catch (IllegalStateException ise) { 306 } 307 308 309 try { 310 ejbContext.isCallerInRole("ROLE"); 311 policy.allow( policy.Context_isCallerInRole ); 312 } catch (IllegalStateException ise) { 313 } 314 315 316 try { 317 ejbContext.getRollbackOnly(); 318 policy.allow( policy.Context_getRollbackOnly ); 319 } catch (IllegalStateException ise) { 320 } 321 322 323 try { 324 ejbContext.setRollbackOnly(); 325 policy.allow( policy.Context_setRollbackOnly ); 326 } catch (IllegalStateException ise) { 327 } 328 329 330 try { 331 ejbContext.getUserTransaction(); 332 policy.allow( policy.Context_getUserTransaction ); 333 } catch (IllegalStateException ise) { 334 } 335 336 337 try { 338 ejbContext.getEJBObject(); 339 policy.allow( policy.Context_getEJBObject ); 340 } catch (IllegalStateException ise) { 341 } 342 343 347 try { 348 ejbContext.getPrimaryKey(); 349 policy.allow( policy.Context_getPrimaryKey ); 350 } catch (IllegalStateException ise) { 351 } 352 353 354 try { 355 InitialContext jndiContext = new InitialContext (); 356 357 String actual = (String )jndiContext.lookup("java:comp/env/stateless/references/JNDI_access_to_java_comp_env"); 358 359 policy.allow( policy.JNDI_access_to_java_comp_env ); 360 } catch (IllegalStateException ise) { 361 } catch (javax.naming.NamingException ne) { 362 } 363 364 365 try { 366 InitialContext jndiContext = new InitialContext ( ); 367 368 DataSource ds = (DataSource )jndiContext.lookup("java:comp/env/stateless/references/Resource_manager_access"); 369 370 policy.allow( policy.Resource_manager_access ); 371 } catch (IllegalStateException ise) { 372 } catch (javax.naming.NamingException ne) { 373 } 374 375 376 try { 377 InitialContext jndiContext = new InitialContext ( ); 378 379 Object obj = jndiContext.lookup("java:comp/env/stateless/beanReferences/Enterprise_bean_access"); 380 381 policy.allow( policy.Enterprise_bean_access ); 382 } catch (IllegalStateException ise) { 383 } catch (javax.naming.NamingException ne) { 384 } 385 386 allowedOperationsTable.put(methodName, policy); 387 } 388 389 } 390 | Popular Tags |