use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class CancelTaskDeadlineCommand method execute.
@Override
public Void execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
logger.debug("About to cancel deadline {} on a task {}", deadlineId, task);
Deadlines deadlines = ((InternalTask) task).getDeadlines();
DeadlineType type = DeadlineType.START;
Deadline deadline = deadlines.getStartDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
if (deadline == null) {
deadline = deadlines.getEndDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
type = DeadlineType.END;
}
TaskPersistenceContext persistenceContext = context.getPersistenceContext();
TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
deadlinesService.unschedule(taskId, deadline, type);
persistenceContext.removeDeadline(deadline);
return null;
}
use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithIncorrectUser.
@Test
public void testCompleteWithIncorrectUser() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Go straight from Ready to Inprogress
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Should not complete as wrong user
PermissionDeniedException denied = null;
try {
taskService.complete(taskId, "Bobba Fet", null);
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class LifeCycleBaseTest method testSuspendFromReservedWithIncorrectUser.
@Test
public void testSuspendFromReservedWithIncorrectUser() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Check is Reserved
taskService.claim(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Check is not changed
PermissionDeniedException denied = null;
try {
taskService.suspend(taskId, "Bobba Fet");
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class LifeCycleBaseTest method testStopWithIncorrectUser.
@Test
public void testStopWithIncorrectUser() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Go straight from Ready to Inprogress
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Should not stop
PermissionDeniedException denied = null;
try {
taskService.stop(taskId, "Bobba Fet");
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
use of org.jbpm.services.task.exception.PermissionDeniedException in project jbpm by kiegroup.
the class LifeCycleBaseTest method testExitPermissionDenied.
@Test
public void testExitPermissionDenied() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { skipable = false} ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator')] }),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
task = taskService.getTaskById(taskId);
assertEquals(Status.Ready, task.getTaskData().getStatus());
try {
taskService.exit(taskId, "Darth Vader");
fail("Non admin user can't exit a task");
} catch (PermissionDeniedException e) {
}
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Ready, task1.getTaskData().getStatus());
}
Aggregations