Set Context in READ-ONLY mode when retrieving community lists

This commit is contained in:
Tom Desair
2017-04-02 16:02:06 +02:00
parent eee4923518
commit dbfc8ce9a7
9 changed files with 34 additions and 14 deletions

View File

@@ -47,9 +47,6 @@ public class Context
{ {
private static final Logger log = Logger.getLogger(Context.class); private static final Logger log = Logger.getLogger(Context.class);
/** option flags */
public static final short READ_ONLY = 0x01;
/** Current user - null means anonymous access */ /** Current user - null means anonymous access */
private EPerson currentUser; private EPerson currentUser;
@@ -723,15 +720,15 @@ public class Context
} }
public Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson) { public Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson) {
if(mode == Mode.READ_ONLY) { if(isReadOnly()) {
return authorizedActionsCache.get(buildAuthorizedActionKey(dspaceObject, action, eperson)); return authorizedActionsCache.get(buildAuthorizedActionKey(dspaceObject, action, eperson));
} else { } else {
return false; return null;
} }
} }
public void cacheAuthorizedAction(DSpaceObject dspaceObject, int action, EPerson eperson, Boolean result) { public void cacheAuthorizedAction(DSpaceObject dspaceObject, int action, EPerson eperson, Boolean result) {
if(mode == Mode.READ_ONLY) { if(isReadOnly()) {
authorizedActionsCache.put(buildAuthorizedActionKey(dspaceObject, action, eperson), result); authorizedActionsCache.put(buildAuthorizedActionKey(dspaceObject, action, eperson), result);
} }
} }

View File

@@ -320,7 +320,7 @@ public class RDFConsumer implements Consumer
// create a new context, to be sure to work as anonymous user // create a new context, to be sure to work as anonymous user
// we don't want to store private data in a triplestore with public // we don't want to store private data in a triplestore with public
// SPARQL endpoint. // SPARQL endpoint.
ctx = new Context(Context.READ_ONLY); ctx = new Context(Context.Mode.READ_ONLY);
if (toDelete == null) if (toDelete == null)
{ {
log.debug("Deletion queue does not exists, creating empty queue."); log.debug("Deletion queue does not exists, creating empty queue.");

View File

@@ -84,7 +84,7 @@ public class RDFizer {
this.dryrun = false; this.dryrun = false;
this.lang = "TURTLE"; this.lang = "TURTLE";
this.processed = new CopyOnWriteArraySet<UUID>(); this.processed = new CopyOnWriteArraySet<UUID>();
this.context = new Context(Context.READ_ONLY); this.context = new Context(Context.Mode.READ_ONLY);
this.configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); this.configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
this.contentServiceFactory = ContentServiceFactory.getInstance(); this.contentServiceFactory = ContentServiceFactory.getInstance();
@@ -796,7 +796,7 @@ public class RDFizer {
// data into a triple store that provides a public sparql endpoint. // data into a triple store that provides a public sparql endpoint.
// all exported rdf data can be read by anonymous users. // all exported rdf data can be read by anonymous users.
// We won't change the database => read_only context will assure this. // We won't change the database => read_only context will assure this.
Context context = new Context(Context.READ_ONLY); Context context = new Context(Context.Mode.READ_ONLY);
RDFizer myself = null; RDFizer myself = null;
myself = new RDFizer(); myself = new RDFizer();

View File

@@ -307,7 +307,7 @@ public class ContextTest extends AbstractUnitTest
assertThat("testIsReadOnly 0", context.isReadOnly(), equalTo(false)); assertThat("testIsReadOnly 0", context.isReadOnly(), equalTo(false));
// Create a new read-only context // Create a new read-only context
Context instance = new Context(Context.READ_ONLY); Context instance = new Context(Context.Mode.READ_ONLY);
assertThat("testIsReadOnly 1", instance.isReadOnly(), equalTo(true)); assertThat("testIsReadOnly 1", instance.isReadOnly(), equalTo(true));
// Cleanup our context // Cleanup our context

View File

@@ -87,7 +87,7 @@ public class DataProviderServlet extends HttpServlet {
DSpaceObject dso = null; DSpaceObject dso = null;
try try
{ {
context = new Context(Context.READ_ONLY); context = new Context(Context.Mode.READ_ONLY);
dso = handleService.resolveToObject(context, handle); dso = handleService.resolveToObject(context, handle);
} }
catch (SQLException ex) catch (SQLException ex)

View File

@@ -69,7 +69,7 @@ public class LocalURIRedirectionServlet extends HttpServlet
DSpaceObject dso = null; DSpaceObject dso = null;
try try
{ {
context = new Context(Context.READ_ONLY); context = new Context(Context.Mode.READ_ONLY);
dso = handleService.resolveToObject(context, handle); dso = handleService.resolveToObject(context, handle);
} }
catch (SQLException ex) catch (SQLException ex)

View File

@@ -40,6 +40,7 @@ import org.dspace.content.Community;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CommunityService; import org.dspace.content.service.CommunityService;
import org.dspace.core.Context;
import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
@@ -146,7 +147,10 @@ public class CommunityBrowser extends AbstractDSpaceTransformer implements Cache
if (validity == null) if (validity == null)
{ {
try { try {
DSpaceValidity theValidity = new DSpaceValidity(); Context.Mode originalMode = context.getCurrentMode();
context.setMode(Context.Mode.READ_ONLY);
DSpaceValidity theValidity = new DSpaceValidity();
TreeNode treeRoot = buildTree(communityService.findAllTop(context)); TreeNode treeRoot = buildTree(communityService.findAllTop(context));
@@ -187,6 +191,8 @@ public class CommunityBrowser extends AbstractDSpaceTransformer implements Cache
} }
this.validity = theValidity.complete(); this.validity = theValidity.complete();
context.setMode(originalMode);
} }
catch (SQLException sqle) catch (SQLException sqle)
{ {
@@ -236,6 +242,9 @@ public class CommunityBrowser extends AbstractDSpaceTransformer implements Cache
division.setHead(T_head); division.setHead(T_head);
division.addPara(T_select); division.addPara(T_select);
Context.Mode originalMode = context.getCurrentMode();
context.setMode(Context.Mode.READ_ONLY);
TreeNode treeRoot = buildTree(communityService.findAllTop(context)); TreeNode treeRoot = buildTree(communityService.findAllTop(context));
boolean full = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("xmlui.community-list.render.full", true); boolean full = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("xmlui.community-list.render.full", true);
@@ -264,6 +273,8 @@ public class CommunityBrowser extends AbstractDSpaceTransformer implements Cache
} }
} }
context.setMode(originalMode);
} }
/** /**

View File

@@ -26,6 +26,7 @@ import org.dspace.content.service.ItemService;
import org.dspace.content.service.SupervisedItemService; import org.dspace.content.service.SupervisedItemService;
import org.dspace.content.service.WorkspaceItemService; import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@@ -125,6 +126,9 @@ public class Submissions extends AbstractDSpaceTransformer
public void addBody(Body body) throws SAXException, WingException, public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException UIException, SQLException, IOException, AuthorizeException
{ {
Context.Mode originalMode = context.getCurrentMode();
context.setMode(Context.Mode.READ_ONLY);
Request request = ObjectModelHelper.getRequest(objectModel); Request request = ObjectModelHelper.getRequest(objectModel);
boolean displayAll = false; boolean displayAll = false;
//This param decides whether we display all of the user's previous //This param decides whether we display all of the user's previous
@@ -141,6 +145,8 @@ public class Submissions extends AbstractDSpaceTransformer
this.addUnfinishedSubmissions(div); this.addUnfinishedSubmissions(div);
// this.addSubmissionsInWorkflowDiv(div); // this.addSubmissionsInWorkflowDiv(div);
this.addPreviousSubmissions(div, displayAll); this.addPreviousSubmissions(div, displayAll);
context.setMode(originalMode);
} }
/** /**

View File

@@ -27,6 +27,7 @@ import org.dspace.content.DSpaceObject;
import org.dspace.content.factory.ContentServiceFactory; import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService; import org.dspace.content.service.CollectionService;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.handle.HandleServiceImpl; import org.dspace.handle.HandleServiceImpl;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
@@ -78,7 +79,10 @@ public class SelectCollectionStep extends AbstractSubmissionStep
public void addBody(Body body) throws SAXException, WingException, public void addBody(Body body) throws SAXException, WingException,
UIException, SQLException, IOException, AuthorizeException UIException, SQLException, IOException, AuthorizeException
{ {
Context.Mode originalMode = context.getCurrentMode();
context.setMode(Context.Mode.READ_ONLY);
java.util.List<Collection> collections; // List of possible collections. java.util.List<Collection> collections; // List of possible collections.
String actionURL = contextPath + "/submit/" + knot.getId() + ".continue"; String actionURL = contextPath + "/submit/" + knot.getId() + ".continue";
DSpaceObject dso = handleService.resolveToObject(context, handle); DSpaceObject dso = handleService.resolveToObject(context, handle);
@@ -113,6 +117,8 @@ public class SelectCollectionStep extends AbstractSubmissionStep
Button submit = list.addItem().addButton("submit"); Button submit = list.addItem().addButton("submit");
submit.setValue(T_submit_next); submit.setValue(T_submit_next);
context.setMode(originalMode);
} }
/** /**