use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress in project dataverse by IQSS.
the class Workflows method resumeWorkflow.
@Path("{invocationId}")
@POST
public Response resumeWorkflow(@PathParam("invocationId") String invocationId, String body) {
PendingWorkflowInvocation pending = workflows.getPendingWorkflow(invocationId);
String remoteAddrStr = httpRequest.getRemoteAddr();
IpAddress remoteAddr = IpAddress.valueOf((remoteAddrStr != null) ? remoteAddrStr : "0.0.0.0");
if (!isAllowed(remoteAddr)) {
return unauthorized("Sorry, your IP address is not authorized to send resume requests. Please contact an admin.");
}
Logger.getLogger(Workflows.class.getName()).log(Level.INFO, "Resume request from: {0}", httpRequest.getRemoteAddr());
if (pending == null) {
return notFound("Cannot find workflow invocation with id " + invocationId);
}
workflows.resume(pending, body);
return Response.accepted("/api/datasets/" + pending.getDataset().getId()).build();
}
use of edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress 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.ip.IpAddress 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