1 Reply Latest reply on Aug 17, 2005 5:26 PM by Dorren Chen

    create or cancel EJB timer kills JAAS authentication

    Dorren Chen Newbie

      * Company's web application uses JAAS login. Whenever I call my EJB's methods (scheduleJob and cancelJob ) that contains timerService.createTimer() or Timer.cancel(), I always get kicked out of web app as if I wasn't logged in, and have to relogin again.
      * I do see the job is indeed scheduled after I relogin.
      * Once a job is scheduled, it runs fine.
      * there is no error msg/stacktrace from the console when submit new job or cancel.
      * However, get list of timers (getScheduledJobs) works fine, without kicking me out.

      What should I do so I can use Timer service functions without losing authentication?

      I'm using JBoss 4.0.2.

      public class TimedCommandHandlerServiceBean implements SessionBean, TimedObject {
      
       public void scheduleJob(ScheduledJob job, Date initialTime){
       TimerService timerService = ctx.getTimerService();
       timerService.createTimer(initialTime,job);
       }
      
       public void cancelJob(ScheduledJob aJob){
       TimerService timerService = ctx.getTimerService();
       Collection timers = timerService.getTimers();
      
       for(Iterator iter = timers.iterator(); iter.hasNext();){
       Timer timer = (Timer)iter.next();
       ScheduledJob job = (ScheduledJob)timer.getInfo();
       if(job.getName().equals(aJob.getName())){
       timer.cancel();
       break;
       }
       }
       }
      
       public Collection getScheduledJobs(){
       TimerService timerService = ctx.getTimerService();
       Collection timers = timerService.getTimers();
      
       Collection result = new ArrayList();
       for(Iterator iter = timers.iterator(); iter.hasNext();){
       Timer timer = (Timer)iter.next();
       ScheduledJob job = (ScheduledJob)timer.getInfo();
       result.add(job);
       }
       return result;
       }
      


      jboss-web.xml
      <jboss-web>
       <security-domain>java:/jaas/CompanyRealm</security-domain>
      </jboss-web>
      


      login module in jboss-4.0.2\server\default\conf\login-config.xml
       <application-policy name="CompanyRealm">
       <authentication>
       <login-module code="mycompany.jaas.jboss.JBossLoginModule"
       flag="required">
       <module-option name="dsJndiName">java:MYDB</module-option>
       </login-module>
       </authentication>
       </application-policy>