title: How to invoke a @RolesAllowed protected method from an EJB Timer?
body: <p>I have a Method annotated with <code>@RolesAllowed</code>, this method needs to be invoked from an timer (<code>@Schedule</code>), that is located in an other Ejb. But I only get a Authorization Exception: <code>WARNUNG: javax.ejb.AccessLocalException: Client not authorized for this invocation</code></p>
  
  <pre><code> @RolesAllowed("user")
   @Stateless
   public class RatingService {
      public void recalculateRating() {...}
   }
  
   @Singleton
   @Startup     
   public class TimerService {
  
       @EJB private RatingService ratingService;
  
       @Schedule(minute = "0", hour = "*")
       public void timerTriggeredRecalculate() {        
            this.ratingService.recalculateRating();
       }
   }
  </code></pre>
  
  <p>I accept this exception, but <strong>how to invoke a <code>@RolesAllowed</code> protected method from a Timer?</strong></p>
  
  <hr>
  
  <hr>
  
  <p><em>I also tryed to add <code>@RunAs("user")</code> to the <code>TimerService</code> Class. But then I get this exception:</em></p>
  
  <pre><code>SCHWERWIEGEND: SECEJB9000: Exception while running pre-invoke
  java.lang.NullPointerException
      at java.util.Arrays$ArrayList.&lt;init&gt;(Arrays.java:3357)
      at java.util.Arrays.asList(Arrays.java:3343)
      at com.sun.enterprise.security.auth.realm.file.FileRealm.getGroupNames(FileRealm.java:291)
      at com.sun.enterprise.security.auth.login.LoginContextDriver.loginPrincipal(LoginContextDriver.java:294)
      at org.glassfish.ejb.security.application.EJBSecurityManager$2.run(EJBSecurityManager.java:825)
      at com.sun.enterprise.security.common.AppservAccessController.doPrivileged(AppservAccessController.java:61)
      at org.glassfish.ejb.security.application.EJBSecurityManager.loginForRunAs(EJBSecurityManager.java:823)
      at org.glassfish.ejb.security.application.EJBSecurityManager.preInvoke(EJBSecurityManager.java:791)
      at org.glassfish.ejb.security.application.EjbSecurityComponentInvocationHandler$1.beforePreInvoke(EjbSecurityComponentInvocationHandler.java:84)
      at org.glassfish.api.invocation.InvocationManagerImpl.preInvoke(InvocationManagerImpl.java:156)
      at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:487)
      at com.sun.ejb.containers.AbstractSingletonContainer.access$100(AbstractSingletonContainer.java:79)
      at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:719)
      at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:451)
      at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:216)
      at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:177)
      at org.glassfish.ejb.startup.SingletonLifeCycleManager.doStartup(SingletonLifeCycleManager.java:155)
      at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:177)
      at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
      at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
      at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
      at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
      at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
      at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
      at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
      at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
      at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p><em>The Server is a Glassfish 3.1.2</em></p>