In order to perform batch operations from a servlet when batch role-based authentication is configured, you need to add an authentication challenge to the servlet so that it runs under a specific user rather than UNAUTHENTICATED.
You could add this to the sample like this:
import javax.servlet.annotation.HttpConstraint;
import javax.servlet.annotation.HttpMethodConstraint;
import javax.servlet.annotation.ServletSecurity;
import javax.servlet.annotation.WebServlet;
// ...
@ServletSecurity(value = @HttpConstraint(transportGuarantee = ServletSecurity.TransportGuarantee.CONFIDENTIAL),
httpMethodConstraints = { @HttpMethodConstraint(value = "POST", emptyRoleSemantic = ServletSecurity.EmptyRoleSemantic.PERMIT),
@HttpMethodConstraint(value = "GET", emptyRoleSemantic = ServletSecurity.EmptyRoleSemantic.PERMIT),
@HttpMethodConstraint(value = "PUT", emptyRoleSemantic = ServletSecurity.EmptyRoleSemantic.PERMIT) })
@WebServlet(urlPatterns = { "/joboperator" })
public class JobOperatorServlet extends HttpServlet {
That's in addition to defining the user registry and the users, and granting them access to the batch roles as in the doc you referenced, and here is a snippet of that:
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<keyStore id="defaultKeyStore" password="Liberty"/>
<basicRegistry id="basic" realm="ibm/api">
<user name="bob" password="bobpwd"/>
<user name="jane" password="janepwd"/>
</basicRegistry>
<authorization-roles id="com.ibm.ws.batch">
<security-role name="batchSubmitter">
<user name="bob"/>
</security-role>
<security-role name="batchAdmin">
<user name="jane"/>
</security-role>
</authorization-roles>
Now, there's a separate but related question of how do you configure batch security, i.e. which features bring batch security into the picture. But I'll leave that for a follow-up question and take it for granted here that it's present.