1 45 package org.openejb.test.stateless; 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.SessionContext ; 53 import javax.naming.InitialContext ; 54 import javax.sql.DataSource ; 55 56 import org.openejb.test.ApplicationException; 57 import org.openejb.test.object.OperationsPolicy; 58 59 64 public class BasicStatelessBean implements javax.ejb.SessionBean { 65 66 private String name; 67 private SessionContext ejbContext; 68 private Hashtable allowedOperationsTable = new Hashtable (); 69 70 71 78 79 88 public String businessMethod(String text){ 89 testAllowedOperations("businessMethod"); 90 StringBuffer b = new StringBuffer (text); 91 return b.reverse().toString(); 92 } 93 94 95 99 public void throwApplicationException() throws ApplicationException{ 100 throw new ApplicationException("Testing ability to throw Application Exceptions"); 101 } 102 103 110 public void throwSystemException_NullPointer() { 111 throw new NullPointerException ("Testing ability to throw System Exceptions"); 112 } 113 114 123 public Properties getPermissionsReport(){ 124 125 return null; 126 } 127 128 138 public OperationsPolicy getAllowedOperationsReport(String methodName){ 139 return (OperationsPolicy) allowedOperationsTable.get(methodName); 140 } 141 142 146 147 154 public void setSessionContext(SessionContext ctx) throws EJBException ,RemoteException { 155 ejbContext = ctx; 156 testAllowedOperations("setSessionContext"); 157 } 158 163 public void ejbCreate() throws javax.ejb.CreateException { 164 testAllowedOperations("ejbCreate"); 165 this.name = "nameless automaton"; 166 } 167 173 public void ejbRemove() throws EJBException ,RemoteException { 174 testAllowedOperations("ejbRemove"); 175 } 176 177 182 public void ejbActivate() throws EJBException ,RemoteException { 183 testAllowedOperations("ejbActivate"); 184 } 186 191 public void ejbPassivate() throws EJBException ,RemoteException { 192 testAllowedOperations("ejbPassivate"); 193 } 195 196 200 protected void testAllowedOperations(String methodName) { 201 OperationsPolicy policy = new OperationsPolicy(); 202 203 204 try { 205 ejbContext.getEJBHome(); 206 policy.allow(policy.Context_getEJBHome); 207 } catch (IllegalStateException ise) { 208 } 209 210 211 try { 212 ejbContext.getCallerPrincipal(); 213 policy.allow( policy.Context_getCallerPrincipal ); 214 } catch (IllegalStateException ise) { 215 } 216 217 218 try { 219 ejbContext.isCallerInRole("ROLE"); 220 policy.allow( policy.Context_isCallerInRole ); 221 } catch (IllegalStateException ise) { 222 } 223 224 225 try { 226 ejbContext.getRollbackOnly(); 227 policy.allow( policy.Context_getRollbackOnly ); 228 } catch (IllegalStateException ise) { 229 } 230 231 232 try { 233 ejbContext.setRollbackOnly(); 234 policy.allow( policy.Context_setRollbackOnly ); 235 } catch (IllegalStateException ise) { 236 } 237 238 239 try { 240 ejbContext.getUserTransaction(); 241 policy.allow( policy.Context_getUserTransaction ); 242 } catch (IllegalStateException ise) { 243 } 244 245 246 try { 247 ejbContext.getEJBObject(); 248 policy.allow( policy.Context_getEJBObject ); 249 } catch (IllegalStateException ise) { 250 } 251 252 256 257 258 try { 259 InitialContext jndiContext = new InitialContext (); 260 261 String actual = (String )jndiContext.lookup("java:comp/env/stateless/references/JNDI_access_to_java_comp_env"); 262 263 policy.allow( policy.JNDI_access_to_java_comp_env ); 264 } catch (IllegalStateException ise) { 265 } catch (javax.naming.NamingException ne) { 266 } 267 268 269 try { 270 InitialContext jndiContext = new InitialContext ( ); 271 272 DataSource ds = (DataSource )jndiContext.lookup("java:comp/env/stateless/references/Resource_manager_access"); 273 274 policy.allow( policy.Resource_manager_access ); 275 } catch (IllegalStateException ise) { 276 } catch (javax.naming.NamingException ne) { 277 } 278 279 280 try { 281 InitialContext jndiContext = new InitialContext ( ); 282 283 Object obj = jndiContext.lookup("java:comp/env/stateless/beanReferences/Enterprise_bean_access"); 284 285 policy.allow( policy.Enterprise_bean_access ); 286 } catch (IllegalStateException ise) { 287 } catch (javax.naming.NamingException ne) { 288 } 289 290 allowedOperationsTable.put(methodName, policy); 291 } 292 293 } 294 | Popular Tags |