我正在尝试从启动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);
}
}
在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运行我的工作?
答案 0 :(得分:1)
一种简单的方法是:
您需要将@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);
}
}
在您的代码段中,您具有基本注册表,并且用户已映射到批授权角色。您只需要通过@RunAs
在线程上建立此用户。