3 Replies Latest reply on Feb 17, 2003 2:45 AM by dmeister

    Login from Schedulable

    dmeister

      I want to call some EJB-Methods from inside an Schedulable started inside a MBean.

      The Authentication with jaas didnot failed, altough i
      always i got Authentication exceptions when i calls the ejb-method.
      Can anyone help?

      This is the exception trace:
      java.lang.SecurityException: Authentication exception, principal=null
      at org.jboss.ejb.plugins.SecurityInterceptor.checkSecurityAssociation(SecurityInterceptor.java:173)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:94)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:129)
      at org.jboss.ejb.StatelessSessionContainer.invokeHome(StatelessSessionContainer.java:300)
      at org.jboss.ejb.Container.invoke(Container.java:730)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
      at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:198)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
      at $Proxy55.create(Unknown Source)
      at [package cut].TimeTrigger.perform(TimeTrigger.java:68)
      at org.jboss.varia.scheduler.Scheduler$Listener.handleNotification(Scheduler.java:1046)
      at org.jboss.mx.server.NotificationListenerProxy.handleNotification(NotificationListenerProxy.java:71)
      at javax.management.NotificationBroadcasterSupport.sendNotification(NotificationBroadcasterSupport.java:84)
      at javax.management.timer.Timer.sendNotifications(Timer.java:441)
      at javax.management.timer.Timer.access$000(Timer.java:31)
      at javax.management.timer.Timer$RegisteredNotification.doRun(Timer.java:612)
      at org.jboss.mx.util.SchedulableRunnable.run(SchedulableRunnable.java:164)
      at org.jboss.mx.util.ThreadPool$Worker.run(ThreadPool.java:225)

      This is the Schedulable-code:
      [import statements cut]

      public class TimeTrigger implements Schedulable {
      private static Logger log = Logger.getLogger(TimeTrigger.class);

      String username;
      String password;

      public TimeTrigger(String user,String password) {
      super();
      try {
      this.login(user,password);
      } catch (LoginException e) {
      log.error("Cannot log in");
      }
      }
      public void perform(Date date, long repetitions) {
      SchedularHome home;
      try {
      home = SchedularUtil.getHome();
      Schedular schedular = home.create();
      schedular.startDueItems();

      } catch (NamingException e) {
      log.error("Naming Exception", e);
      } catch (CreateException e) {
      log.error("Creation Exception", e);
      } catch (RemoteException e) {
      log.error("Remote Exception", e);
      }
      }

      private void login(String username, String password)
      throws javax.security.auth.login.LoginException {
      try {

      UsernamePasswordHandler handler =
      new UsernamePasswordHandler(username, password.toCharArray());
      LoginContext lc = new LoginContext("client-login", handler);
      log.debug("Created LoginContext");
      lc.login();

      log.debug("Login completed");
      } catch (LoginException le) {
      log.error("Login failed");
      throw new javax.security.auth.login.LoginException("Login failed");
      }
      }
      }

      Why is the principal null?

        • 1. Re: Login from Schedulable

          Is the perform() method called in a separate thread? That would explain the error, because when used in JBoss itself the ClientLoginModule associated the security attributes with the current thread only...
          To solve this, you have to do the login on the thread that calls the ejb.

          Hth
          Peter.

          • 2. Re: Login from Schedulable
            jwkaltz

            What about this Scheduler EJB you're calling: does it live in a security context ? (i.e. is it deployed with security descriptors)

            • 3. Re: Login from Schedulable
              dmeister

              It seems to depends of the thread.

              I changed to code that it will login in the same thread and now the security exception does not happen.

              Thank you