Search in sources :

Example 6 with JobDeleteRequest

use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.

the class JobServiceTest method testDeleteJobAssertNoErrorWhenUserHasPermissions.

@Test
public void testDeleteJobAssertNoErrorWhenUserHasPermissions() throws Exception {
    // Start a job that will wait in a receive task
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    String username = "username";
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(username);
    applicationUser.setNamespaceAuthorizations(new HashSet<>());
    applicationUser.getNamespaceAuthorizations().add(new NamespaceAuthorization(TEST_ACTIVITI_NAMESPACE_CD, Arrays.asList(NamespacePermissionEnum.EXECUTE)));
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null));
    try {
        jobService.deleteJob(job.getId(), new JobDeleteRequest("test delete reason"));
    } catch (AccessDeniedException e) {
        fail();
    }
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) AccessDeniedException(org.springframework.security.access.AccessDeniedException) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) NamespaceAuthorization(org.finra.herd.model.api.xml.NamespaceAuthorization) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 7 with JobDeleteRequest

use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.

the class JobServiceTest method testDeleteJobAssertErrorJobDoesNotExist.

/**
 * Asserts that the deleteJob call will throw an error when specified job does not exist.
 *
 * @throws Exception
 */
@Test
public void testDeleteJobAssertErrorJobDoesNotExist() throws Exception {
    // Create a job delete request
    JobDeleteRequest jobDeleteRequest = new JobDeleteRequest();
    jobDeleteRequest.setDeleteReason("test delete reason");
    try {
        jobService.deleteJob("DOES_NOT_EXIST", jobDeleteRequest);
    } catch (Exception e) {
        assertEquals(ObjectNotFoundException.class, e.getClass());
        assertEquals("Job with ID \"DOES_NOT_EXIST\" does not exist or is already completed.", e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Example 8 with JobDeleteRequest

use of org.finra.herd.model.api.xml.JobDeleteRequest in project herd by FINRAOS.

the class JobServiceTest method testDeleteJobAssertAccessDeniedWhenUserHasNoPermissions.

@Test
public void testDeleteJobAssertAccessDeniedWhenUserHasNoPermissions() throws Exception {
    // Start a job that will wait in a receive task
    jobDefinitionServiceTestHelper.createJobDefinition(ACTIVITI_XML_TEST_RECEIVE_TASK_WITH_CLASSPATH);
    Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME));
    String username = "username";
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(username);
    applicationUser.setNamespaceAuthorizations(new HashSet<>());
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper(username, "password", false, false, false, false, Collections.emptyList(), applicationUser), null));
    try {
        jobService.deleteJob(job.getId(), new JobDeleteRequest("test delete reason"));
        fail();
    } catch (Exception e) {
        assertEquals(AccessDeniedException.class, e.getClass());
        assertEquals(String.format("User \"%s\" does not have \"[EXECUTE]\" permission(s) to the namespace \"%s\"", username, TEST_ACTIVITI_NAMESPACE_CD), e.getMessage());
    }
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) AccessDeniedException(org.springframework.security.access.AccessDeniedException) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) JobDeleteRequest(org.finra.herd.model.api.xml.JobDeleteRequest) Job(org.finra.herd.model.api.xml.Job) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Test(org.junit.Test)

Aggregations

JobDeleteRequest (org.finra.herd.model.api.xml.JobDeleteRequest)8 Test (org.junit.Test)8 Job (org.finra.herd.model.api.xml.Job)7 AccessDeniedException (org.springframework.security.access.AccessDeniedException)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)3 HashMap (java.util.HashMap)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)2 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)2 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)2 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JobUpdateRequest (org.finra.herd.model.api.xml.JobUpdateRequest)1 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)1