Search in sources :

Example 91 with AuthenticatedUser

use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.

the class PermissionServiceBean method getUsersWithPermissionOn.

public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
    List<AuthenticatedUser> usersHasPermissionOn = new LinkedList<>();
    Set<RoleAssignment> ras = roleService.rolesAssignments(dvo);
    for (RoleAssignment ra : ras) {
        if (ra.getRole().permissions().contains(permission)) {
            RoleAssignee raee = roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier());
            usersHasPermissionOn.addAll(roleAssigneeService.getExplicitUsers(raee));
        }
    }
    return usersHasPermissionOn;
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) LinkedList(java.util.LinkedList) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 92 with AuthenticatedUser

use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.

the class ManageFilePermissionsPage method initMaps.

private void initMaps() {
    // initialize files and usergroup list
    roleAssigneeMap.clear();
    fileMap.clear();
    fileAccessRequestMap.clear();
    for (DataFile file : dataset.getFiles()) {
        // Added a null check in case there are files that have no metadata records SEK
        if (file.getFileMetadata() != null && (file.isRestricted() || file.getFileMetadata().isRestricted())) {
            // we get the direct role assignments assigned to the file
            List<RoleAssignment> ras = roleService.directRoleAssignments(file);
            List<RoleAssignmentRow> raList = new ArrayList<>(ras.size());
            for (RoleAssignment ra : ras) {
                // for files, only show role assignments which can download
                if (ra.getRole().permissions().contains(Permission.DownloadFile)) {
                    raList.add(new RoleAssignmentRow(ra, roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier()).getDisplayInfo()));
                    addFileToRoleAssignee(ra);
                }
            }
            fileMap.put(file, raList);
            // populate the file access requests map
            for (AuthenticatedUser au : file.getFileAccessRequesters()) {
                List<DataFile> requestedFiles = fileAccessRequestMap.get(au);
                if (requestedFiles == null) {
                    requestedFiles = new ArrayList<>();
                    fileAccessRequestMap.put(au, requestedFiles);
                }
                requestedFiles.add(file);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Example 93 with AuthenticatedUser

use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.

the class MailServiceBean method getMessageTextBasedOnNotification.

public String getMessageTextBasedOnNotification(UserNotification userNotification, Object targetObject, String comment) {
    String messageText = ResourceBundle.getBundle("Bundle").getString("notification.email.greeting");
    DatasetVersion version;
    Dataset dataset;
    DvObject dvObj;
    String dvObjURL;
    String dvObjTypeStr;
    String pattern;
    switch(userNotification.getType()) {
        case ASSIGNROLE:
            AuthenticatedUser au = userNotification.getUser();
            dvObj = (DvObject) targetObject;
            String joinedRoleNames = getRoleStringFromUser(au, dvObj);
            dvObjURL = getDvObjectLink(dvObj);
            dvObjTypeStr = getDvObjectTypeString(dvObj);
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.assignRole");
            String[] paramArrayAssignRole = { joinedRoleNames, dvObjTypeStr, dvObj.getDisplayName(), dvObjURL };
            messageText += MessageFormat.format(pattern, paramArrayAssignRole);
            if (joinedRoleNames.contains("File Downloader")) {
                if (dvObjTypeStr.equals("dataset")) {
                    pattern = ResourceBundle.getBundle("Bundle").getString("notification.access.granted.fileDownloader.additionalDataset");
                    String[] paramArrayAssignRoleDS = { " " };
                    messageText += MessageFormat.format(pattern, paramArrayAssignRoleDS);
                }
                if (dvObjTypeStr.equals("dataverse")) {
                    pattern = ResourceBundle.getBundle("Bundle").getString("notification.access.granted.fileDownloader.additionalDataverse");
                    String[] paramArrayAssignRoleDV = { " " };
                    messageText += MessageFormat.format(pattern, paramArrayAssignRoleDV);
                }
            }
            return messageText;
        case REVOKEROLE:
            dvObj = (DvObject) targetObject;
            dvObjURL = getDvObjectLink(dvObj);
            dvObjTypeStr = getDvObjectTypeString(dvObj);
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.revokeRole");
            String[] paramArrayRevokeRole = { dvObjTypeStr, dvObj.getDisplayName(), dvObjURL };
            messageText += MessageFormat.format(pattern, paramArrayRevokeRole);
            return messageText;
        case CREATEDV:
            Dataverse dataverse = (Dataverse) targetObject;
            Dataverse parentDataverse = dataverse.getOwner();
            // initialize to empty string in the rare case that there is no parent dataverse (i.e. root dataverse just created)
            String parentDataverseDisplayName = "";
            String parentDataverseUrl = "";
            if (parentDataverse != null) {
                parentDataverseDisplayName = parentDataverse.getDisplayName();
                parentDataverseUrl = getDataverseLink(parentDataverse);
            }
            String dataverseCreatedMessage = BundleUtil.getStringFromBundle("notification.email.createDataverse", Arrays.asList(dataverse.getDisplayName(), getDataverseLink(dataverse), parentDataverseDisplayName, parentDataverseUrl, systemConfig.getGuidesBaseUrl(), systemConfig.getGuidesVersion()));
            logger.fine(dataverseCreatedMessage);
            return messageText += dataverseCreatedMessage;
        case REQUESTFILEACCESS:
            DataFile datafile = (DataFile) targetObject;
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.requestFileAccess");
            String[] paramArrayRequestFileAccess = { datafile.getOwner().getDisplayName(), getDatasetManageFileAccessLink(datafile) };
            messageText += MessageFormat.format(pattern, paramArrayRequestFileAccess);
            return messageText;
        case GRANTFILEACCESS:
            dataset = (Dataset) targetObject;
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.grantFileAccess");
            String[] paramArrayGrantFileAccess = { dataset.getDisplayName(), getDatasetLink(dataset) };
            messageText += MessageFormat.format(pattern, paramArrayGrantFileAccess);
            return messageText;
        case REJECTFILEACCESS:
            dataset = (Dataset) targetObject;
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.rejectFileAccess");
            String[] paramArrayRejectFileAccess = { dataset.getDisplayName(), getDatasetLink(dataset) };
            messageText += MessageFormat.format(pattern, paramArrayRejectFileAccess);
            return messageText;
        case CREATEDS:
            version = (DatasetVersion) targetObject;
            String datasetCreatedMessage = BundleUtil.getStringFromBundle("notification.email.createDataset", Arrays.asList(version.getDataset().getDisplayName(), getDatasetLink(version.getDataset()), version.getDataset().getOwner().getDisplayName(), getDataverseLink(version.getDataset().getOwner()), systemConfig.getGuidesBaseUrl(), systemConfig.getGuidesVersion()));
            logger.fine(datasetCreatedMessage);
            return messageText += datasetCreatedMessage;
        case MAPLAYERUPDATED:
            version = (DatasetVersion) targetObject;
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.worldMap.added");
            String[] paramArrayMapLayer = { version.getDataset().getDisplayName(), getDatasetLink(version.getDataset()) };
            messageText += MessageFormat.format(pattern, paramArrayMapLayer);
            return messageText;
        case MAPLAYERDELETEFAILED:
            FileMetadata targetFileMetadata = (FileMetadata) targetObject;
            version = targetFileMetadata.getDatasetVersion();
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.maplayer.deletefailed.text");
            String[] paramArrayMapLayerDelete = { targetFileMetadata.getLabel(), getDatasetLink(version.getDataset()) };
            messageText += MessageFormat.format(pattern, paramArrayMapLayerDelete);
            return messageText;
        case SUBMITTEDDS:
            version = (DatasetVersion) targetObject;
            String mightHaveSubmissionComment = "";
            /*
                FIXME
                Setting up to add single comment when design completed
                "submissionComment" needs to be added to Bundle
                mightHaveSubmissionComment = ".";
                if (comment != null && !comment.isEmpty()) {
                    mightHaveSubmissionComment = ".\n\n" + BundleUtil.getStringFromBundle("submissionComment") + "\n\n" + comment;
                }
                */
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.wasSubmittedForReview");
            String[] paramArraySubmittedDataset = { version.getDataset().getDisplayName(), getDatasetDraftLink(version.getDataset()), version.getDataset().getOwner().getDisplayName(), getDataverseLink(version.getDataset().getOwner()), mightHaveSubmissionComment };
            messageText += MessageFormat.format(pattern, paramArraySubmittedDataset);
            return messageText;
        case PUBLISHEDDS:
            version = (DatasetVersion) targetObject;
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.wasPublished");
            String[] paramArrayPublishedDataset = { version.getDataset().getDisplayName(), getDatasetLink(version.getDataset()), version.getDataset().getOwner().getDisplayName(), getDataverseLink(version.getDataset().getOwner()) };
            messageText += MessageFormat.format(pattern, paramArrayPublishedDataset);
            return messageText;
        case RETURNEDDS:
            version = (DatasetVersion) targetObject;
            pattern = ResourceBundle.getBundle("Bundle").getString("notification.email.wasReturnedByReviewer");
            String optionalReturnReason = "";
            /*
                FIXME
                Setting up to add single comment when design completed
                optionalReturnReason = ".";
                if (comment != null && !comment.isEmpty()) {
                    optionalReturnReason = ".\n\n" + BundleUtil.getStringFromBundle("wasReturnedReason") + "\n\n" + comment;
                }
                */
            String[] paramArrayReturnedDataset = { version.getDataset().getDisplayName(), getDatasetDraftLink(version.getDataset()), version.getDataset().getOwner().getDisplayName(), getDataverseLink(version.getDataset().getOwner()), optionalReturnReason };
            messageText += MessageFormat.format(pattern, paramArrayReturnedDataset);
            return messageText;
        case CREATEACC:
            String rootDataverseName = dataverseService.findRootDataverse().getName();
            InternetAddress systemAddress = getSystemAddress();
            String accountCreatedMessage = BundleUtil.getStringFromBundle("notification.email.welcome", Arrays.asList(BrandingUtil.getInstallationBrandName(rootDataverseName), systemConfig.getGuidesBaseUrl(), systemConfig.getGuidesVersion(), BrandingUtil.getSupportTeamName(systemAddress, rootDataverseName), BrandingUtil.getSupportTeamEmailAddress(systemAddress)));
            String optionalConfirmEmailAddon = confirmEmailService.optionalConfirmEmailAddonMsg(userNotification.getUser());
            accountCreatedMessage += optionalConfirmEmailAddon;
            logger.fine("accountCreatedMessage: " + accountCreatedMessage);
            return messageText += accountCreatedMessage;
        case CHECKSUMFAIL:
            dataset = (Dataset) targetObject;
            String checksumFailMsg = BundleUtil.getStringFromBundle("notification.checksumfail", Arrays.asList(dataset.getGlobalId()));
            logger.fine("checksumFailMsg: " + checksumFailMsg);
            return messageText += checksumFailMsg;
        case FILESYSTEMIMPORT:
            version = (DatasetVersion) targetObject;
            String fileImportMsg = BundleUtil.getStringFromBundle("notification.mail.import.filesystem", Arrays.asList(systemConfig.getDataverseSiteUrl(), version.getDataset().getGlobalId(), version.getDataset().getDisplayName()));
            logger.fine("fileImportMsg: " + fileImportMsg);
            return messageText += fileImportMsg;
        case CHECKSUMIMPORT:
            version = (DatasetVersion) targetObject;
            String checksumImportMsg = BundleUtil.getStringFromBundle("notification.import.checksum", Arrays.asList(version.getDataset().getGlobalId(), version.getDataset().getDisplayName()));
            logger.fine("checksumImportMsg: " + checksumImportMsg);
            return messageText += checksumImportMsg;
    }
    return "";
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Example 94 with AuthenticatedUser

use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.

the class Admin method startConfirmEmailProcess.

/**
 * This method is used in integration tests.
 *
 * @param userId The database id of an AuthenticatedUser.
 */
@Path("confirmEmail/{userId}")
@POST
public Response startConfirmEmailProcess(@PathParam("userId") long userId) {
    AuthenticatedUser user = authSvc.findByID(userId);
    if (user != null) {
        try {
            ConfirmEmailInitResponse confirmEmailInitResponse = confirmEmailSvc.beginConfirm(user);
            ConfirmEmailData confirmEmailData = confirmEmailInitResponse.getConfirmEmailData();
            return ok(Json.createObjectBuilder().add("tokenCreated", confirmEmailData.getCreated().toString()).add("identifier", user.getUserIdentifier()));
        } catch (ConfirmEmailException ex) {
            return error(Status.BAD_REQUEST, "Could not start confirm email process for user " + userId + ": " + ex.getLocalizedMessage());
        }
    }
    return error(Status.BAD_REQUEST, "Could not find user based on " + userId);
}
Also used : ConfirmEmailException(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailException) ConfirmEmailInitResponse(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailInitResponse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) ConfirmEmailData(edu.harvard.iq.dataverse.confirmemail.ConfirmEmailData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 95 with AuthenticatedUser

use of edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser in project dataverse by IQSS.

the class Admin method createAuthenicatedUser.

/**
 * @todo Make this support creation of BuiltInUsers.
 *
 * @todo Add way more error checking. Only the happy path is tested by
 * AdminIT.
 */
@POST
@Path("authenticatedUsers")
public Response createAuthenicatedUser(JsonObject jsonObject) {
    logger.fine("JSON in: " + jsonObject);
    String persistentUserId = jsonObject.getString("persistentUserId");
    String identifier = jsonObject.getString("identifier");
    String proposedAuthenticatedUserIdentifier = identifier.replaceFirst("@", "");
    String firstName = jsonObject.getString("firstName");
    String lastName = jsonObject.getString("lastName");
    String emailAddress = jsonObject.getString("email");
    String position = null;
    String affiliation = null;
    UserRecordIdentifier userRecordId = new UserRecordIdentifier(jsonObject.getString("authenticationProviderId"), persistentUserId);
    AuthenticatedUserDisplayInfo userDisplayInfo = new AuthenticatedUserDisplayInfo(firstName, lastName, emailAddress, affiliation, position);
    boolean generateUniqueIdentifier = true;
    AuthenticatedUser authenticatedUser = authSvc.createAuthenticatedUser(userRecordId, proposedAuthenticatedUserIdentifier, userDisplayInfo, true);
    return ok(json(authenticatedUser));
}
Also used : AuthenticatedUserDisplayInfo(edu.harvard.iq.dataverse.authorization.AuthenticatedUserDisplayInfo) UserRecordIdentifier(edu.harvard.iq.dataverse.authorization.UserRecordIdentifier) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)125 Dataverse (edu.harvard.iq.dataverse.Dataverse)24 Timestamp (java.sql.Timestamp)24 Date (java.util.Date)24 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 Dataset (edu.harvard.iq.dataverse.Dataset)22 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)21 Path (javax.ws.rs.Path)19 EJBException (javax.ejb.EJBException)16 ArrayList (java.util.ArrayList)14 User (edu.harvard.iq.dataverse.authorization.users.User)13 DataFile (edu.harvard.iq.dataverse.DataFile)11 IOException (java.io.IOException)11 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 POST (javax.ws.rs.POST)11 Test (org.junit.Test)11 BuiltinUser (edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser)10 SwordError (org.swordapp.server.SwordError)10 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)8 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)8