Search in sources :

Example 6 with JobSecurityException

use of javax.batch.operations.JobSecurityException in project eap-additional-testsuite by jboss-set.

the class BatchSubsystemSecurityTestCase method testStart_NotAllowed.

/**
 * Try running a job as a user who doesn't have the permission to run jobs. It should not succeed.
 */
@Test
public void testStart_NotAllowed() throws Exception {
    final SecurityIdentity user2 = getSecurityIdentity("user2", "password2");
    try {
        user2.runAs((Callable<Long>) () -> operator.start("assert-identity", new Properties()));
        Assert.fail("user2 shouldn't be allowed to start batch jobs");
    } catch (JobSecurityException e) {
    // OK
    }
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) JobSecurityException(javax.batch.operations.JobSecurityException) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with JobSecurityException

use of javax.batch.operations.JobSecurityException in project eap-additional-testsuite by jboss-set.

the class BatchSubsystemSecurityTestCase method testRestart_NotAllowed.

/**
 * Test restarting failed jobs by a user who doesn't have the permission to do it.
 */
@Test
public void testRestart_NotAllowed() throws Exception {
    final SecurityIdentity user1 = getSecurityIdentity("user1", "password1");
    final SecurityIdentity user2 = getSecurityIdentity("user2", "password2");
    Properties params = new Properties();
    params.put("should.fail", "true");
    final Long executionId = user1.runAs((Callable<Long>) () -> operator.start("failing-batchlet", params));
    waitForJobEnd(executionId, 10);
    Assert.assertEquals(BatchStatus.FAILED, operator.getJobExecution(executionId).getBatchStatus());
    try {
        user2.runAs((Callable<Long>) () -> operator.restart(executionId, params));
        Assert.fail("user2 shouldn't be allowed to restart batch jobs");
    } catch (JobSecurityException e) {
    // OK
    }
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) JobSecurityException(javax.batch.operations.JobSecurityException) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with JobSecurityException

use of javax.batch.operations.JobSecurityException in project eap-additional-testsuite by jboss-set.

the class BatchSubsystemSecurityTestCase method testRead_NotAllowed.

/**
 * Test reading execution metadata by a user who doesn't have the permission to do it.
 * User1 runs a job and then user2 tries to read its metadata.
 */
@Test
public void testRead_NotAllowed() throws Exception {
    final SecurityIdentity user1 = getSecurityIdentity("user1", "password1");
    final SecurityIdentity user2 = getSecurityIdentity("user2", "password2");
    final Long executionId = user1.runAs((Callable<Long>) () -> operator.start("assert-identity", new Properties()));
    try {
        user2.runAs((Callable<Properties>) () -> operator.getJobExecution(executionId).getJobParameters());
        Assert.fail("user2 shouldn't be allowed to read batch job metadata");
    } catch (JobSecurityException e) {
    // OK
    }
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) JobSecurityException(javax.batch.operations.JobSecurityException) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with JobSecurityException

use of javax.batch.operations.JobSecurityException in project eap-additional-testsuite by jboss-set.

the class BatchSubsystemSecurityTestCase method testStop_NotAllowed.

/**
 * Stopping an execution by a user who doesn't have the permission to do it.
 */
@Test
public void testStop_NotAllowed() throws Exception {
    final SecurityIdentity user1 = getSecurityIdentity("user1", "password1");
    final SecurityIdentity user3 = getSecurityIdentity("user3", "password3");
    final Long id = user1.runAs((Callable<Long>) () -> operator.start("long-running-batchlet", null));
    TimeUnit.SECONDS.sleep(1);
    try {
        user3.runAs(() -> operator.stop(id));
        Assert.fail("user2 should not be allowed to stop job executions");
    } catch (JobSecurityException e) {
    // OK
    }
    Assert.assertNotEquals(BatchStatus.STOPPED, operator.getJobExecution(id).getBatchStatus());
}
Also used : SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) JobSecurityException(javax.batch.operations.JobSecurityException) Test(org.junit.Test)

Example 10 with JobSecurityException

use of javax.batch.operations.JobSecurityException in project dataverse by IQSS.

the class FileRecordJobListener method doReport.

/**
 * Generate all the job reports and user notifications.
 */
private void doReport() {
    try {
        String jobJson;
        String jobId = Long.toString(jobContext.getInstanceId());
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        if (user == null) {
            getJobLogger().log(Level.SEVERE, "Cannot find authenticated user.");
            return;
        }
        if (dataset == null) {
            getJobLogger().log(Level.SEVERE, "Cannot find dataset.");
            return;
        }
        long datasetVersionId = dataset.getLatestVersion().getId();
        JobExecution jobExecution = jobOperator.getJobExecution(jobContext.getInstanceId());
        if (jobExecution != null) {
            Date date = new Date();
            Timestamp timestamp = new Timestamp(date.getTime());
            JobExecutionEntity jobExecutionEntity = JobExecutionEntity.create(jobExecution);
            jobExecutionEntity.setExitStatus("COMPLETED");
            jobExecutionEntity.setStatus(BatchStatus.COMPLETED);
            jobExecutionEntity.setEndTime(date);
            jobJson = new ObjectMapper().writeValueAsString(jobExecutionEntity);
            String logDir = System.getProperty("com.sun.aas.instanceRoot") + SEP + "logs" + SEP + "batch-jobs" + SEP;
            // [1] save json log to file
            LoggingUtil.saveJsonLog(jobJson, logDir, jobId);
            // [2] send user notifications - to all authors
            notificationServiceBean.sendNotification(user, timestamp, notifyType, datasetVersionId);
            Map<String, AuthenticatedUser> distinctAuthors = permissionServiceBean.getDistinctUsersWithPermissionOn(Permission.EditDataset, dataset);
            distinctAuthors.values().forEach((value) -> {
                notificationServiceBean.sendNotification((AuthenticatedUser) value, new Timestamp(new Date().getTime()), notifyType, datasetVersionId);
            });
            // [3] send SuperUser notification
            List<AuthenticatedUser> superUsers = authenticationServiceBean.findSuperUsers();
            if (superUsers != null && !superUsers.isEmpty()) {
                superUsers.forEach((au) -> {
                    notificationServiceBean.sendNotification(au, timestamp, notifyType, datasetVersionId);
                });
            }
            // [4] action log: store location of the full log to avoid truncation issues
            actionLogServiceBean.log(LoggingUtil.getActionLogRecord(user.getIdentifier(), jobExecution, logDir + "job-" + jobId + ".log", jobId));
        } else {
            getJobLogger().log(Level.SEVERE, "Job execution is null");
        }
    } catch (NoSuchJobExecutionException | JobSecurityException | JsonProcessingException e) {
        getJobLogger().log(Level.SEVERE, "Creating job json: " + e.getMessage());
    }
}
Also used : JobExecutionEntity(edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity) JobOperator(javax.batch.operations.JobOperator) Timestamp(java.sql.Timestamp) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Date(java.util.Date) JobExecution(javax.batch.runtime.JobExecution) JobSecurityException(javax.batch.operations.JobSecurityException) NoSuchJobExecutionException(javax.batch.operations.NoSuchJobExecutionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JobSecurityException (javax.batch.operations.JobSecurityException)12 Test (org.junit.Test)10 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)10 Properties (java.util.Properties)9 JobOperator (javax.batch.operations.JobOperator)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 JobExecutionEntity (edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity)1 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)1 File (java.io.File)1 Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 JobStartException (javax.batch.operations.JobStartException)1 NoSuchJobExecutionException (javax.batch.operations.NoSuchJobExecutionException)1 JobExecution (javax.batch.runtime.JobExecution)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1