use of edu.harvard.iq.dataverse.engine.command.exception.PermissionException in project dataverse by IQSS.
the class RevokeSuperuserStatusCommand method executeImpl.
@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
if (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser()) {
throw new PermissionException("Revoke Superuser status command can only be called by superusers.", this, null, null);
}
try {
targetUser.setSuperuser(false);
ctxt.em().merge(targetUser);
ctxt.em().flush();
} catch (Exception e) {
throw new CommandException("Failed to revoke the superuser status for user " + targetUser.getIdentifier(), this);
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.PermissionException in project dataverse by IQSS.
the class UpdateDatasetTargetURLCommand method executeImpl.
@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
if (!(getUser() instanceof AuthenticatedUser) || !getUser().isSuperuser()) {
throw new PermissionException("Update Target URL can only be called by superusers.", this, Collections.singleton(Permission.EditDataset), target);
}
IdServiceBean idServiceBean = IdServiceBean.getBean(target.getProtocol(), ctxt);
HashMap<String, String> metadata = idServiceBean.getMetadataFromDatasetForTargetURL(target);
try {
String doiRetString = idServiceBean.modifyIdentifier(target, metadata);
if (doiRetString != null && doiRetString.contains(target.getIdentifier())) {
target.setGlobalIdCreateTime(new Timestamp(new Date().getTime()));
ctxt.em().merge(target);
ctxt.em().flush();
} else {
// do nothing - we'll know it failed because the global id create time won't have been updated.
}
} catch (Exception e) {
// do nothing - idem and the problem has been logged
}
}
use of edu.harvard.iq.dataverse.engine.command.exception.PermissionException in project dataverse by IQSS.
the class ListDataverseContentCommand method execute.
@Override
public List<DvObject> execute(CommandContext ctxt) throws CommandException {
LinkedList<DvObject> result = new LinkedList<>();
for (Dataset ds : ctxt.datasets().findByOwnerId(dvToList.getId())) {
try {
ds = ctxt.engine().submit(new GetDatasetCommand(getRequest(), ds));
result.add(ds);
} catch (PermissionException ex) {
}
}
for (Dataverse dv : ctxt.dataverses().findByOwnerId(dvToList.getId())) {
try {
dv = ctxt.engine().submit(new GetDataverseCommand(getRequest(), dv));
result.add(dv);
} catch (PermissionException ex) {
}
}
return result;
}
use of edu.harvard.iq.dataverse.engine.command.exception.PermissionException in project dataverse by IQSS.
the class RequestRsyncScriptCommand method execute.
@Override
public ScriptRequestResponse execute(CommandContext ctxt) throws CommandException {
if (request == null) {
throw new PermissionException("DataverseRequest cannot be null.", this, Collections.singleton(Permission.AddDataset), dataset);
}
String dcmBaseUrl = ctxt.settings().getValueForKey(DataCaptureModuleUrl);
if (dcmBaseUrl == null) {
throw new RuntimeException(DataCaptureModuleUrl + " is null!");
}
User user = request.getUser();
if (!(user instanceof AuthenticatedUser)) {
/**
* @todo get Permission.AddDataset from above somehow rather than
* duplicating it here.
*/
throw new PermissionException("This command can only be called by an AuthenticatedUser, not " + user, this, Collections.singleton(Permission.AddDataset), dataset);
}
// We need an AuthenticatedUser so we can pass its database id to the DCM.
AuthenticatedUser authenticatedUser = (AuthenticatedUser) user;
String errorPreamble = "User id " + authenticatedUser.getId() + " had a problem retrieving rsync script for dataset id " + dataset.getId() + " from Data Capture Module.";
String jsonString = DataCaptureModuleUtil.generateJsonForUploadRequest(authenticatedUser, dataset).toString();
UploadRequestResponse uploadRequestResponse = null;
try {
uploadRequestResponse = ctxt.dataCaptureModule().requestRsyncScriptCreation(jsonString, dcmBaseUrl + DataCaptureModuleServiceBean.uploadRequestPath);
} catch (DataCaptureModuleException ex) {
throw new RuntimeException("Problem making upload request to Data Capture Module: " + DataCaptureModuleUtil.getMessageFromException(ex));
}
int statusCode = uploadRequestResponse.getHttpStatusCode();
String response = uploadRequestResponse.getResponse();
if (statusCode != 200) {
throw new RuntimeException("When making the upload request, rather than 200 the status code was " + statusCode + ". The body was \'" + response + "\'. We cannot proceed. Returning.");
}
long millisecondsToSleep = DataCaptureModuleServiceBean.millisecondsToSleepBetweenUploadRequestAndScriptRequestCalls;
logger.fine("Message from Data Caputure Module upload request endpoint: " + response + ". Sleeping " + millisecondsToSleep + " milliseconds before making rsync script request.");
try {
Thread.sleep(millisecondsToSleep);
} catch (InterruptedException ex) {
throw new RuntimeException(errorPreamble + " Unable to wait " + millisecondsToSleep + " milliseconds: " + ex.getLocalizedMessage());
}
ScriptRequestResponse scriptRequestResponse = null;
try {
scriptRequestResponse = ctxt.dataCaptureModule().retreiveRequestedRsyncScript(dataset.getIdentifier(), dcmBaseUrl + DataCaptureModuleServiceBean.scriptRequestPath);
} catch (DataCaptureModuleException ex) {
throw new RuntimeException("Problem making script request to Data Capture Module: " + DataCaptureModuleUtil.getMessageFromException(ex));
}
String script = scriptRequestResponse.getScript();
if (script == null || script.isEmpty()) {
logger.warning("There was a problem getting the script. DCM returned status code: " + scriptRequestResponse.getHttpStatusCode());
}
logger.fine("script for dataset " + dataset.getId() + ": " + script);
return scriptRequestResponse;
}
use of edu.harvard.iq.dataverse.engine.command.exception.PermissionException in project dataverse by IQSS.
the class ManagePermissionsPage method revokeRole.
// internal method used by removeRoleAssignment and saveConfiguration
private void revokeRole(RoleAssignment ra) {
try {
commandEngine.submit(new RevokeRoleCommand(ra, dvRequestService.getDataverseRequest()));
JsfHelper.addSuccessMessage(ra.getRole().getName() + " role for " + roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier()).getDisplayInfo().getTitle() + " was removed.");
RoleAssignee assignee = roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier());
notifyRoleChange(assignee, UserNotification.Type.REVOKEROLE);
} catch (PermissionException ex) {
JH.addMessage(FacesMessage.SEVERITY_ERROR, "The role assignment was not able to be removed.", "Permissions " + ex.getRequiredPermissions().toString() + " missing.");
} catch (CommandException ex) {
JH.addMessage(FacesMessage.SEVERITY_FATAL, "The role assignment could not be removed.");
logger.log(Level.SEVERE, "Error removing role assignment: " + ex.getMessage(), ex);
}
}
Aggregations