Search in sources :

Example 1 with ExplicitGroup

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.

the class GroupServiceBean method groupTransitiveClosure.

/**
 * Given a set of groups and a DV object, return all the groups that are
 * reachable from the set. Effectively, if the initial set has an {@link ExplicitGroup},
 * recursively add all the groups it contains.
 *
 * @param groups
 * @param dvo
 * @return All the groups included in the groups in {@code groups}.
 */
private Set<Group> groupTransitiveClosure(Set<Group> groups, DvObject dvo) {
    // now, get the explicit group transitive closure.
    Set<ExplicitGroup> perimeter = new HashSet<>();
    Set<ExplicitGroup> visited = new HashSet<>();
    groups.stream().filter((g) -> (g instanceof ExplicitGroup)).forEachOrdered((g) -> perimeter.add((ExplicitGroup) g));
    visited.addAll(perimeter);
    while (!perimeter.isEmpty()) {
        ExplicitGroup g = perimeter.iterator().next();
        perimeter.remove(g);
        groups.add(g);
        Set<ExplicitGroup> discovered = explicitGroupProvider.groupsFor(g, dvo);
        // Ideally the conjunction is always empty, as we don't allow cycles.
        discovered.removeAll(visited);
        // Still, coding defensively here, in case someone gets too
        // smart on the SQL console.
        perimeter.addAll(discovered);
        visited.addAll(discovered);
    }
    return groups;
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) ExplicitGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) HashMap(java.util.HashMap) Level(java.util.logging.Level) HashSet(java.util.HashSet) Map(java.util.Map) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) DvObject(edu.harvard.iq.dataverse.DvObject) Named(javax.inject.Named) Collectors.toSet(java.util.stream.Collectors.toSet) EJB(javax.ejb.EJB) Stateless(javax.ejb.Stateless) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) ShibGroupServiceBean(edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupServiceBean) BuiltInGroupsProvider(edu.harvard.iq.dataverse.authorization.groups.impl.builtin.BuiltInGroupsProvider) Collection(java.util.Collection) Set(java.util.Set) Logger(java.util.logging.Logger) Stream(java.util.stream.Stream) ExplicitGroupServiceBean(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean) PostConstruct(javax.annotation.PostConstruct) IpGroupsServiceBean(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupsServiceBean) ShibGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupProvider) RoleAssigneeServiceBean(edu.harvard.iq.dataverse.RoleAssigneeServiceBean) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) HashSet(java.util.HashSet)

Example 2 with ExplicitGroup

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.

the class Dataverses method createExplicitGroup.

@POST
@Path("{identifier}/groups/")
public Response createExplicitGroup(ExplicitGroupDTO dto, @PathParam("identifier") String dvIdtf) {
    return response(req -> {
        ExplicitGroupProvider prv = explicitGroupSvc.getProvider();
        ExplicitGroup newGroup = dto.apply(prv.makeGroup());
        newGroup = execCommand(new CreateExplicitGroupCommand(req, findDataverseOrDie(dvIdtf), newGroup));
        String groupUri = String.format("%s/groups/%s", dvIdtf, newGroup.getGroupAliasInOwner());
        return created(groupUri, json(newGroup));
    });
}
Also used : CreateExplicitGroupCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateExplicitGroupCommand) ExplicitGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider) JsonString(javax.json.JsonString) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with ExplicitGroup

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.

the class ManageGroupsPage method saveExplicitGroup.

public void saveExplicitGroup(ActionEvent ae) {
    ExplicitGroup eg = selectedGroup;
    if (getSelectedGroupAddRoleAssignees() != null) {
        try {
            for (RoleAssignee ra : getSelectedGroupAddRoleAssignees()) {
                eg.add(ra);
            }
        } catch (GroupException ge) {
            JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group edit failed.", ge.getMessage());
            return;
        }
    }
    try {
        eg = engineService.submit(new UpdateExplicitGroupCommand(dvRequestService.getDataverseRequest(), eg));
        JsfHelper.addSuccessMessage("Succesfully saved group " + eg.getDisplayName());
    } catch (CommandException ex) {
        JsfHelper.JH.addMessage(FacesMessage.SEVERITY_ERROR, "Group Save 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 : UpdateExplicitGroupCommand(edu.harvard.iq.dataverse.engine.command.impl.UpdateExplicitGroupCommand) GroupException(edu.harvard.iq.dataverse.authorization.groups.GroupException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) 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 4 with ExplicitGroup

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.

the class RoleAssigneeServiceBean method getUserRuntimeGroups.

private List<String> getUserRuntimeGroups(DataverseRequest dataverseRequest) {
    List<String> retVal = new ArrayList<>();
    // Set<Group> groups = groupSvc.groupsFor(dataverseRequest, null);
    Set<Group> groups = groupSvc.collectAncestors(groupSvc.groupsFor(dataverseRequest));
    for (Group group : groups) {
        logger.fine("found group " + group.getIdentifier() + " with alias " + group.getAlias());
        // if (group.getGroupProvider().getGroupProviderAlias().equals("shib") || group.getGroupProvider().getGroupProviderAlias().equals("ip")) {
        String groupAlias = group.getAlias();
        if (groupAlias != null && !groupAlias.isEmpty()) {
            if (group instanceof ExplicitGroup) {
                retVal.add("&explicit/" + groupAlias);
            } else {
                retVal.add('&' + groupAlias);
            }
        }
    // }
    }
    logger.fine("retVal: " + retVal);
    return retVal;
}
Also used : ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) Group(edu.harvard.iq.dataverse.authorization.groups.Group) ArrayList(java.util.ArrayList) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)

Example 5 with ExplicitGroup

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup in project dataverse by IQSS.

the class DeleteDataverseCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    // Make sure we don't delete root
    if (doomed.getOwner() == null) {
        throw new IllegalCommandException("Cannot delete the root dataverse", this);
    }
    // make sure the dataverse is emptyw
    if (ctxt.dvObjects().hasData(doomed)) {
        throw new IllegalCommandException("Cannot delete non-empty dataverses", this);
    }
    // ASSIGNMENTS
    for (RoleAssignment ra : ctxt.roles().directRoleAssignments(doomed)) {
        ctxt.em().remove(ra);
    }
    // ROLES
    for (DataverseRole ra : ctxt.roles().findByOwnerId(doomed.getId())) {
        ctxt.em().remove(ra);
    }
    // EXPLICIT GROUPS
    for (ExplicitGroup eg : ctxt.em().createNamedQuery("ExplicitGroup.findByOwnerId", ExplicitGroup.class).setParameter("ownerId", doomed.getId()).getResultList()) {
        ctxt.explicitGroups().removeGroup(eg);
    }
    // Input Level
    for (DataverseFieldTypeInputLevel inputLevel : doomed.getDataverseFieldTypeInputLevels()) {
        DataverseFieldTypeInputLevel merged = ctxt.em().merge(inputLevel);
        ctxt.em().remove(merged);
    }
    doomed.setDataverseFieldTypeInputLevels(new ArrayList<>());
    // DATAVERSE
    Dataverse doomedAndMerged = ctxt.em().merge(doomed);
    ctxt.em().remove(doomedAndMerged);
    // Remove from index
    ctxt.index().delete(doomed);
}
Also used : IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)

Aggregations

ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)11 ExplicitGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider)4 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)3 GroupException (edu.harvard.iq.dataverse.authorization.groups.GroupException)2 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 CreateExplicitGroupCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateExplicitGroupCommand)2 MockRoleAssigneeServiceBean (edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)1 DvObject (edu.harvard.iq.dataverse.DvObject)1 RoleAssigneeServiceBean (edu.harvard.iq.dataverse.RoleAssigneeServiceBean)1 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)1 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)1 Group (edu.harvard.iq.dataverse.authorization.groups.Group)1 BuiltInGroupsProvider (edu.harvard.iq.dataverse.authorization.groups.impl.builtin.BuiltInGroupsProvider)1 ExplicitGroupServiceBean (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean)1 IpGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider)1 IpGroupsServiceBean (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupsServiceBean)1