如何授权Java批处理作业,以便它可以从WebSphereLiberty中的启动bean运行?

如何授权Java批处理作业,以便它可以从WebSphereLiberty中的启动bean运行?,websphere,websphere-liberty,jsr352,java-batch,open-liberty,Websphere,Websphere Liberty,Jsr352,Java Batch,Open Liberty,我试图从我的启动bean中提交一个基本的批处理作业,这会给我一条错误消息“未经验证的用户无权启动批处理作业” 这是我的启动bean: @Singleton @Startup public class ControllerBean { @PersistenceContext(unitName = "item-persister") EntityManager entityManager; @PostConstruct public void initialize

我试图从我的启动bean中提交一个基本的批处理作业,这会给我一条错误消息“未经验证的用户无权启动批处理作业”

这是我的启动bean:

@Singleton
@Startup
public class ControllerBean {
    @PersistenceContext(unitName = "item-persister")
    EntityManager entityManager; 

    @PostConstruct
    public void initialize() { 
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        long execID = jobOperator.start("testjob", null);
    }
}
在my server.xml中,我配置了用户名和密码:

<basicRegistry id="basic" realm="ibm/api">
    <user name="bob" password="bobpwd"/>
</basicRegistry>

<authorization-roles id="com.ibm.ws.batch">
    <security-role name="batchAdmin">
        <user name="bob"/>
    </security-role>
</authorization-roles>

如何正确地进行身份验证,以便启动bean可以运行我的作业?

一个简单的方法是:

配置运行方式标识 您需要将
@RunAs
注释值与服务器配置对齐

在服务器配置(server.xml)中: 在代码段中,您将基本注册表和用户映射到批授权角色。您只需要通过
@RunAs
在线程上建立此用户

<application name="MyApp" ... >
    <application-bnd>
        <security-role name="JOBSTARTER">
            <user name="bob" />
            <run-as userid="bob" password="bobpwd"/>
        </security-role>
    </application-bnd>
</application>
@Singleton
@Startup
@RunAs("JOBSTARTER")
public class ControllerBean {

    @PostConstruct
    public void initialize() { 
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        long execID = jobOperator.start("testjob", null);
    }
}