Search in sources :

Example 1 with JobDefinitionAlternateKeyDto

use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.

the class JobDefinitionHelper method getJobDefinitionKey.

/**
 * Gets a job definition key using namespace and name of the the job definition extracted from the specified process definition key and the Regex pattern.
 *
 * @param processDefinitionKey the process definition key
 * @param regexPattern the Regex pattern
 *
 * @return the job definition key
 */
public JobDefinitionAlternateKeyDto getJobDefinitionKey(String processDefinitionKey, Pattern regexPattern) {
    // Create a job definition key.
    JobDefinitionAlternateKeyDto jobDefinitionKey = new JobDefinitionAlternateKeyDto();
    // Use the Regex pattern to match the namespace and job name from a process definition key.
    Matcher matcher = regexPattern.matcher(processDefinitionKey);
    if (matcher.find()) {
        jobDefinitionKey.setNamespace(matcher.group("namespace"));
        jobDefinitionKey.setJobName(matcher.group("jobName"));
    } else {
        // against the database. The check is here for robustness, but should not be expected to be covered as part of tests.
        throw new IllegalArgumentException(String.format("Process definition key \"%s\" does not match the expected pattern \"%s\".", processDefinitionKey, regexPattern.toString()));
    }
    return jobDefinitionKey;
}
Also used : Matcher(java.util.regex.Matcher) JobDefinitionAlternateKeyDto(org.finra.herd.model.dto.JobDefinitionAlternateKeyDto)

Example 2 with JobDefinitionAlternateKeyDto

use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.

the class JobServiceImpl method checkPermissions.

/**
 * Checks the namespace permissions for the current user for the given process definition key.
 *
 * @param processDefinitionKey The process definition key
 * @param permissions The list of permissions the current user must have
 */
private void checkPermissions(String processDefinitionKey, NamespacePermissionEnum[] permissions) {
    // Get the job definition key.
    JobDefinitionAlternateKeyDto jobDefinitionKey = jobDefinitionHelper.getJobDefinitionKey(processDefinitionKey);
    // Checks the permissions against the namespace.
    namespaceSecurityHelper.checkPermission(jobDefinitionKey.getNamespace(), permissions);
}
Also used : JobDefinitionAlternateKeyDto(org.finra.herd.model.dto.JobDefinitionAlternateKeyDto)

Example 3 with JobDefinitionAlternateKeyDto

use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.

the class BaseJavaDelegate method setSecurityContext.

/**
 * Sets the security context per last updater of the current process instance's job definition.
 *
 * @param execution the current execution context
 */
protected void setSecurityContext(DelegateExecution execution) {
    String processDefinitionId = execution.getProcessDefinitionId();
    // Get process definition by process definition ID from Activiti.
    ProcessDefinition processDefinition = activitiService.getProcessDefinitionById(processDefinitionId);
    // Validate that we retrieved the process definition from Activiti.
    if (processDefinition == null) {
        throw new ObjectNotFoundException(String.format("Failed to find Activiti process definition for processDefinitionId=\"%s\".", processDefinitionId));
    }
    // Retrieve the process definition key.
    String processDefinitionKey = processDefinition.getKey();
    // Get the job definition key.
    JobDefinitionAlternateKeyDto jobDefinitionKey = jobDefinitionHelper.getJobDefinitionKey(processDefinitionKey);
    // Get the job definition from the Herd repository and validate that it exists.
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoHelper.getJobDefinitionEntity(jobDefinitionKey.getNamespace(), jobDefinitionKey.getJobName());
    // Set the security context per last updater of the job definition.
    String updatedByUserId = jobDefinitionEntity.getUpdatedBy();
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(updatedByUserId);
    userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser);
    SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken(new SecurityUserWrapper(updatedByUserId, "", true, true, true, true, Collections.emptyList(), applicationUser), null));
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobDefinitionAlternateKeyDto(org.finra.herd.model.dto.JobDefinitionAlternateKeyDto) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 4 with JobDefinitionAlternateKeyDto

use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.

the class JobDefinitionHelperTest method testGetJobDefinitionKey.

@Test
public void testGetJobDefinitionKey() {
    // Set up test values.
    String testProcessDefinitionKey = String.format("%s.%s", NAMESPACE, JOB_NAME);
    // Validate the happy path scenario.
    assertEquals(new JobDefinitionAlternateKeyDto(NAMESPACE, JOB_NAME), jobDefinitionHelper.getJobDefinitionKey(testProcessDefinitionKey));
}
Also used : JobDefinitionAlternateKeyDto(org.finra.herd.model.dto.JobDefinitionAlternateKeyDto) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 5 with JobDefinitionAlternateKeyDto

use of org.finra.herd.model.dto.JobDefinitionAlternateKeyDto in project herd by FINRAOS.

the class JobServiceGetJobsTest method before.

@Before
public void before() {
    initMocks(this);
    when(herdStringHelper.getConfigurationValueAsInteger(ConfigurationValue.JOBS_QUERY_MAX_RESULTS)).thenReturn(1);
    when(jobDefinitionHelper.getJobDefinitionKey(eq("a.b"), any())).thenReturn(new JobDefinitionAlternateKeyDto("a", "b"));
}
Also used : JobDefinitionAlternateKeyDto(org.finra.herd.model.dto.JobDefinitionAlternateKeyDto) Before(org.junit.Before)

Aggregations

JobDefinitionAlternateKeyDto (org.finra.herd.model.dto.JobDefinitionAlternateKeyDto)6 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)2 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)1 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)1 JobSummary (org.finra.herd.model.api.xml.JobSummary)1 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)1 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)1 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1 Before (org.junit.Before)1 Test (org.junit.Test)1 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)1