1 22 package org.jboss.ejb3.test.security; 23 24 import java.util.Date ; 25 26 import javax.naming.InitialContext ; 27 28 import javax.annotation.Resource; 29 import javax.annotation.security.RunAs; 30 import javax.ejb.Remote ; 31 import javax.ejb.SessionContext ; 32 import javax.ejb.Stateless ; 33 import javax.ejb.Timeout ; 34 import javax.ejb.Timer ; 35 import javax.ejb.TimerService ; 36 37 import org.jboss.annotation.ejb.RemoteBinding; 38 import org.jboss.annotation.security.SecurityDomain; 39 40 import org.jboss.security.SecurityAssociation; 41 42 import org.jboss.logging.Logger; 43 44 50 @Stateless 51 @Remote (TimerTester.class) 52 @RemoteBinding(jndiBinding="TimerTester") 53 @SecurityDomain("timer-runas-test") 54 public class TimerTesterBean implements TimerTester 55 { 56 private static final Logger log = Logger.getLogger(TimerTesterBean.class); 57 58 public static boolean timerCalled = false; 59 60 private @Resource TimerService timerService; 61 62 private @Resource SessionContext ctx; 63 64 private Timer timer; 65 66 public void startTimer(long pPeriod) 67 { 68 timerCalled = false; 69 System.out.println("************ startTimer"); 70 timer = timerService.createTimer(new Date (new Date ().getTime() + pPeriod), "TimerSLSBean"); 71 72 } 73 74 public boolean isTimerCalled() 75 { 76 return timerCalled; 77 } 78 79 @Timeout 80 public void timeoutHandler(Timer timer) 81 { 82 log.info("EJB TIMEOUT!!!!"); 83 log.info("CallerPrincipal: "+ctx.getCallerPrincipal()+"."); 84 log.info("PrincipalFromSecurityAssociation: "+SecurityAssociation.getPrincipal()+"."); 85 log.info("CallerPricipalFromSecurityAssociation: "+SecurityAssociation.getCallerPrincipal()+"."); 86 87 try 88 { 89 UncheckedStateless tester = 90 (UncheckedStateless) new InitialContext ().lookup("UncheckedStatelessBean/remote"); 91 tester.unchecked(); 92 timerCalled = true; 93 } catch (Exception e) 94 { 95 e.printStackTrace(); 96 } 97 } 98 } 99 | Popular Tags |