Search in sources :

Example 1 with ExplicitGroupProvider

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

use of edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider 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)

Example 3 with ExplicitGroupProvider

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

the class GroupServiceBeanTest method testCollectAncestors.

@Test
public void testCollectAncestors() throws GroupException {
    // Setup
    MockRoleAssigneeServiceBean roleAssigneeSvc = new MockRoleAssigneeServiceBean();
    MockExplicitGroupService explicitGroupSvc = new MockExplicitGroupService();
    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());
        g.updateAlias();
        roleAssigneeSvc.add(g);
        explicitGroupSvc.registerGroup(g);
    });
    // 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;
    sut.explicitGroupService = explicitGroupSvc;
    assertEquals(setOf(gA), sut.collectAncestors(setOf(gA)));
    assertEquals(setOf(gA, gAb), sut.collectAncestors(setOf(gAb)));
    assertEquals(setOf(gA, gAa, AuthenticatedUsers.get()), sut.collectAncestors(setOf(AuthenticatedUsers.get())));
    assertEquals(setOf(gA, gAb, gAa, gAstar), sut.collectAncestors(setOf(gAstar)));
}
Also used : ExplicitGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider) MockRoleAssigneeServiceBean(edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean) MockExplicitGroupService(edu.harvard.iq.dataverse.mocks.MockExplicitGroupService) Dataverse(edu.harvard.iq.dataverse.Dataverse) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) Test(org.junit.Test)

Aggregations

ExplicitGroup (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup)3 ExplicitGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 MockRoleAssigneeServiceBean (edu.harvard.iq.dataverse.mocks.MockRoleAssigneeServiceBean)2 Test (org.junit.Test)2 CreateExplicitGroupCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateExplicitGroupCommand)1 MockExplicitGroupService (edu.harvard.iq.dataverse.mocks.MockExplicitGroupService)1 HashSet (java.util.HashSet)1 JsonString (javax.json.JsonString)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1