Glassfish 中批处理 OSGi 应用程序的授权问题 - "The current user is not authorized to perform this operation"

Authorization issues with batch OSGi app in Glassfish - "The current user is not authorized to perform this operation"

我已经在 Glassfish 4.1.2 下部署了一个带有许多 OSGi 包的 OSGi maven 应用程序。这个 bundle 是用一个 webapp 激活的,这个 webapp 会调用一些定义在它上面的 Jobs。所有这一切实际上都在以预期的方式运作。

Web 应用程序执行作业,作业调用 OSGi 包。当我尝试从外部获取批处理状态时出现问题。

目的是用REST webservices部署其他web应用,这样我就可以按需查询批次状态。当我 运行:

private JobExecution getJob(int id) {

   JobOperator jobOperator = BatchRuntime.getJobOperator();
   JobExecution job = null;

   try {

           job = jobOperator.getJobExecution(id);

           System.out.println("job: " + job);
           System.out.println("name: " + job.getJobName());
           System.out.println("batchStatus: " + job.getBatchStatus());

   } catch (Exception e) {

           e.printStackTrace();

   }

   return job;

}

我得到这个异常:

javax.batch.operations.JobSecurityException: The current user is not authorized to perform this operation

我已经尝试在与 运行 批处理相同的 Web 应用程序中部署 Web 服务,只是为了测试行为,在发送批处理后,我不断收到相同的异常。

奇怪的是,当我 运行 来自 webapp 控制器的批次时,它 运行s,我可以像魅力一样获得批次状态:

@ViewScoped
@ManagedBean(name = "controller")
public class Controller implements Serializable {


   public void executeJobController() {

       JobOperator jobOperator = BatchRuntime.getJobOperator();
       Long executionIdDummy = jobOperator.start("DummyJob", new Properties());
       JobExecution jobExecutionDummy = jobOperator.getJobExecution(executionIdDummy);
       System.out.println("BatchDummyStatus : " + jobExecutionDummy.getBatchStatus());

   }
}

我在 JSR352 规范、Java文档或 Java EE 批量教程中找不到任何关于安全性的内容。

可以这样做吗?是关于 Glassfish JSR352 的吗?我怎样才能做到这一点?

感谢您的宝贵时间。

编辑

按照 @Scott Kurz 的建议将大部分日志设置为 FINE 后, 我可以看到这些新行:

[2017-12-05T13:10:45.100-0500] [glassfish 4.1] [FINE] [] [javax.enterprise.web.core] [tid: _ThreadID=64 _ThreadName=http-listener-1(4)] [timeMillis: 1512497445100] [levelValue: 500] [CLASSNAME: org.apache.catalina.authenticator.AuthenticatorBase] [METHODNAME: invoke] [[ Security checking request GET /ws/webresources/facturacion/getJobs]] [2017-12-05T13:10:45.101-0500] [glassfish 4.1] [FINE] [] [javax.enterprise.web.core] [tid: _ThreadID=64 _ThreadName=http-listener-1(4)] [timeMillis: 1512497445101] [levelValue: 500] [CLASSNAME: org.apache.catalina.authenticator.AuthenticatorBase] [METHODNAME: invoke] [[ Not subject to any constraint]]

这个意思有点奇怪:

[2017-12-05T13:10:45.104-0500] [glassfish 4.1] [FINE] [AS-WEB-NAMING-00005] [javax.enterprise.web.naming] [tid: _ThreadID=64 _ThreadName=http-listener-1(4)] [timeMillis: 1512497445104] [levelValue: 500] [CLASSNAME: org.apache.naming.resources.FileDirContext] [METHODNAME: file] [[ File cannot be read /home/felipe/Documents/Programas/glassfish4/glassfish/domains/domain1/applications/ws/WEB-INF/classes/META-INF/services/javax.batch.operations.JobOperator]]

我已经尝试 运行在本地主机中将 glassfish 作为 sudo,但我得到了相同的行为,并且得到了完全相同的错误。

当我在 OSGi 环境中工作时,首先再次重新部署(手动取消部署并一个接一个地部署)所有 OSGi 捆绑包,最后重新部署(取消部署并部署)Web 服务所在的 Web 应用程序,然后,它开始工作了。

似乎在进行一些重新部署后,OSGi 依赖项无法以某种方式被识别,从而导致安全问题。