use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup in project dataverse by IQSS.
the class Workflows method updateWhitelist.
private void updateWhitelist() {
IpGroup updatedList = new IpGroup();
String[] ips = settingsSvc.get(WorkflowsAdmin.IP_WHITELIST_KEY, "127.0.0.1;::1").split(";");
Arrays.stream(ips).forEach(str -> updatedList.add(IpAddressRange.makeSingle(IpAddress.valueOf(str))));
whitelist = updatedList;
lastWhitelistUpdate = System.currentTimeMillis();
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup 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));
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup 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));
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup in project dataverse by IQSS.
the class JsonParser method parseIpGroup.
public IpGroup parseIpGroup(JsonObject obj) {
IpGroup retVal = new IpGroup();
if (obj.containsKey("id")) {
retVal.setId(Long.valueOf(obj.getInt("id")));
}
retVal.setDisplayName(obj.getString("name", null));
retVal.setDescription(obj.getString("description", null));
retVal.setPersistedGroupAlias(obj.getString("alias", null));
if (obj.containsKey("ranges")) {
obj.getJsonArray("ranges").stream().filter(jv -> jv.getValueType() == JsonValue.ValueType.ARRAY).map(jv -> (JsonArray) jv).forEach(rr -> {
retVal.add(IpAddressRange.make(IpAddress.valueOf(rr.getString(0)), IpAddress.valueOf(rr.getString(1))));
});
}
if (obj.containsKey("addresses")) {
obj.getJsonArray("addresses").stream().map(jsVal -> IpAddress.valueOf(((JsonString) jsVal).getString())).map(addr -> IpAddressRange.make(addr, addr)).forEach(retVal::add);
}
return retVal;
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup in project dataverse by IQSS.
the class JsonPrinter method json.
public static JsonObjectBuilder json(IpGroup grp) {
// collect single addresses
List<String> singles = grp.getRanges().stream().filter(IpAddressRange::isSingleAddress).map(IpAddressRange::getBottom).map(IpAddress::toString).collect(toList());
// collect "real" ranges
List<List<String>> ranges = grp.getRanges().stream().filter(rng -> !rng.isSingleAddress()).map(rng -> Arrays.asList(rng.getBottom().toString(), rng.getTop().toString())).collect(toList());
JsonObjectBuilder bld = jsonObjectBuilder().add("alias", grp.getPersistedGroupAlias()).add("identifier", grp.getIdentifier()).add("id", grp.getId()).add("name", grp.getDisplayName()).add("description", grp.getDescription());
if (!singles.isEmpty()) {
bld.add("addresses", asJsonArray(singles));
}
if (!ranges.isEmpty()) {
JsonArrayBuilder rangesBld = Json.createArrayBuilder();
ranges.forEach(r -> rangesBld.add(Json.createArrayBuilder().add(r.get(0)).add(r.get(1))));
bld.add("ranges", rangesBld);
}
return bld;
}
Aggregations