Search in sources :

Example 21 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee 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 22 with RoleAssignee

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

the class ManageFilePermissionsPage method addFileToRoleAssignee.

private void addFileToRoleAssignee(RoleAssignment assignment) {
    RoleAssignee ra = roleAssigneeService.getRoleAssignee(assignment.getAssigneeIdentifier());
    List<RoleAssignmentRow> assignments = roleAssigneeMap.get(ra);
    if (assignments == null) {
        assignments = new ArrayList<>();
        roleAssigneeMap.put(ra, assignments);
    }
    assignments.add(new RoleAssignmentRow(assignment, ra.getDisplayInfo()));
}
Also used : RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 23 with RoleAssignee

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

the class ManageGroupsPage method createExplicitGroup.

public void createExplicitGroup(ActionEvent ae) {
    ExplicitGroup eg = explicitGroupService.getProvider().makeGroup();
    eg.setDisplayName(getExplicitGroupName());
    eg.setGroupAliasInOwner(getExplicitGroupIdentifier());
    eg.setDescription(getNewExplicitGroupDescription());
    if (getNewExplicitGroupRoleAssignees() != null) {
        try {
            for (RoleAssignee ra : getNewExplicitGroupRoleAssignees()) {
                eg.add(ra);
            }
        } catch (GroupException ge) {
            JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Creation failed.", ge.getMessage());
            return;
        }
    }
    try {
        eg = engineService.submit(new CreateExplicitGroupCommand(dvRequestService.getDataverseRequest(), this.dataverse, eg));
        explicitGroups.add(eg);
        JsfHelper.addSuccessMessage("Succesfully created group " + eg.getDisplayName() + ". Refresh to update your page.");
    } catch (CreateExplicitGroupCommand.GroupAliasExistsException gaee) {
        explicitGroupIdentifierField.setValid(false);
        FacesContext.getCurrentInstance().addMessage(explicitGroupIdentifierField.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, gaee.getMessage(), null));
    } catch (CommandException ex) {
        logger.log(Level.WARNING, "Group creation failed", ex);
        JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Creation failed.", ex.getMessage());
    } catch (Exception ex) {
        JH.addMessage(FacesMessage.SEVERITY_FATAL, "The role was not able to be saved.");
        logger.log(Level.SEVERE, "Error saving role: " + ex.getMessage(), ex);
    }
    showAssignmentMessages();
}
Also used : CreateExplicitGroupCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateExplicitGroupCommand) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) FacesMessage(javax.faces.application.FacesMessage) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 24 with RoleAssignee

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

the class ManageGroupsPage method getMembershipString.

public String getMembershipString(ExplicitGroup eg) {
    long userCount = 0;
    long groupCount = 0;
    for (RoleAssignee ra : eg.getDirectMembers()) {
        if (ra instanceof User) {
            userCount++;
        } else {
            groupCount++;
        }
    }
    if (userCount == 0 && groupCount == 0) {
        return "No members";
    }
    String memberString = "";
    if (userCount == 1) {
        memberString = "1 user";
    } else if (userCount != 1) {
        memberString = Long.toString(userCount) + " users";
    }
    if (groupCount == 1) {
        memberString = memberString + ", 1 group";
    } else if (groupCount != 1) {
        memberString = memberString + ", " + Long.toString(groupCount) + " groups";
    }
    return memberString;
}
Also used : User(edu.harvard.iq.dataverse.authorization.users.User) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 25 with RoleAssignee

use of edu.harvard.iq.dataverse.authorization.RoleAssignee 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)

Aggregations

RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)35 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)19 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)19 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)18 Test (org.junit.Test)17 Dataset (edu.harvard.iq.dataverse.Dataset)13 DvObject (edu.harvard.iq.dataverse.DvObject)11 ArrayList (java.util.ArrayList)6 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 GroupException (edu.harvard.iq.dataverse.authorization.groups.GroupException)3 ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 AssignRoleCommand (edu.harvard.iq.dataverse.engine.command.impl.AssignRoleCommand)2 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)2 LinkedList (java.util.LinkedList)2 JsonObject (javax.json.JsonObject)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 POST (javax.ws.rs.POST)2