use of javax.batch.operations.JobSecurityException in project dataverse by IQSS.
the class ImportFromFileSystemCommand method execute.
@Override
public JsonObject execute(CommandContext ctxt) throws CommandException {
JsonObjectBuilder bld = jsonObjectBuilder();
/**
* batch import as-individual-datafiles is disabled in this iteration;
* only the import-as-a-package is allowed. -- L.A. Feb 2 2017
*/
String fileMode = FileRecordWriter.FILE_MODE_PACKAGE_FILE;
try {
/**
* Current constraints: 1. only supports merge and replace mode 2.
* valid dataset 3. valid dataset directory 4. valid user & user has
* edit dataset permission 5. only one dataset version 6. dataset
* version is draft
*/
if (!mode.equalsIgnoreCase("MERGE") && !mode.equalsIgnoreCase("REPLACE")) {
String error = "Import mode: " + mode + " is not currently supported.";
logger.info(error);
throw new IllegalCommandException(error, this);
}
if (!fileMode.equals(FileRecordWriter.FILE_MODE_INDIVIDUAL_FILES) && !fileMode.equals(FileRecordWriter.FILE_MODE_PACKAGE_FILE)) {
String error = "File import mode: " + fileMode + " is not supported.";
logger.info(error);
throw new IllegalCommandException(error, this);
}
File directory = new File(System.getProperty("dataverse.files.directory") + File.separator + dataset.getAuthority() + File.separator + dataset.getIdentifier());
if (!isValidDirectory(directory)) {
String error = "Dataset directory is invalid. " + directory;
logger.info(error);
throw new IllegalCommandException(error, this);
}
if (Strings.isNullOrEmpty(uploadFolder)) {
String error = "No uploadFolder specified";
logger.info(error);
throw new IllegalCommandException(error, this);
}
File uploadDirectory = new File(System.getProperty("dataverse.files.directory") + File.separator + dataset.getAuthority() + File.separator + dataset.getIdentifier() + File.separator + uploadFolder);
if (!isValidDirectory(uploadDirectory)) {
String error = "Upload folder is not a valid directory.";
logger.info(error);
throw new IllegalCommandException(error, this);
}
if (dataset.getVersions().size() != 1) {
String error = "Error creating FilesystemImportJob with dataset with ID: " + dataset.getId() + " - Dataset has more than one version.";
logger.info(error);
throw new IllegalCommandException(error, this);
}
if (dataset.getLatestVersion().getVersionState() != DatasetVersion.VersionState.DRAFT) {
String error = "Error creating FilesystemImportJob with dataset with ID: " + dataset.getId() + " - Dataset isn't in DRAFT mode.";
logger.info(error);
throw new IllegalCommandException(error, this);
}
try {
long jid;
Properties props = new Properties();
props.setProperty("datasetId", dataset.getId().toString());
props.setProperty("userId", getUser().getIdentifier().replace("@", ""));
props.setProperty("mode", mode);
props.setProperty("fileMode", fileMode);
props.setProperty("uploadFolder", uploadFolder);
if (totalSize != null && totalSize > 0) {
props.setProperty("totalSize", totalSize.toString());
}
JobOperator jo = BatchRuntime.getJobOperator();
jid = jo.start("FileSystemImportJob", props);
if (jid > 0) {
bld.add("executionId", jid).add("message", "FileSystemImportJob in progress");
return bld.build();
} else {
String error = "Error creating FilesystemImportJob with dataset with ID: " + dataset.getId();
logger.info(error);
throw new CommandException(error, this);
}
} catch (JobStartException | JobSecurityException ex) {
String error = "Error creating FilesystemImportJob with dataset with ID: " + dataset.getId() + " - " + ex.getMessage();
logger.info(error);
throw new IllegalCommandException(error, this);
}
} catch (Exception e) {
bld.add("message", "Import Exception - " + e.getMessage());
return bld.build();
}
}
use of javax.batch.operations.JobSecurityException in project wildfly by wildfly.
the class BatchSubsystemSecurityTestCase method testAbandon_NotAllowed.
/**
* Abandoning an execution by a user who doesn't have the permission to do it.
*/
@Test
public void testAbandon_NotAllowed() throws Exception {
final SecurityIdentity user1 = getSecurityIdentity("user1", "password1");
final SecurityIdentity user2 = getSecurityIdentity("user2", "password2");
final Long id = user1.runAs((Callable<Long>) () -> operator.start("assert-identity", new Properties()));
waitForJobEnd(id, 10);
try {
user2.runAs(() -> operator.abandon(id));
Assert.fail("user2 should not be allowed to abandon job executions");
} catch (JobSecurityException e) {
// OK
}
Assert.assertEquals(operator.getJobExecution(id).getBatchStatus(), BatchStatus.COMPLETED);
}
Aggregations