Search in sources :

Example 1 with IpAddress

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();
}
Also used : IpAddress(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress) PendingWorkflowInvocation(edu.harvard.iq.dataverse.workflow.PendingWorkflowInvocation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 2 with IpAddress

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));
}
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)

Example 3 with IpAddress

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;
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) NullSafeJsonBuilder.jsonObjectBuilder(edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder.jsonObjectBuilder) Arrays(java.util.Arrays) DatasetDistributor(edu.harvard.iq.dataverse.DatasetDistributor) DataFileTag(edu.harvard.iq.dataverse.DataFileTag) Date(java.util.Date) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) User(edu.harvard.iq.dataverse.authorization.users.User) Permission(edu.harvard.iq.dataverse.authorization.Permission) Map(java.util.Map) DataverseFacet(edu.harvard.iq.dataverse.DataverseFacet) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) Collector(java.util.stream.Collector) DatasetField(edu.harvard.iq.dataverse.DatasetField) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) EnumSet(java.util.EnumSet) JsonObject(javax.json.JsonObject) DatasetFieldValue(edu.harvard.iq.dataverse.DatasetFieldValue) Collection(java.util.Collection) DatasetFieldWalker(edu.harvard.iq.dataverse.util.DatasetFieldWalker) Set(java.util.Set) DataFile(edu.harvard.iq.dataverse.DataFile) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) BinaryOperator(java.util.function.BinaryOperator) DataverseTheme(edu.harvard.iq.dataverse.DataverseTheme) DataverseContact(edu.harvard.iq.dataverse.DataverseContact) List(java.util.List) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) JsonObjectBuilder(javax.json.JsonObjectBuilder) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) StringUtil(edu.harvard.iq.dataverse.util.StringUtil) JsonArrayBuilder(javax.json.JsonArrayBuilder) Util(edu.harvard.iq.dataverse.api.Util) AuthenticationProviderRow(edu.harvard.iq.dataverse.authorization.providers.AuthenticationProviderRow) Deque(java.util.Deque) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TreeSet(java.util.TreeSet) IpAddress(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress) ArrayList(java.util.ArrayList) ControlledVocabularyValue(edu.harvard.iq.dataverse.ControlledVocabularyValue) DatasetFieldCompoundValue(edu.harvard.iq.dataverse.DatasetFieldCompoundValue) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) IpAddressRange(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddressRange) Workflow(edu.harvard.iq.dataverse.workflow.Workflow) BiConsumer(java.util.function.BiConsumer) Json(javax.json.Json) LinkedList(java.util.LinkedList) Dataverse(edu.harvard.iq.dataverse.Dataverse) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) BuiltinUser(edu.harvard.iq.dataverse.authorization.providers.builtin.BuiltinUser) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) Dataset(edu.harvard.iq.dataverse.Dataset) JsonArray(javax.json.JsonArray) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess) Collections(edu.emory.mathcs.backport.java.util.Collections) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Collectors.toList(java.util.stream.Collectors.toList) WorkflowStepData(edu.harvard.iq.dataverse.workflow.step.WorkflowStepData) ShibGroup(edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroup) RoleAssigneeDisplayInfo(edu.harvard.iq.dataverse.authorization.RoleAssigneeDisplayInfo) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Collectors.toList(java.util.stream.Collectors.toList) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) IpAddressRange(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddressRange)

Aggregations

IpAddress (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 IpGroup (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 Collections (edu.emory.mathcs.backport.java.util.Collections)1 ControlledVocabularyValue (edu.harvard.iq.dataverse.ControlledVocabularyValue)1 DataFile (edu.harvard.iq.dataverse.DataFile)1 DataFileTag (edu.harvard.iq.dataverse.DataFileTag)1 Dataset (edu.harvard.iq.dataverse.Dataset)1 DatasetDistributor (edu.harvard.iq.dataverse.DatasetDistributor)1 DatasetField (edu.harvard.iq.dataverse.DatasetField)1 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)1 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)1 DatasetFieldValue (edu.harvard.iq.dataverse.DatasetFieldValue)1 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)1 DataverseContact (edu.harvard.iq.dataverse.DataverseContact)1 DataverseFacet (edu.harvard.iq.dataverse.DataverseFacet)1 DataverseTheme (edu.harvard.iq.dataverse.DataverseTheme)1 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)1 MetadataBlock (edu.harvard.iq.dataverse.MetadataBlock)1