Search in sources :

Example 16 with DataverseRole

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

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeSuccess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee assignee = privateUrlUser;
    DvObject dataset = new Dataset();
    dataset.setId(42l);
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNotNull(privateUrl);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 17 with DataverseRole

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

the class ManageFilePermissionsPage method grantAccess.

public void grantAccess(ActionEvent evt) {
    // Find the built in file downloader role (currently by alias)
    DataverseRole fileDownloaderRole = roleService.findBuiltinRoleByAlias(DataverseRole.FILE_DOWNLOADER);
    for (RoleAssignee roleAssignee : selectedRoleAssignees) {
        boolean sendNotification = false;
        for (DataFile file : selectedFiles) {
            if (assignRole(roleAssignee, file, fileDownloaderRole)) {
                if (file.isReleased()) {
                    sendNotification = true;
                }
                // remove request, if it exist
                if (file.getFileAccessRequesters().remove(roleAssignee)) {
                    datafileService.save(file);
                }
            }
        }
        if (sendNotification) {
            for (AuthenticatedUser au : roleAssigneeService.getExplicitUsers(roleAssignee)) {
                userNotificationService.sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.GRANTFILEACCESS, dataset.getId());
            }
        }
    }
    initMaps();
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Timestamp(java.sql.Timestamp) Date(java.util.Date) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 18 with DataverseRole

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

the class ManageFilePermissionsPage method grantAccessToRequests.

private void grantAccessToRequests(AuthenticatedUser au, List<DataFile> files) {
    boolean actionPerformed = false;
    // Find the built in file downloader role (currently by alias)
    DataverseRole fileDownloaderRole = roleService.findBuiltinRoleByAlias(DataverseRole.FILE_DOWNLOADER);
    for (DataFile file : files) {
        if (assignRole(au, file, fileDownloaderRole)) {
            file.getFileAccessRequesters().remove(au);
            datafileService.save(file);
            actionPerformed = true;
        }
    }
    if (actionPerformed) {
        JsfHelper.addSuccessMessage("File Access request by " + au.getDisplayInfo().getTitle() + " was granted.");
        userNotificationService.sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.GRANTFILEACCESS, dataset.getId());
        initMaps();
    }
}
Also used : Timestamp(java.sql.Timestamp) Date(java.util.Date) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 19 with DataverseRole

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

the class RoleAssigneeServiceBean method getAssigneeDataverseRoleFor.

public List<DataverseRole> getAssigneeDataverseRoleFor(DataverseRequest dataverseRequest) {
    if (dataverseRequest == null) {
        throw new NullPointerException("dataverseRequest cannot be null!");
    }
    AuthenticatedUser au = dataverseRequest.getAuthenticatedUser();
    if (au.getUserIdentifier() == null) {
        return null;
    }
    String roleAssigneeIdentifier = "@" + au.getUserIdentifier();
    List<DataverseRole> retList = new ArrayList<>();
    // remove spaces from string
    roleAssigneeIdentifier = roleAssigneeIdentifier.replaceAll("\\s", "");
    List<String> userGroups = getUserExplicitGroups(au);
    List<String> userRunTimeGroups = getUserRuntimeGroups(dataverseRequest);
    String identifierClause = " WHERE r.assigneeIdentifier= '" + roleAssigneeIdentifier + "'";
    if (userGroups != null || userRunTimeGroups != null) {
        identifierClause = getGroupIdentifierClause(roleAssigneeIdentifier, userGroups, userRunTimeGroups);
    }
    String qstr = "SELECT distinct r.role_id";
    qstr += " FROM RoleAssignment r";
    qstr += identifierClause;
    qstr += ";";
    msg("qstr: " + qstr);
    for (Object o : em.createNativeQuery(qstr).getResultList()) {
        retList.add(dataverseRoleService.find((Long) o));
    }
    return retList;
}
Also used : ArrayList(java.util.ArrayList) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 20 with DataverseRole

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

the class RolePermissionFragment method createNewRole.

public void createNewRole(ActionEvent e) {
    setRole(new DataverseRole());
    role.setOwner(dvObject);
}
Also used : DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Aggregations

DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)44 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)23 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)18 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)6 ArrayList (java.util.ArrayList)5 User (edu.harvard.iq.dataverse.authorization.users.User)4 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)3 Permission (edu.harvard.iq.dataverse.authorization.Permission)3 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)3 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)3 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)3 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)3 Timestamp (java.sql.Timestamp)3