Search in sources :

Example 6 with ExplicitGroup

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

the class CreateExplicitGroupCommand method execute.

@Override
public ExplicitGroup execute(CommandContext ctxt) throws CommandException {
    // make sure alias in owner is unique
    eg.setOwner(dv);
    eg.updateAlias();
    ExplicitGroup existing = eg.getGroupProvider().get(eg.getAlias());
    if (existing != null) {
        throw new GroupAliasExistsException(eg.getGroupAliasInOwner());
    }
    // persist
    return ctxt.explicitGroups().persist(eg);
}
Also used : ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)

Example 7 with ExplicitGroup

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

the class DeleteExplicitGroupCommand method executeImpl.

@Override
protected void executeImpl(CommandContext ctxt) throws CommandException {
    ExplicitGroup merged = ctxt.em().merge(explicitGroup);
    // Remove this group from all explicit groups it belongs to.
    ctxt.em().createNativeQuery("DELETE FROM explicitgroup_explicitgroup " + "WHERE containedexplicitgroups_id=" + merged.getId()).executeUpdate();
    ctxt.explicitGroups().removeGroup(merged);
}
Also used : ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)

Example 8 with ExplicitGroup

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup 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 9 with ExplicitGroup

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

the class MocksFactory method makeExplicitGroup.

public static ExplicitGroup makeExplicitGroup(String name, ExplicitGroupProvider prv) {
    long id = nextId();
    ExplicitGroup eg = new ExplicitGroup(prv);
    eg.setId(id);
    eg.setDisplayName(name == null ? "explicitGroup-" + id : name);
    eg.setGroupAliasInOwner("eg" + id);
    return eg;
}
Also used : ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)

Example 10 with ExplicitGroup

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

the class GroupServiceBeanTest method testFlattenGroupsCollection.

@Test
public void testFlattenGroupsCollection() throws GroupException {
    // Setup
    MockRoleAssigneeServiceBean roleAssigneeSvc = new MockRoleAssigneeServiceBean();
    ExplicitGroupProvider prv = new ExplicitGroupProvider(null, roleAssigneeSvc);
    ExplicitGroup gA = new ExplicitGroup(prv);
    gA.setDisplayName("A");
    ExplicitGroup gAa = new ExplicitGroup(prv);
    gAa.setDisplayName("Aa");
    ExplicitGroup gAb = new ExplicitGroup(prv);
    gAb.setDisplayName("Ab");
    ExplicitGroup gAstar = new ExplicitGroup(prv);
    gAstar.setDisplayName("A*");
    Dataverse dv = MocksFactory.makeDataverse();
    Stream.of(gA, gAa, gAb, gAstar).forEach(g -> {
        g.setId(MocksFactory.nextId());
        g.setOwner(dv);
        g.setGroupAliasInOwner(g.getDisplayName());
        roleAssigneeSvc.add(g);
        g.updateAlias();
    });
    // create some containment hierarchy.
    gA.add(gAa);
    gA.add(gAb);
    gAb.add(gAstar);
    gAa.add(gAstar);
    gAa.add(AuthenticatedUsers.get());
    // Test
    GroupServiceBean sut = new GroupServiceBean();
    sut.roleAssigneeSvc = roleAssigneeSvc;
    Set<Group> grps = setOf(AllUsers.get(), gA);
    List<Group> result = sut.flattenGroupsCollection(grps).collect(toList());
    assertEquals("Groups should appear only once", result.size(), new HashSet<>(result).size());
    grps.addAll(listOf(gAa, gAb, gAstar, AuthenticatedUsers.get()));
    assertEquals("All groups should appear", grps, new HashSet<>(result));
}
Also used : ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) ExplicitGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider) MockRoleAssigneeServiceBean(edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean) Dataverse(edu.harvard.iq.dataverse.Dataverse) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) HashSet(java.util.HashSet) Test(org.junit.Test)

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