Search in sources :

Example 11 with PermissionException

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);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 12 with PermissionException

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
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) IdServiceBean(edu.harvard.iq.dataverse.IdServiceBean) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Timestamp(java.sql.Timestamp) Date(java.util.Date) PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException)

Example 13 with PermissionException

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;
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) Dataverse(edu.harvard.iq.dataverse.Dataverse) LinkedList(java.util.LinkedList)

Example 14 with PermissionException

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;
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) ScriptRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) UploadRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.UploadRequestResponse) DataCaptureModuleException(edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Example 15 with PermissionException

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);
    }
}
Also used : PermissionException(edu.harvard.iq.dataverse.engine.command.exception.PermissionException) RevokeRoleCommand(edu.harvard.iq.dataverse.engine.command.impl.RevokeRoleCommand) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Aggregations

PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)17 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)15 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)8 DataFile (edu.harvard.iq.dataverse.DataFile)3 Dataset (edu.harvard.iq.dataverse.Dataset)3 RevokeRoleCommand (edu.harvard.iq.dataverse.engine.command.impl.RevokeRoleCommand)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 IdServiceBean (edu.harvard.iq.dataverse.IdServiceBean)2 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)2 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)2 AssignRoleCommand (edu.harvard.iq.dataverse.engine.command.impl.AssignRoleCommand)2 DvObject (edu.harvard.iq.dataverse.DvObject)1 Guestbook (edu.harvard.iq.dataverse.Guestbook)1 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)1 ActionLogRecord (edu.harvard.iq.dataverse.actionlogging.ActionLogRecord)1 Permission (edu.harvard.iq.dataverse.authorization.Permission)1 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)1 User (edu.harvard.iq.dataverse.authorization.users.User)1 DataCaptureModuleException (edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleException)1 ScriptRequestResponse (edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse)1