Search in sources :

Example 6 with IpGroup

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();
}
Also used : IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup)

Example 7 with IpGroup

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));
}
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 8 with 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));
}
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 9 with IpGroup

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;
}
Also used : Date(java.util.Date) FieldDTO(edu.harvard.iq.dataverse.api.dto.FieldDTO) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) JsonValue(javax.json.JsonValue) Gson(com.google.gson.Gson) Map(java.util.Map) DatasetField(edu.harvard.iq.dataverse.DatasetField) ParseException(java.text.ParseException) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) JsonObject(javax.json.JsonObject) MetadataBlockServiceBean(edu.harvard.iq.dataverse.MetadataBlockServiceBean) DatasetFieldValue(edu.harvard.iq.dataverse.DatasetFieldValue) Timestamp(java.sql.Timestamp) Set(java.util.Set) DataFile(edu.harvard.iq.dataverse.DataFile) Logger(java.util.logging.Logger) ValueType(javax.json.JsonValue.ValueType) DataverseTheme(edu.harvard.iq.dataverse.DataverseTheme) DataverseContact(edu.harvard.iq.dataverse.DataverseContact) List(java.util.List) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataFileCategory(edu.harvard.iq.dataverse.DataFileCategory) OptionalFileParams(edu.harvard.iq.dataverse.datasetutility.OptionalFileParams) DatasetFieldConstant(edu.harvard.iq.dataverse.DatasetFieldConstant) Util(edu.harvard.iq.dataverse.api.Util) HashMap(java.util.HashMap) 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) HashSet(java.util.HashSet) IpAddressRange(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddressRange) Workflow(edu.harvard.iq.dataverse.workflow.Workflow) Json(javax.json.Json) LinkedList(java.util.LinkedList) Dataverse(edu.harvard.iq.dataverse.Dataverse) JsonReader(javax.json.JsonReader) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) HarvestingClient(edu.harvard.iq.dataverse.harvest.client.HarvestingClient) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) Dataset(edu.harvard.iq.dataverse.Dataset) JsonArray(javax.json.JsonArray) TermsOfUseAndAccess(edu.harvard.iq.dataverse.TermsOfUseAndAccess) DatasetFieldServiceBean(edu.harvard.iq.dataverse.DatasetFieldServiceBean) JsonString(javax.json.JsonString) License(edu.harvard.iq.dataverse.TermsOfUseAndAccess.License) WorkflowStepData(edu.harvard.iq.dataverse.workflow.step.WorkflowStepData) StringReader(java.io.StringReader) Collections(java.util.Collections) JsonArray(javax.json.JsonArray) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) JsonString(javax.json.JsonString)

Example 10 with IpGroup

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

IpGroup (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup)10 IpGroupProvider (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider)5 JsonObject (javax.json.JsonObject)5 Test (org.junit.Test)5 Dataverse (edu.harvard.iq.dataverse.Dataverse)4 IpAddress (edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress)3 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)3 ControlledVocabularyValue (edu.harvard.iq.dataverse.ControlledVocabularyValue)2 DataFile (edu.harvard.iq.dataverse.DataFile)2 Dataset (edu.harvard.iq.dataverse.Dataset)2 DatasetField (edu.harvard.iq.dataverse.DatasetField)2 DatasetFieldCompoundValue (edu.harvard.iq.dataverse.DatasetFieldCompoundValue)2 DatasetFieldType (edu.harvard.iq.dataverse.DatasetFieldType)2 DatasetFieldValue (edu.harvard.iq.dataverse.DatasetFieldValue)2 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)2 DataverseContact (edu.harvard.iq.dataverse.DataverseContact)2 DataverseTheme (edu.harvard.iq.dataverse.DataverseTheme)2 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)2 TermsOfUseAndAccess (edu.harvard.iq.dataverse.TermsOfUseAndAccess)2 Util (edu.harvard.iq.dataverse.api.Util)2