public void authorizeForJob(String user, String jobId, boolean write) throws AuthorizationException {
if (securityEnabled && write && !isAdmin(user)) {
// handle workflow jobs
if (jobId.endsWith("-W")) {
WorkflowJobBean jobBean = null;
WorkflowStore store = null;
try {
store = Services.get().get(WorkflowStoreService.class).create();
store.beginTrx();
jobBean = store.getWorkflow(jobId, false);
store.commitTrx();
}
catch (StoreException ex) {
incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
if (store != null) {
store.rollbackTrx();
}
throw new AuthorizationException(ex);
}
catch (Exception ex) {
incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
log.error("Exception, {0}", ex.getMessage(), ex);
if (store != null && store.isActive()) {
try {
store.rollbackTrx();
}
catch (RuntimeException rex) {
log.warn("openjpa error, {0}", rex.getMessage(), rex);
}
}
throw new AuthorizationException(ErrorCode.E0501, ex);
}
finally {
if (store != null) {
if (!store.isActive()) {
try {
store.closeTrx();
}
catch (RuntimeException rex) {
log.warn("Exception while attempting to close store", rex);
}
}
else {
log.warn("transaction is not committed or rolled back before closing entitymanager.");
}
}
}
if (jobBean != null && !jobBean.getUser().equals(user)) {
if (!isUserInGroup(user, jobBean.getGroup())) {
incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
throw new AuthorizationException(ErrorCode.E0508, user, jobId);
}
}
}
// handle coordinator jobs
else {
CoordinatorJobBean jobBean = null;
CoordinatorStore store = null;
try {
store = Services.get().get(CoordinatorStoreService.class).create();
store.beginTrx();
jobBean = store.getCoordinatorJob(jobId, false);
store.commitTrx();
}
catch (StoreException ex) {
incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
if (store != null) {
store.rollbackTrx();
}
throw new AuthorizationException(ex);
}
catch (Exception ex) {
incrCounter(INSTR_FAILED_AUTH_COUNTER, 1);
log.error("Exception, {0}", ex.getMessage(), ex);
if (store != null && store.isActive()) {
try {
store.rollbackTrx();
}
catch (RuntimeException rex) {
log.warn("openjpa error, {0}", rex.getMessage(), rex);
}
}
throw new AuthorizationException(ErrorCode.E0501, ex);
}
finally {
if (store != null) {
if (!store.isActive()) {
try {
store.closeTrx();
}
catch (RuntimeException rex) {
log.warn("Exception while attempting to close store", rex);
}
}