KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > security > TimerTesterBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.security;
23
24 import java.util.Date JavaDoc;
25
26 import javax.naming.InitialContext JavaDoc;
27
28 import javax.annotation.Resource;
29 import javax.annotation.security.RunAs;
30 import javax.ejb.Remote JavaDoc;
31 import javax.ejb.SessionContext JavaDoc;
32 import javax.ejb.Stateless JavaDoc;
33 import javax.ejb.Timeout JavaDoc;
34 import javax.ejb.Timer JavaDoc;
35 import javax.ejb.TimerService JavaDoc;
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 /**
45  * Comment
46  *
47  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
48  * @version $Revision: 56066 $
49  */

50 @Stateless JavaDoc
51 @Remote JavaDoc(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 JavaDoc timerService;
61
62    private @Resource SessionContext JavaDoc ctx;
63    
64    private Timer JavaDoc timer;
65
66    public void startTimer(long pPeriod)
67    {
68       timerCalled = false;
69       System.out.println("************ startTimer");
70       timer = timerService.createTimer(new Date JavaDoc(new Date JavaDoc().getTime() + pPeriod), "TimerSLSBean");
71       
72    }
73    
74    public boolean isTimerCalled()
75    {
76       return timerCalled;
77    }
78
79    @Timeout JavaDoc
80    public void timeoutHandler(Timer JavaDoc 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 JavaDoc().lookup("UncheckedStatelessBean/remote");
91          tester.unchecked();
92          timerCalled = true;
93       } catch (Exception JavaDoc e)
94       {
95          e.printStackTrace();
96       }
97    }
98 }
99
Popular Tags