Search in sources :

Example 16 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class TaskServiceImplIntAutocommitTest method shouldNotTransferByFailingSecurity.

@WithAccessId(userName = "User", groupNames = { "businessadmin" })
@Test
public void shouldNotTransferByFailingSecurity() throws WorkbasketNotFoundException, ClassificationNotFoundException, NotAuthorizedException, ClassificationAlreadyExistException, SQLException, TaskNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    final String user = CurrentUserContext.getUserid();
    // Set up Security for this Test
    dataSource = TaskanaEngineConfigurationTest.getDataSource();
    taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false, true);
    taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
    taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
    taskanaEngineImpl.setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
    taskServiceImpl = (TaskServiceImpl) taskanaEngine.getTaskService();
    classificationService = taskanaEngine.getClassificationService();
    workbasketService = taskanaEngine.getWorkbasketService();
    ClassificationImpl classification = (ClassificationImpl) classificationService.newClassification("KEY", "DOMAIN_A", "TASK");
    classification.setCategory("EXTERNAL");
    classification.setName("Transfert-Task Classification");
    classificationService.createClassification(classification);
    WorkbasketImpl wb = (WorkbasketImpl) workbasketService.newWorkbasket("k5", "DOMAIN_A");
    wb.setName("BASE WB");
    wb.setDescription("Normal base WB");
    wb.setOwner(user);
    wb.setType(WorkbasketType.TOPIC);
    wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
    createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
    WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket("key77", "DOMAIN_A");
    wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
    wbNoAppend.setDescription("Workbasket without permission APPEND on Task");
    wbNoAppend.setOwner(user);
    wbNoAppend.setType(WorkbasketType.PERSONAL);
    wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
    createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
    WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket("k99", "DOMAIN_B");
    wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
    wbNoTransfer.setDescription("Workbasket without permission TRANSFER on Task");
    wbNoTransfer.setOwner(user);
    wbNoTransfer.setType(WorkbasketType.CLEARANCE);
    wbNoTransfer = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoTransfer);
    createWorkbasketWithSecurity(wbNoTransfer, wbNoTransfer.getOwner(), true, true, true, false);
    TaskImpl task = (TaskImpl) taskServiceImpl.newTask(wb.getId());
    task.setName("Task Name");
    task.setDescription("Task used for transfer Test");
    task.setOwner(user);
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = (TaskImpl) taskServiceImpl.createTask(task);
    // Check failing with missing APPEND
    try {
        task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wbNoAppend.getId());
        fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
    } catch (NotAuthorizedException e) {
        if (!e.getMessage().contains("APPEND")) {
            fail("Transfer Task should be FAILD, because there are no APPEND-Rights on destination WB.");
        }
        assertThat(task.isTransferred(), equalTo(false));
        assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
        assertThat(task.getWorkbasketKey(), equalTo(wb.getKey()));
    }
    // Check failing with missing TRANSFER
    task.setId("");
    task.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
    task.setWorkbasketKey(null);
    task = (TaskImpl) taskServiceImpl.createTask(task);
    try {
        task = (TaskImpl) taskServiceImpl.transfer(task.getId(), wb.getId());
        fail("Transfer Task should be FAILD, because there are no TRANSFER-Rights on current WB.");
    } catch (NotAuthorizedException e) {
        if (!e.getMessage().contains("TRANSFER")) {
            fail("Transfer Task should be FAILD, because there are no APPEND-Rights on current WB.");
        }
        assertThat(task.isTransferred(), equalTo(false));
        assertThat(task.getWorkbasketKey(), not(equalTo(wbNoAppend.getKey())));
    }
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) TaskImpl(pro.taskana.impl.TaskImpl) WorkbasketImpl(pro.taskana.impl.WorkbasketImpl) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) ClassificationImpl(pro.taskana.impl.ClassificationImpl) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 17 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class WorkbasketServiceImplIntAutocommitTest method testInsertWorkbasketAccessUser.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void testInsertWorkbasketAccessUser() throws NotAuthorizedException, InvalidArgumentException {
    WorkbasketAccessItem accessItem = workBasketService.newWorkbasketAccessItem("k100000000000000000000000000000000000000", "Arthur Dent");
    accessItem.setPermOpen(true);
    accessItem.setPermRead(true);
    workBasketService.createWorkbasketAccessItem(accessItem);
    Assert.assertEquals(1, workBasketService.getWorkbasketAccessItems("k100000000000000000000000000000000000000").size());
}
Also used : WorkbasketAccessItem(pro.taskana.WorkbasketAccessItem) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 18 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class TaskQueryAccTest method testTaskQueryUser_1_1BusinessAdm.

@WithAccessId(userName = "user_1_1", groupNames = { "businessadmin" })
@Test
public void testTaskQueryUser_1_1BusinessAdm() {
    TaskService taskService = taskanaEngine.getTaskService();
    List<TaskSummary> results = taskService.createTaskQuery().ownerLike("%a%", "%u%").list();
    assertThat(results.size(), equalTo(3));
}
Also used : TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 19 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class TaskQueryAccTest method testTaskQueryUser_1_1.

@WithAccessId(// , groupNames = {"businessadmin"})
userName = "user_1_1")
@Test
public void testTaskQueryUser_1_1() {
    TaskService taskService = taskanaEngine.getTaskService();
    List<TaskSummary> results = taskService.createTaskQuery().ownerLike("%a%", "%u%").list();
    assertThat(results.size(), equalTo(3));
}
Also used : TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 20 with WithAccessId

use of pro.taskana.security.WithAccessId in project taskana by Taskana.

the class TaskQueryAccTest method testTaskQueryUser_1_1Admin.

@WithAccessId(userName = "user_1_1", groupNames = { "admin" })
@Test
public void testTaskQueryUser_1_1Admin() {
    TaskService taskService = taskanaEngine.getTaskService();
    List<TaskSummary> results = taskService.createTaskQuery().ownerLike("%a%", "%u%").list();
    assertThat(results.size(), equalTo(25));
}
Also used : TaskService(pro.taskana.TaskService) TaskSummary(pro.taskana.TaskSummary) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

Test (org.junit.Test)216 WithAccessId (pro.taskana.security.WithAccessId)216 AbstractAccTest (acceptance.AbstractAccTest)201 TaskService (pro.taskana.TaskService)100 WorkbasketService (pro.taskana.WorkbasketService)78 Task (pro.taskana.Task)57 WorkbasketSummary (pro.taskana.WorkbasketSummary)51 TaskSummary (pro.taskana.TaskSummary)47 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)34 Workbasket (pro.taskana.Workbasket)23 Classification (pro.taskana.Classification)21 KeyDomain (pro.taskana.KeyDomain)19 InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)19 ArrayList (java.util.ArrayList)17 Instant (java.time.Instant)16 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)16 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)15 Connection (java.sql.Connection)10 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)9 TimeInterval (pro.taskana.TimeInterval)8