Search in sources :

Example 21 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class Dataverses method deleteAssignment.

@DELETE
@Path("{identifier}/assignments/{id}")
public Response deleteAssignment(@PathParam("id") long assignmentId, @PathParam("identifier") String dvIdtf) {
    RoleAssignment ra = em.find(RoleAssignment.class, assignmentId);
    if (ra != null) {
        try {
            findDataverseOrDie(dvIdtf);
            execCommand(new RevokeRoleCommand(ra, createDataverseRequest(findUserOrDie())));
            return ok("Role " + ra.getRole().getName() + " revoked for assignee " + ra.getAssigneeIdentifier() + " in " + ra.getDefinitionPoint().accept(DvObject.NamePrinter));
        } catch (WrappedResponse ex) {
            return ex.getResponse();
        }
    } else {
        return error(Status.NOT_FOUND, "Role assignment " + assignmentId + " not found");
    }
}
Also used : RevokeRoleCommand(edu.harvard.iq.dataverse.engine.command.impl.RevokeRoleCommand) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 22 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class SearchPermissionsServiceBean method findDvObjectPerms.

public List<String> findDvObjectPerms(DvObject dvObject) {
    List<String> permStrings = new ArrayList<>();
    resetRoleAssigneeCache();
    Set<RoleAssignment> roleAssignments = rolesSvc.rolesAssignments(dvObject);
    for (RoleAssignment roleAssignment : roleAssignments) {
        logger.fine("role assignment on dvObject " + dvObject.getId() + ": " + roleAssignment.getAssigneeIdentifier());
        if (roleAssignment.getRole().permissions().contains(getRequiredSearchPermission(dvObject))) {
            RoleAssignee userOrGroup = getRoleAssignee(roleAssignment.getAssigneeIdentifier());
            String indexableUserOrGroupPermissionString = getIndexableStringForUserOrGroup(userOrGroup);
            if (indexableUserOrGroupPermissionString != null) {
                permStrings.add(indexableUserOrGroupPermissionString);
            }
        }
    }
    resetRoleAssigneeCache();
    return permStrings;
}
Also used : RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 23 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class SearchPermissionsServiceBean method findWhoHasDirectAssignments.

@Deprecated
private List<RoleAssignee> findWhoHasDirectAssignments(DvObject dvObject) {
    List<RoleAssignee> emptyList = new ArrayList<>();
    List<RoleAssignee> peopleWhoCanSearch = emptyList;
    resetRoleAssigneeCache();
    List<RoleAssignment> assignmentsOn = permissionService.assignmentsOn(dvObject);
    for (RoleAssignment roleAssignment : assignmentsOn) {
        if (roleAssignment.getRole().permissions().contains(getRequiredSearchPermission(dvObject))) {
            RoleAssignee userOrGroup = getRoleAssignee(roleAssignment.getAssigneeIdentifier());
            if (userOrGroup != null) {
                peopleWhoCanSearch.add(userOrGroup);
            }
        }
    }
    resetRoleAssigneeCache();
    return peopleWhoCanSearch;
}
Also used : RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 24 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class PrivateUrlServiceBean method getRoleAssignmentFromPrivateUrlToken.

/**
 * @return A RoleAssignment or null.
 *
 * @todo This might be a good place for Optional.
 */
private RoleAssignment getRoleAssignmentFromPrivateUrlToken(String privateUrlToken) {
    if (privateUrlToken == null) {
        return null;
    }
    TypedQuery<RoleAssignment> query = em.createNamedQuery("RoleAssignment.listByPrivateUrlToken", RoleAssignment.class);
    query.setParameter("privateUrlToken", privateUrlToken);
    try {
        RoleAssignment roleAssignment = query.getSingleResult();
        return roleAssignment;
    } catch (NoResultException | NonUniqueResultException ex) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) NoResultException(javax.persistence.NoResultException)

Example 25 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class DataverseUserPage method getRoleStringFromUser.

private String getRoleStringFromUser(AuthenticatedUser au, DvObject dvObj) {
    // Find user's role(s) for given dataverse/dataset
    Set<RoleAssignment> roles = permissionService.assignmentsFor(au, dvObj);
    List<String> roleNames = new ArrayList<>();
    // Include roles derived from a user's groups
    Set<Group> groupsUserBelongsTo = groupService.groupsFor(au, dvObj);
    for (Group g : groupsUserBelongsTo) {
        roles.addAll(permissionService.assignmentsFor(g, dvObj));
    }
    for (RoleAssignment ra : roles) {
        roleNames.add(ra.getRole().getName());
    }
    if (roleNames.isEmpty()) {
        return "[Unknown]";
    }
    return StringUtils.join(roleNames, "/");
}
Also used : Group(edu.harvard.iq.dataverse.authorization.groups.Group) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList)

Aggregations

RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)38 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)23 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)22 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)14 Dataverse (edu.harvard.iq.dataverse.Dataverse)8 ArrayList (java.util.ArrayList)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)7 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)6 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)5 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)4 User (edu.harvard.iq.dataverse.authorization.users.User)4 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)4 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)4 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)4 Before (org.junit.Before)4 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)3