Search in sources :

Example 1 with IpGroupProvider

use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.

the class JsonParserTest method testIpGroupRoundTrip.

@Test
public void testIpGroupRoundTrip() {
    IpGroup original = new IpGroup();
    original.setDescription("Ip group description");
    original.setDisplayName("Test-ip-group");
    original.setId(42l);
    original.setPersistedGroupAlias("test-ip-group");
    original.setGroupProvider(new IpGroupProvider(null));
    original.add(IpAddressRange.make(IpAddress.valueOf("1.2.1.1"), IpAddress.valueOf("1.2.1.10")));
    original.add(IpAddressRange.make(IpAddress.valueOf("1.1.1.1"), IpAddress.valueOf("1.1.1.1")));
    original.add(IpAddressRange.make(IpAddress.valueOf("1:2:3::4:5"), IpAddress.valueOf("1:2:3::4:5")));
    original.add(IpAddressRange.make(IpAddress.valueOf("1:2:3::3:ff"), IpAddress.valueOf("1:2:3::3:5")));
    JsonObject serialized = JsonPrinter.json(original).build();
    System.out.println(serialized.toString());
    IpGroup parsed = new JsonParser().parseIpGroup(serialized);
    assertEquals(original, parsed);
}
Also used : JsonObject(javax.json.JsonObject) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) Test(org.junit.Test)

Example 2 with IpGroupProvider

use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.

the class JsonParserTest method testIpGroupRoundTrip_singleIpv6Address.

@Test
public void testIpGroupRoundTrip_singleIpv6Address() {
    IpGroup original = new IpGroup();
    original.setDescription("Ip group description");
    original.setDisplayName("Test-ip-group");
    original.setId(42l);
    original.setPersistedGroupAlias("test-ip-group");
    original.setGroupProvider(new IpGroupProvider(null));
    original.add(IpAddressRange.make(IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61"), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61")));
    JsonObject serialized = JsonPrinter.json(original).build();
    System.out.println(serialized.toString());
    IpGroup parsed = new JsonParser().parseIpGroup(serialized);
    assertEquals(original, parsed);
    assertTrue(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce60"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce62"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe47:ce61"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0af:fe48:ce61"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe79::22c9:d0ff:fe48:ce61"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("2.1.1.1"))));
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) JsonObject(javax.json.JsonObject) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) Test(org.junit.Test)

Example 3 with IpGroupProvider

use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.

the class JsonParserTest method testIpGroupRoundTrip_singleIpv4Address.

@Test
public void testIpGroupRoundTrip_singleIpv4Address() {
    IpGroup original = new IpGroup();
    original.setDescription("Ip group description");
    original.setDisplayName("Test-ip-group");
    original.setId(42l);
    original.setPersistedGroupAlias("test-ip-group");
    original.setGroupProvider(new IpGroupProvider(null));
    original.add(IpAddressRange.make(IpAddress.valueOf("1.1.1.1"), IpAddress.valueOf("1.1.1.1")));
    JsonObject serialized = JsonPrinter.json(original).build();
    System.out.println(serialized.toString());
    IpGroup parsed = new JsonParser().parseIpGroup(serialized);
    assertEquals(original, parsed);
    assertTrue(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.1"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.2"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.2.1"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.0"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.1.1.250"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("1.2.1.1"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("2.1.1.1"))));
    assertFalse(parsed.contains(new DataverseRequest(GuestUser.get(), IpAddress.valueOf("fe80::22c9:d0ff:fe48:ce61"))));
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) JsonObject(javax.json.JsonObject) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) Test(org.junit.Test)

Example 4 with IpGroupProvider

use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider in project dataverse by IQSS.

the class ExplicitGroupTest method recursiveStructuralContainment.

@Test
public void recursiveStructuralContainment() throws GroupException {
    Dataverse dvParent = makeDataverse();
    ExplicitGroup parentGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
    ExplicitGroup childGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
    ExplicitGroup grandChildGroup = roleAssigneeSvc.add(makeExplicitGroup(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());
    assertTrue(grandChildGroup.structuralContains(au));
    assertTrue(childGroup.structuralContains(au));
    assertTrue(parentGroup.structuralContains(au));
    assertTrue(childGroup.structuralContains(GuestUser.get()));
    assertTrue(parentGroup.structuralContains(GuestUser.get()));
    grandChildGroup.remove(au);
    assertFalse(grandChildGroup.structuralContains(au));
    assertFalse(childGroup.structuralContains(au));
    assertFalse(parentGroup.structuralContains(au));
    childGroup.add(AuthenticatedUsers.get());
    assertFalse(grandChildGroup.structuralContains(au));
    assertFalse(childGroup.structuralContains(au));
    assertFalse(parentGroup.structuralContains(au));
    assertTrue(childGroup.structuralContains(AuthenticatedUsers.get()));
    final IpGroup ipGroup = new IpGroup(new IpGroupProvider(null));
    grandChildGroup.add(ipGroup);
    ipGroup.add(IpAddressRange.make(IpAddress.valueOf("0.0.1.1"), IpAddress.valueOf("0.0.255.255")));
    assertTrue(grandChildGroup.structuralContains(ipGroup));
    assertTrue(childGroup.structuralContains(ipGroup));
    assertTrue(parentGroup.structuralContains(ipGroup));
}
Also used : 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)

Example 5 with IpGroupProvider

use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider 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

IpGroup (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup)5 IpGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider)5 Test (org.junit.Test)5 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)3 JsonObject (javax.json.JsonObject)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 IpAddress (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress)1