Commit 38deae28 authored by thorsten.vitt's avatar thorsten.vitt
Browse files

Skip forbidden ancestors building TEI header stack.

When preparing the TEI header of an exported corpus, the TEIHeaderStack
implementation asks TG-search for the root object's ancestor path(s) and
retrieves metadata for all of them. If we don't have read permission for
any of these objects, an AuthFaultException would have been thrown,
causing a 403. 

This fix causes these ancestors to be simply skipped (which will be
logged but not be noted in the corpus document itself).
parent 8662968f
......@@ -20,6 +20,8 @@
import java.io.InputStream;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
......@@ -43,6 +45,7 @@
import org.w3c.dom.Element;
import com.google.common.collect.Lists;
import com.ibm.icu.text.MessageFormat;
/**
* Generates headers for every possible TEIcorpus level.
......@@ -58,9 +61,11 @@ public class TEIHeaderStack {
private final List<ObjectType> parents = Lists.newLinkedList();
private final ITextGridRep repository = TextGridRepProvider.getInstance();
private Templates stylesheet;
private static final Logger logger = Logger.getLogger(TEIHeaderStack.class.getCanonicalName());
public TEIHeaderStack(final ObjectType object, SearchClient searchClient) throws ObjectNotFoundFault,
MetadataParseFault, IoFault, AuthFault {
MetadataParseFault, IoFault {
final String uri = object.getGeneric().getGenerated().getTextgridUri()
.getValue();
parents.add(object);
......@@ -69,8 +74,12 @@ public TEIHeaderStack(final ObjectType object, SearchClient searchClient) throws
for (final PathType path : pathGroup.getPath()) {
for (final EntryType entry : path.getEntry())
if (!entry.getTextgridUri().equals(uri)) {
final MetadataContainerType container = repository.getCRUDService().readMetadata(searchClient.getSid(), null, entry.getTextgridUri());
try {
MetadataContainerType container = repository.getCRUDService().readMetadata(searchClient.getSid(), null, entry.getTextgridUri());
parents.add(0, container.getObject());
} catch (AuthFault e) {
logger.log(Level.WARNING, MessageFormat.format("Could not access ancestor {0} while building header for {1}: {2}. Skipping.", entry.getTextgridUri(), uri, e.getFaultInfo().getCause()));
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment