Search in sources :

Example 16 with RoleAssignee

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

the class SearchPermissionsServiceBean method findDirectAssignments.

@Deprecated
private List<String> findDirectAssignments(DvObject dvObject) {
    List<String> permStrings = new ArrayList<>();
    List<RoleAssignee> roleAssignees = findWhoHasDirectAssignments(dvObject);
    for (RoleAssignee roleAssignee : roleAssignees) {
        logger.fine("user or group (findDirectAssignments): " + roleAssignee.getIdentifier());
        String indexableUserOrGroupPermissionString = getIndexableStringForUserOrGroup(roleAssignee);
        if (indexableUserOrGroupPermissionString != null) {
            permStrings.add(indexableUserOrGroupPermissionString);
        }
    }
    return permStrings;
}
Also used : ArrayList(java.util.ArrayList) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 17 with RoleAssignee

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

the class JsonPrinterTest method testJson_RoleAssignment.

@Test
public void testJson_RoleAssignment() {
    DataverseRole aRole = new DataverseRole();
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    Dataset dataset = new Dataset();
    dataset.setId(123l);
    String privateUrlToken = "e1d53cf6-794a-457a-9709-7c07629a8267";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    JsonObjectBuilder job = JsonPrinter.json(ra);
    assertNotNull(job);
    JsonObject jsonObject = job.build();
    assertEquals("#42", jsonObject.getString("assignee"));
    assertEquals(123, jsonObject.getInt("definitionPointId"));
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("privateUrlToken"));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 18 with RoleAssignee

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

the class ManagePermissionsPage method initRoleAssignments.

public List<RoleAssignmentRow> initRoleAssignments() {
    List<RoleAssignmentRow> raList = null;
    if (dvObject != null && dvObject.getId() != null) {
        Set<RoleAssignment> ras = roleService.rolesAssignments(dvObject);
        raList = new ArrayList<>(ras.size());
        for (RoleAssignment roleAssignment : ras) {
            // for files, only show role assignments which can download
            if (!(dvObject instanceof DataFile) || roleAssignment.getRole().permissions().contains(Permission.DownloadFile)) {
                RoleAssignee roleAssignee = roleAssigneeService.getRoleAssignee(roleAssignment.getAssigneeIdentifier());
                if (roleAssignee != null) {
                    raList.add(new RoleAssignmentRow(roleAssignment, roleAssignee.getDisplayInfo()));
                } else {
                    logger.info("Could not find role assignee based on role assignment id " + roleAssignment.getId());
                }
            }
        }
    }
    return raList;
}
Also used : RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee)

Example 19 with RoleAssignee

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

Example 20 with RoleAssignee

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

the class ManagePermissionsPage method assignRole.

public void assignRole(ActionEvent evt) {
    logger.info("Got to assignRole");
    List<RoleAssignee> selectedRoleAssigneesList = getRoleAssignSelectedRoleAssignees();
    if (selectedRoleAssigneesList == null) {
        logger.info("** SELECTED role asignees is null");
        selectedRoleAssigneesList = new LinkedList<>();
    }
    for (RoleAssignee roleAssignee : selectedRoleAssigneesList) {
        assignRole(roleAssignee, roleService.find(selectedRoleId));
    }
    roleAssignments = initRoleAssignments();
}
Also used : 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