Search in sources :

Example 56 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class CreateRoleCommandTest method testGuestUsersCantAddRoles.

@Test(expected = IllegalCommandException.class)
public void testGuestUsersCantAddRoles() throws CommandException {
    DataverseRole dvr = new DataverseRole();
    dvr.setAlias("roleTest");
    dvr.setName("Tester Role");
    dvr.addPermission(Permission.AddDataset);
    Dataverse dv = MocksFactory.makeDataverse();
    dvr.setOwner(dv);
    CreateRoleCommand sut = new CreateRoleCommand(dvr, new DataverseRequest(GuestUser.get(), IpAddress.valueOf("89.17.33.33")), dv);
    engine.submit(sut);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Test(org.junit.Test)

Example 57 with DataverseRequest

use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.

the class ExplicitGroupTest method recursiveLogicalContainment.

@Test
public void recursiveLogicalContainment() throws GroupException {
    Dataverse dvParent = makeDataverse();
    ExplicitGroup parentGroup = roleAssigneeSvc.add(makeExplicitGroup("parent", prv));
    ExplicitGroup childGroup = roleAssigneeSvc.add(makeExplicitGroup("child", prv));
    ExplicitGroup grandChildGroup = roleAssigneeSvc.add(makeExplicitGroup("grandChild", prv));
    parentGroup.setOwner(dvParent);
    childGroup.setOwner(dvParent);
    grandChildGroup.setOwner(dvParent);
    childGroup.add(grandChildGroup);
    parentGroup.add(childGroup);
    AuthenticatedUser au = roleAssigneeSvc.add(makeAuthenticatedUser("Jane", "Doe"));
    grandChildGroup.add(au);
    childGroup.add(GuestUser.get());
    DataverseRequest auReq = makeRequest(au);
    DataverseRequest guestReq = makeRequest();
    assertTrue(grandChildGroup.contains(auReq));
    assertTrue(childGroup.contains(auReq));
    assertTrue(parentGroup.contains(auReq));
    assertTrue(childGroup.contains(guestReq));
    assertTrue(parentGroup.contains(guestReq));
    grandChildGroup.remove(au);
    assertFalse(grandChildGroup.contains(auReq));
    assertFalse(childGroup.contains(auReq));
    assertFalse(parentGroup.contains(auReq));
    childGroup.add(AuthenticatedUsers.get());
    assertFalse(grandChildGroup.contains(auReq));
    assertTrue(childGroup.contains(auReq));
    assertTrue(parentGroup.contains(auReq));
    final IpGroup ipGroup = roleAssigneeSvc.add(new IpGroup(new IpGroupProvider(null)));
    grandChildGroup.add(ipGroup);
    ipGroup.add(IpAddressRange.make(IpAddress.valueOf("0.0.1.1"), IpAddress.valueOf("0.0.255.255")));
    final IpAddress ip = IpAddress.valueOf("0.0.128.128");
    final DataverseRequest request = new DataverseRequest(GuestUser.get(), ip);
    assertTrue(ipGroup.contains(request));
    assertTrue(grandChildGroup.contains(request));
    assertTrue(parentGroup.contains(request));
    childGroup.add(GuestUser.get());
    assertTrue(childGroup.contains(guestReq));
    assertTrue(parentGroup.contains(guestReq));
    assertFalse(grandChildGroup.contains(guestReq));
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) IpAddress(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) Dataverse(edu.harvard.iq.dataverse.Dataverse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Test(org.junit.Test)

Aggregations

DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)57 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)22 Dataverse (edu.harvard.iq.dataverse.Dataverse)21 Test (org.junit.Test)18 Dataset (edu.harvard.iq.dataverse.Dataset)15 Path (javax.ws.rs.Path)14 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)13 SwordError (org.swordapp.server.SwordError)10 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)6 IOException (java.io.IOException)6 POST (javax.ws.rs.POST)6 DataFile (edu.harvard.iq.dataverse.DataFile)5 User (edu.harvard.iq.dataverse.authorization.users.User)5 HarvestingClient (edu.harvard.iq.dataverse.harvest.client.HarvestingClient)5 JsonObject (javax.json.JsonObject)5 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 DepositReceipt (org.swordapp.server.DepositReceipt)5 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)4