Skip to content

Commit

Permalink
[DSC-1369] Improve security level check by add a new maxAllowedMetada…
Browse files Browse the repository at this point in the history
…taVisibility property
  • Loading branch information
atarix83 committed Nov 16, 2023
1 parent c5b1165 commit 5fd4e5f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public abstract class AbstractOrcidProfileSectionFactory implements OrcidProfile

protected final OrcidProfileSyncPreference preference;

protected Integer maxAllowedMetadataVisibility = 0;

@Autowired
protected ItemService itemService;

Expand Down Expand Up @@ -70,4 +72,17 @@ protected List<MetadataValue> getMetadataValues(Item item, String metadataField)
return itemService.getMetadataByMetadataString(item, metadataField);
}

protected boolean isAllowedMetadataByVisibility(MetadataValue metadataValue) {
return metadataValue.getSecurityLevel() == null
|| metadataValue.getSecurityLevel() <= getMaxAllowedMetadataVisibility();
}

public Integer getMaxAllowedMetadataVisibility() {
return maxAllowedMetadataVisibility;
}

public void setMaxAllowedMetadataVisibility(Integer maxAllowedMetadataVisibility) {
this.maxAllowedMetadataVisibility = maxAllowedMetadataVisibility;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class OrcidAffiliationFactory extends AbstractOrcidProfileSectionFactory

private String endDateField;

private boolean isAllowedMetadataVisibility = false;

public OrcidAffiliationFactory(OrcidProfileSectionType sectionType, OrcidProfileSyncPreference preference) {
super(sectionType, preference);
}
Expand Down Expand Up @@ -97,7 +95,7 @@ public List<String> getMetadataSignatures(Context context, Item item) {
List<MetadataValue> metadataValues = getMetadataValueByPlace(metadataGroups, currentGroupIndex);
//only "visible" metadatavalues within this group
metadataValues = metadataValues.stream()
.filter(metadataValue -> getAllowedMetadataVisibility(metadataValue))
.filter(metadataValue -> isAllowedMetadataByVisibility(metadataValue))
.collect(Collectors.toList());
if (!metadataValues.isEmpty()) {
signatures.add(metadataSignatureGenerator.generate(context, metadataValues));
Expand Down Expand Up @@ -160,13 +158,6 @@ private boolean isUnprocessableValue(MetadataValue value) {
return value == null || isBlank(value.getValue()) || value.getValue().equals(PLACEHOLDER_PARENT_METADATA_VALUE);
}

private boolean getAllowedMetadataVisibility(MetadataValue metadataValue) {
if (isAllowedMetadataVisibility()) {
return metadataValue.getSecurityLevel() == null || metadataValue.getSecurityLevel() == 0;
}
return true;
}

private Map<String, List<MetadataValue>> getMetadataGroups(Item item) {
Map<String, List<MetadataValue>> metadataGroups = new HashMap<>();
metadataGroups.put(organizationField, itemService.getMetadataByMetadataString(item, organizationField));
Expand Down Expand Up @@ -219,11 +210,4 @@ public void setEndDateField(String endDateField) {
this.endDateField = endDateField;
}

public boolean isAllowedMetadataVisibility() {
return isAllowedMetadataVisibility;
}

public void setAllowedMetadataVisibility(boolean allowedMetadataVisibility) {
isAllowedMetadataVisibility = allowedMetadataVisibility;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class OrcidSimpleValueObjectFactory extends AbstractOrcidProfileSectionFa

private List<String> metadataFields = new ArrayList<String>();

private boolean isAllowedMetadataVisibility = false;

public OrcidSimpleValueObjectFactory(OrcidProfileSectionType sectionType, OrcidProfileSyncPreference preference) {
super(sectionType, preference);
}
Expand Down Expand Up @@ -78,7 +76,7 @@ public Object create(Context context, List<MetadataValue> metadataValues) {
public List<String> getMetadataSignatures(Context context, Item item) {
return metadataFields.stream()
.flatMap(metadataField -> getMetadataValues(item, metadataField).stream())
.filter(metadataValue -> getAllowedMetadataVisibility(metadataValue))
.filter(metadataValue -> isAllowedMetadataByVisibility(metadataValue))
.map(metadataValue -> metadataSignatureGenerator.generate(context, List.of(metadataValue)))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -140,13 +138,6 @@ private Address createAddress(Country country) {
return address;
}

private boolean getAllowedMetadataVisibility(MetadataValue metadataValue) {
if (isAllowedMetadataVisibility()) {
return metadataValue.getSecurityLevel() == null || metadataValue.getSecurityLevel() == 0;
}
return true;
}

public void setMetadataFields(String metadataFields) {
this.metadataFields = metadataFields != null ? asList(metadataFields.split(",")) : emptyList();
}
Expand All @@ -156,11 +147,4 @@ public List<String> getMetadataFields() {
return metadataFields;
}

public boolean isAllowedMetadataVisibility() {
return isAllowedMetadataVisibility;
}

public void setAllowedMetadataVisibility(boolean allowedMetadataVisibility) {
isAllowedMetadataVisibility = allowedMetadataVisibility;
}
}
8 changes: 0 additions & 8 deletions dspace/config/spring/api/orcid-services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
<property name="roleField" value="${orcid.mapping.affiliation.role}" />
<property name="startDateField" value="${orcid.mapping.affiliation.start-date}" />
<property name="endDateField" value="${orcid.mapping.affiliation.end-date}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

<bean class="org.dspace.orcid.model.factory.impl.OrcidAffiliationFactory">
Expand All @@ -122,7 +121,6 @@
<property name="roleField" value="${orcid.mapping.qualification.role}" />
<property name="startDateField" value="${orcid.mapping.qualification.start-date}" />
<property name="endDateField" value="${orcid.mapping.qualification.end-date}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

<bean class="org.dspace.orcid.model.factory.impl.OrcidAffiliationFactory">
Expand All @@ -132,42 +130,36 @@
<property name="roleField" value="${orcid.mapping.education.role}" />
<property name="startDateField" value="${orcid.mapping.education.start-date}" />
<property name="endDateField" value="${orcid.mapping.education.end-date}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

<bean class="org.dspace.orcid.model.factory.impl.OrcidSimpleValueObjectFactory">
<constructor-arg name="sectionType" value="OTHER_NAMES" />
<constructor-arg name="preference" value="BIOGRAPHICAL" />
<property name="metadataFields" value="${orcid.mapping.other-names}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

<bean class="org.dspace.orcid.model.factory.impl.OrcidSimpleValueObjectFactory">
<constructor-arg name="sectionType" value="KEYWORDS" />
<constructor-arg name="preference" value="BIOGRAPHICAL" />
<property name="metadataFields" value="${orcid.mapping.keywords}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

<bean class="org.dspace.orcid.model.factory.impl.OrcidSimpleValueObjectFactory">
<constructor-arg name="sectionType" value="COUNTRY" />
<constructor-arg name="preference" value="BIOGRAPHICAL" />
<property name="metadataFields" value="${orcid.mapping.country}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

<bean class="org.dspace.orcid.model.factory.impl.OrcidPersonExternalIdentifierFactory">
<constructor-arg name="sectionType" value="EXTERNAL_IDS" />
<constructor-arg name="preference" value="IDENTIFIERS" />
<property name="externalIds" value="${orcid.mapping.person-external-ids}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

<bean class="org.dspace.orcid.model.factory.impl.OrcidSimpleValueObjectFactory">
<constructor-arg name="sectionType" value="RESEARCHER_URLS" />
<constructor-arg name="preference" value="IDENTIFIERS" />
<property name="metadataFields" value="${orcid.mapping.researcher-urls}" />
<!-- <property name="allowedMetadataVisibility" value="true" /> -->
</bean>

</list>
Expand Down

0 comments on commit 5fd4e5f

Please sign in to comment.