Search in sources :

Example 11 with TaskanaEngineConfiguration

use of pro.taskana.configuration.TaskanaEngineConfiguration in project taskana by Taskana.

the class TaskServiceImplIntExplicitTest 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 = "User";
    // 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("wbKey1", "DOMAIN_A");
    wb.setName("BASE WB");
    wb.setDescription("Normal base WB");
    wb.setOwner(user);
    wb.setType(WorkbasketType.GROUP);
    wb = (WorkbasketImpl) workbasketService.createWorkbasket(wb);
    createWorkbasketWithSecurity(wb, wb.getOwner(), true, true, true, true);
    WorkbasketImpl wbNoAppend = (WorkbasketImpl) workbasketService.newWorkbasket("keyNoAppend", "DOMAIN_B");
    wbNoAppend.setName("Test-Security-WorkBasket-APPEND");
    wbNoAppend.setDescription("Workbasket without permission APPEND on Task");
    wbNoAppend.setOwner(user);
    wbNoAppend.setType(WorkbasketType.CLEARANCE);
    wbNoAppend = (WorkbasketImpl) workbasketService.createWorkbasket(wbNoAppend);
    createWorkbasketWithSecurity(wbNoAppend, wbNoAppend.getOwner(), true, true, false, true);
    WorkbasketImpl wbNoTransfer = (WorkbasketImpl) workbasketService.newWorkbasket("keyNoTransfer", "DOMAIN_A");
    wbNoTransfer.setName("Test-Security-WorkBasket-TRANSFER");
    wbNoTransfer.setDescription("Workbasket without permission TRANSFER on Task");
    wbNoTransfer.setOwner(user);
    wbNoTransfer.setType(WorkbasketType.GROUP);
    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.setWorkbasketKey(wbNoTransfer.getKey());
    task.getWorkbasketSummaryImpl().setId(wbNoTransfer.getId());
    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 12 with TaskanaEngineConfiguration

use of pro.taskana.configuration.TaskanaEngineConfiguration in project taskana by Taskana.

the class TaskServiceImplIntExplicitTest method testCreateTaskInTaskanaWithDefaultDb.

@WithAccessId(userName = "Elena", groupNames = { "businessadmin" })
@Test
public void testCreateTaskInTaskanaWithDefaultDb() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    DataSource ds = TaskanaEngineConfiguration.createDefaultDataSource();
    DBCleaner cleaner = new DBCleaner();
    cleaner.clearDb(ds, false);
    TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(ds, false, false);
    TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
    Connection connection = ds.getConnection();
    te.setConnection(connection);
    TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
    WorkbasketServiceImpl workBasketServiceImpl = (WorkbasketServiceImpl) te.getWorkbasketService();
    ClassificationServiceImpl classificationServiceImpl = (ClassificationServiceImpl) te.getClassificationService();
    Workbasket workbasket = workbasketService.newWorkbasket("K99", "DOMAIN_A");
    workbasket.setName("workbasket");
    workbasket.setName("workbasket99");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket = workBasketServiceImpl.createWorkbasket(workbasket);
    Classification classification = classificationService.newClassification("TEST", "DOMAIN_A", "TASK");
    classification = classificationServiceImpl.createClassification(classification);
    Task task = taskServiceImpl.newTask(workbasket.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task.addAttachment(null);
    task = taskServiceImpl.createTask(task);
    Assert.assertNotNull(task);
    Assert.assertNotNull(task.getId());
    connection.commit();
    te.setConnection(null);
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) Task(pro.taskana.Task) ClassificationServiceImpl(pro.taskana.impl.ClassificationServiceImpl) TaskanaEngine(pro.taskana.TaskanaEngine) Classification(pro.taskana.Classification) Connection(java.sql.Connection) TaskServiceImpl(pro.taskana.impl.TaskServiceImpl) WorkbasketServiceImpl(pro.taskana.impl.WorkbasketServiceImpl) DBCleaner(pro.taskana.impl.configuration.DBCleaner) Workbasket(pro.taskana.Workbasket) DataSource(javax.sql.DataSource) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 13 with TaskanaEngineConfiguration

use of pro.taskana.configuration.TaskanaEngineConfiguration in project taskana by Taskana.

the class TaskServiceImplIntAutocommitTest method testCreateTaskInTaskanaWithDefaultDb.

@Test
public void testCreateTaskInTaskanaWithDefaultDb() throws FileNotFoundException, SQLException, TaskNotFoundException, NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, ClassificationAlreadyExistException, TaskAlreadyExistException, InvalidWorkbasketException, InvalidArgumentException, WorkbasketAlreadyExistException, DomainNotFoundException {
    DBCleaner cleaner = new DBCleaner();
    cleaner.clearDb(TaskanaEngineConfiguration.createDefaultDataSource(), false);
    TaskanaEngineConfiguration taskanaEngineConfiguration = new TaskanaEngineConfiguration(null, false, false);
    TaskanaEngine te = taskanaEngineConfiguration.buildTaskanaEngine();
    ((TaskanaEngineImpl) te).setConnectionManagementMode(ConnectionManagementMode.AUTOCOMMIT);
    TaskServiceImpl taskServiceImpl = (TaskServiceImpl) te.getTaskService();
    Workbasket wb = workbasketService.newWorkbasket("workbasket", "DOMAIN_A");
    wb.setName("workbasket");
    wb.setType(WorkbasketType.GROUP);
    te.getWorkbasketService().createWorkbasket(wb);
    Classification classification = te.getClassificationService().newClassification("TEST", "DOMAIN_A", "TASK");
    te.getClassificationService().createClassification(classification);
    Task task = taskServiceImpl.newTask(wb.getId());
    task.setName("Unit Test Task");
    task.setClassificationKey(classification.getKey());
    task.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
    task = taskServiceImpl.createTask(task);
    Assert.assertNotNull(task);
    Assert.assertNotNull(task.getId());
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) Task(pro.taskana.Task) TaskanaEngine(pro.taskana.TaskanaEngine) Classification(pro.taskana.Classification) TaskanaEngineImpl(pro.taskana.impl.TaskanaEngineImpl) TaskServiceImpl(pro.taskana.impl.TaskServiceImpl) DBCleaner(pro.taskana.impl.configuration.DBCleaner) Workbasket(pro.taskana.Workbasket) TaskanaEngineConfigurationTest(pro.taskana.impl.configuration.TaskanaEngineConfigurationTest) Test(org.junit.Test)

Example 14 with TaskanaEngineConfiguration

use of pro.taskana.configuration.TaskanaEngineConfiguration in project taskana by Taskana.

the class TaskanaProducers method init.

@PostConstruct
public void init() {
    // Load Properties and get Datasource via Context
    // Load DataSource via Container
    Context ctx;
    DataSource dataSource;
    ClassLoader classloader = Thread.currentThread().getContextClassLoader();
    try (InputStream propertyStream = classloader.getResourceAsStream(TASKANA_PROPERTIES)) {
        Properties properties = new Properties();
        ctx = new InitialContext();
        properties.load(propertyStream);
        dataSource = (DataSource) ctx.lookup(properties.getProperty("datasource.jndi"));
        logger.debug("---------------> " + dataSource.getConnection().getMetaData());
        this.taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, true, false);
    } catch (NamingException | SQLException | IOException e) {
        logger.error("Could not start Taskana: ", e);
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) NamingException(javax.naming.NamingException) IOException(java.io.IOException) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) PostConstruct(javax.annotation.PostConstruct)

Example 15 with TaskanaEngineConfiguration

use of pro.taskana.configuration.TaskanaEngineConfiguration in project taskana by Taskana.

the class ProvideTaskStatusReportAccTest method resetDb.

public static void resetDb() throws SQLException, IOException {
    DataSource dataSource = TaskanaEngineConfigurationTest.getDataSource();
    DBCleaner cleaner = new DBCleaner();
    cleaner.clearDb(dataSource, true);
    dataSource = TaskanaEngineConfigurationTest.getDataSource();
    taskanaEngineConfiguration = new TaskanaEngineConfiguration(dataSource, false);
    taskanaEngineConfiguration.setGermanPublicHolidaysEnabled(false);
    taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine();
    taskanaEngine.setConnectionManagementMode(TaskanaEngine.ConnectionManagementMode.AUTOCOMMIT);
    cleaner.clearDb(dataSource, false);
    TestDataGenerator testDataGenerator = new TestDataGenerator();
    testDataGenerator.generateMonitoringTestData(dataSource);
}
Also used : TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) DBCleaner(pro.taskana.impl.configuration.DBCleaner) DataSource(javax.sql.DataSource) TestDataGenerator(pro.taskana.database.TestDataGenerator)

Aggregations

TaskanaEngineConfiguration (pro.taskana.configuration.TaskanaEngineConfiguration)20 DBCleaner (pro.taskana.impl.configuration.DBCleaner)16 DataSource (javax.sql.DataSource)11 TestDataGenerator (pro.taskana.database.TestDataGenerator)8 Before (org.junit.Before)6 TaskanaEngineImpl (pro.taskana.impl.TaskanaEngineImpl)6 Test (org.junit.Test)5 TaskanaEngineConfigurationTest (pro.taskana.impl.configuration.TaskanaEngineConfigurationTest)4 TaskanaEngine (pro.taskana.TaskanaEngine)3 WithAccessId (pro.taskana.security.WithAccessId)3 Classification (pro.taskana.Classification)2 Task (pro.taskana.Task)2 Workbasket (pro.taskana.Workbasket)2 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)2 ClassificationImpl (pro.taskana.impl.ClassificationImpl)2 TaskImpl (pro.taskana.impl.TaskImpl)2 TaskServiceImpl (pro.taskana.impl.TaskServiceImpl)2 WorkbasketImpl (pro.taskana.impl.WorkbasketImpl)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1