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;
}
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));
});
}
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();
}
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;
}
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);
}
Aggregations