Skip to content

Commit 218f605

Browse files
consider security level in browse index plugins
1 parent e56ef96 commit 218f605

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

dspace-api/src/main/java/org/dspace/discovery/SolrServiceMetadataBrowseIndexingPlugin.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,20 @@ public void additionalIndex(Context context, IndexableObject indexableObject, So
125125
Boolean.FALSE),
126126
true);
127127

128+
// the maximum security level (if not null) which ist still indexed
129+
Integer maxsecuritylevel = DSpaceServicesFactory
130+
.getInstance()
131+
.getConfigurationService()
132+
.getIntProperty("discovery.index.securitylevel.maxlevel", 0);
133+
134+
128135
for (int x = 0; x < values.size(); x++) {
129136
MetadataValue val = values.get(x);
137+
138+
if (val.getSecurityLevel() != null && val.getSecurityLevel() > maxsecuritylevel) {
139+
continue;
140+
}
141+
130142
boolean hasChoiceAuthority = choiceAuthorityService
131143
.isChoicesConfigured(metadataAuthorityService
132144
.makeFieldKey(val.getSchema(), val.getElement(), val.getQualifier())

dspace-api/src/test/java/org/dspace/discovery/DiscoveryIT.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
package org.dspace.discovery;
99

1010
import static org.dspace.discovery.SolrServiceWorkspaceWorkflowRestrictionPlugin.DISCOVER_WORKSPACE_CONFIGURATION_NAME;
11+
import static org.hamcrest.MatcherAssert.assertThat;
12+
import static org.hamcrest.Matchers.hasItem;
13+
import static org.hamcrest.Matchers.not;
14+
import static org.hamcrest.Matchers.startsWith;
1115
import static org.junit.Assert.assertEquals;
1216
import static org.junit.Assert.assertFalse;
1317
import static org.junit.Assert.assertTrue;
@@ -21,6 +25,10 @@
2125
import java.util.stream.Collectors;
2226
import javax.servlet.http.HttpServletRequest;
2327

28+
import org.apache.solr.client.solrj.SolrQuery;
29+
import org.apache.solr.client.solrj.SolrServerException;
30+
import org.apache.solr.client.solrj.response.QueryResponse;
31+
import org.apache.solr.common.SolrDocument;
2432
import org.dspace.AbstractIntegrationTestWithDatabase;
2533
import org.dspace.app.launcher.ScriptLauncher;
2634
import org.dspace.app.scripts.handler.impl.TestDSpaceRunnableHandler;
@@ -99,6 +107,9 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
99107
MetadataAuthorityService metadataAuthorityService = ContentAuthorityServiceFactory.getInstance()
100108
.getMetadataAuthorityService();
101109

110+
SolrSearchCore solrSearchCore = DSpaceServicesFactory.getInstance().getServiceManager()
111+
.getServicesByType(SolrSearchCore.class).get(0);
112+
102113
@Override
103114
@Before
104115
public void setUp() throws Exception {
@@ -799,6 +810,108 @@ public void searchWithDefaultSortServiceTest() throws SearchServiceException {
799810
}
800811
}
801812

813+
/**
814+
* Test designed to check if metadatavalues with securitylevel are indexed.
815+
* @throws SearchServiceException
816+
*/
817+
@Test
818+
public void searchWithMaxSecurityLevelSetTest() throws SearchServiceException {
819+
820+
configurationService.setProperty("discovery.index.securitylevel.maxlevel", 0);
821+
DiscoveryConfiguration defaultConf = SearchUtils.getDiscoveryConfiguration(context, "default", null);
822+
823+
// Populate the testing objects: create items in eperson's workspace and perform search in it
824+
int numberItems = 10;
825+
context.turnOffAuthorisationSystem();
826+
EPerson submitter = null;
827+
try {
828+
submitter = EPersonBuilder.createEPerson(context).withEmail("[email protected]")
829+
.withNameInMetadata("Peter", "Funny").build();
830+
} catch (SQLException e) {
831+
throw new RuntimeException(e);
832+
}
833+
context.setCurrentUser(submitter);
834+
Community community = CommunityBuilder.createCommunity(context).build();
835+
Collection collection = CollectionBuilder.createCollection(context, community).build();
836+
for (int i = 0; i < numberItems; i++) {
837+
ItemBuilder.createItem(context, collection)
838+
.withTitle("item " + i)
839+
.withSecuredMetadata("dc", "description", "abstract", "secured" + i + ".", 1)
840+
.withSecuredMetadata("dc", "description", "abstract", "secured" + i + ".", 2)
841+
.withSecuredMetadata("dc", "description", "abstract", "nonsecured" + i + ".", 0)
842+
.build();
843+
}
844+
context.restoreAuthSystemState();
845+
846+
// Build query with default parameters (except for workspaceConf)
847+
QueryResponse result = null;
848+
try {
849+
result = solrSearchCore.getSolr().query(new SolrQuery(String.format(
850+
"search.resourcetype:\"Item\"")));
851+
} catch (SolrServerException e) {
852+
throw new RuntimeException(e);
853+
} catch (IOException e) {
854+
throw new RuntimeException(e);
855+
}
856+
assertEquals(result.getResults().size(), numberItems);
857+
for (SolrDocument doc : result.getResults()) {
858+
assertThat(doc.getFieldNames(), hasItem("dc.description.abstract"));
859+
assertThat(doc.getFieldValues("dc.description.abstract"), not(hasItem(startsWith("secured"))));
860+
assertThat(doc.getFieldValues("dc.description.abstract"), hasItem(startsWith("nonsecured")));
861+
}
862+
}
863+
864+
/**
865+
* Test designed to check if metadatavalues with securitylevel greater than 0 are indexed.
866+
* @throws SearchServiceException
867+
*/
868+
@Test
869+
public void searchWithMaxSecurityLevelGreater1SetTest() throws SearchServiceException {
870+
871+
configurationService.setProperty("discovery.index.securitylevel.maxlevel", 1);
872+
DiscoveryConfiguration defaultConf = SearchUtils.getDiscoveryConfiguration(context, "default", null);
873+
874+
// Populate the testing objects: create items in eperson's workspace and perform search in it
875+
int numberItems = 10;
876+
context.turnOffAuthorisationSystem();
877+
EPerson submitter = null;
878+
try {
879+
submitter = EPersonBuilder.createEPerson(context).withEmail("[email protected]")
880+
.withNameInMetadata("Peter", "Funny").build();
881+
} catch (SQLException e) {
882+
throw new RuntimeException(e);
883+
}
884+
context.setCurrentUser(submitter);
885+
Community community = CommunityBuilder.createCommunity(context).build();
886+
Collection collection = CollectionBuilder.createCollection(context, community).build();
887+
for (int i = 0; i < numberItems; i++) {
888+
ItemBuilder.createItem(context, collection)
889+
.withTitle("item " + i)
890+
.withSecuredMetadata("dc", "description", "abstract", "nonsecured" + i + ".", 1)
891+
.withSecuredMetadata("dc", "description", "abstract", "secured" + i + ".", 2)
892+
.withSecuredMetadata("dc", "description", "abstract", "nonsecured" + i + ".", 0)
893+
.build();
894+
}
895+
context.restoreAuthSystemState();
896+
897+
// Build query with default parameters (except for workspaceConf)
898+
QueryResponse result = null;
899+
try {
900+
result = solrSearchCore.getSolr().query(new SolrQuery(String.format(
901+
"search.resourcetype:\"Item\"")));
902+
} catch (SolrServerException e) {
903+
throw new RuntimeException(e);
904+
} catch (IOException e) {
905+
throw new RuntimeException(e);
906+
}
907+
assertEquals(result.getResults().size(), numberItems);
908+
for (SolrDocument doc : result.getResults()) {
909+
assertThat(doc.getFieldNames(), hasItem("dc.description.abstract"));
910+
assertThat(doc.getFieldValues("dc.description.abstract"), not(hasItem(startsWith("secured"))));
911+
assertThat(doc.getFieldValues("dc.description.abstract"), hasItem(startsWith("nonsecured")));
912+
}
913+
}
914+
802915
private void assertSearchQuery(String resourceType, int size) throws SearchServiceException {
803916
assertSearchQuery(resourceType, size, size, 0, -1);
804917
}

0 commit comments

Comments
 (0)