1 22 package org.jboss.ejb3.test.asynchronous; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import javax.ejb.EJB ; 26 import javax.annotation.security.DenyAll; 27 import javax.annotation.security.PermitAll; 28 import javax.annotation.security.RolesAllowed; 29 import javax.ejb.EJBAccessException ; 30 import javax.ejb.Local ; 31 import javax.ejb.Remote ; 32 import javax.ejb.Stateless ; 33 import org.jboss.annotation.security.SecurityDomain; 34 import org.jboss.aspects.asynch.Future; 35 import org.jboss.ejb3.asynchronous.Asynch; 36 37 41 @Stateless 42 @SecurityDomain("other") 43 @Remote (SecuredStatelessRemote.class) 44 @Local (SecuredStatelessLocal.class) 45 public class SecuredStatelessBean implements SecuredStatelessRemote, SecuredStatelessLocal 46 { 47 @EJB 48 public SecuredStatelessLocal local; 49 50 @PermitAll 51 public int uncheckedMethod(int i) 52 { 53 return i; 54 } 55 56 @DenyAll 57 public int excludedMethod(int i) 58 { 59 return i; 60 } 61 62 @RolesAllowed("allowed") 63 public int method(int i) 64 { 65 SecuredStatelessLocal asynchLocal = (SecuredStatelessLocal)Asynch.getAsynchronousProxy(local); 66 67 asynchLocal.excludedMethod(i); 68 Object ret = getReturnOrException(asynchLocal); 69 if (!(ret instanceof EJBAccessException )) 70 { 71 throw new RuntimeException ("Local excluded method call did not cause a SecurityException"); 72 } 73 74 asynchLocal.localSecured(i); 75 ret = getReturnOrException(asynchLocal); 76 return (Integer )ret; 77 } 78 79 @RolesAllowed("allowed") 80 public int localSecured(int i) 81 { 82 return i; 83 } 84 85 private Object getReturnOrException(Object proxy) 86 { 87 try 88 { 89 Future future = Asynch.getFutureResult(proxy); 90 91 while (!future.isDone()) 92 { 93 Thread.sleep(100); 94 } 95 return future.get(); 96 } 97 catch(InvocationTargetException e) 98 { 99 return e.getCause(); 100 } 101 catch (InterruptedException e) 102 { 103 throw new RuntimeException ("Bummer"); 104 } 105 } 106 107 } 108 | Popular Tags |