Skip to content

Commit

Permalink
Revert "Add check for problematic SPARQL Update statement"
Browse files Browse the repository at this point in the history
This reverts commit 74b6253.
  • Loading branch information
Andrew Woods committed Jun 19, 2015
1 parent 74b6253 commit 50a04b5
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 89 deletions.
Expand Up @@ -366,8 +366,6 @@ public Response updateSparql(@ContentLocation final InputStream requestBodyStrea
addCacheControlHeaders(servletResponse, resource(), session);

return noContent().build();
} catch (final IllegalArgumentException iae) {
throw new BadRequestException(iae.getMessage());
} catch ( final RuntimeException ex ) {
final Throwable cause = ex.getCause();
if (cause instanceof PathNotFoundException) {
Expand Down
Expand Up @@ -24,7 +24,6 @@
import static com.google.common.collect.Lists.newArrayList;
import static com.hp.hpl.jena.update.UpdateAction.execute;
import static com.hp.hpl.jena.update.UpdateFactory.create;
import static java.util.regex.Pattern.compile;
import static org.apache.commons.codec.digest.DigestUtils.shaHex;
import static org.fcrepo.kernel.impl.identifiers.NodeResourceConverter.nodeConverter;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isFrozenNode;
Expand All @@ -43,7 +42,6 @@
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;

import javax.jcr.AccessDeniedException;
import javax.jcr.ItemNotFoundException;
Expand Down Expand Up @@ -96,16 +94,6 @@ public class FedoraResourceImpl extends JcrTools implements FedoraJcrTypes, Fedo

protected Node node;

/*
* Helps split SPARQL Update statements, e.g., on <>, to enable individual processing
*/
private static final Pattern subject = compile(".+<[a-zA-Z]*>");

/*
* Helps ensure there's no terminating slash in the predicate
*/
private static final Pattern terminated = compile("/>");

/**
* Construct a {@link org.fcrepo.kernel.models.FedoraResource} from an existing JCR Node
* @param node an existing JCR node to treat as an fcrepo object
Expand Down Expand Up @@ -402,11 +390,6 @@ public void updateProperties(final IdentifierConverter<Resource, FedoraResource>
final String sparqlUpdateStatement, final RdfStream originalTriples)
throws MalformedRdfException, AccessDeniedException {

if (!clean(sparqlUpdateStatement)) {
throw new IllegalArgumentException("Invalid SPARQL UPDATE statement:"
+ sparqlUpdateStatement);
}

final Model model = originalTriples.asModel();

final JcrPropertyStatementListener listener =
Expand All @@ -422,41 +405,6 @@ public void updateProperties(final IdentifierConverter<Resource, FedoraResource>
listener.assertNoExceptions();
}

/**
* Helps ensure that there are no terminating slashes in the predicate.
* A terminating slash means ModeShape has trouble extracting the localName, e.g., for
* http://myurl.org/.
*
* @see <a href="https://jira.duraspace.org/browse/FCREPO-1409"> FCREPO-1409 </a> for details.
*
* @param updateStmt SPARQL Update statement specified by the user
* @return whether the statement is deemed to be not problematic for ModeShape
*/
private boolean clean(final String updateStmt) {
final int start = updateStmt.indexOf("INSERT");
final int end = updateStmt.lastIndexOf("WHERE");

if (start < 0 || end < 0) {
return true;
}

final String insertStmt = updateStmt.substring(start, end);
final String[] insert = subject.split(insertStmt);
int count = 0;
final String terminatorIndicator = terminated.pattern();

for (final String s: insert) {
if (s.contains(terminatorIndicator)) {
final String[] p = terminated.split(s);
count++;
LOGGER.info("Problematic token({}):{}{} in statement:{}",
count, p[0], terminated, updateStmt);
}
}

return count == 0;
}

@Override
public RdfStream getTriples(final IdentifierConverter<Resource, FedoraResource> idTranslator,
final Class<? extends RdfStream> context) {
Expand Down
Expand Up @@ -452,41 +452,6 @@ public void testUpdateDenied() throws RepositoryException {
+ " WHERE { }", new RdfStream());
}

@Test (expected = IllegalArgumentException.class)
public void testInvalidSparqlUpdateValidation() throws RepositoryException {
final String pid = UUID.randomUUID().toString();
final FedoraResource object =
containerService.findOrCreate(session, pid);
object.updateProperties(
subjects,
"INSERT { <> <http://myurl.org/title/> \"fancy title\" . \n" +
" <> <http://myurl.org/title/> \"fancy title 2\" . } WHERE { }",
new RdfStream());
}

@Test
public void testValidSparqlUpdateValidation1() throws RepositoryException {
final String pid = UUID.randomUUID().toString();
final FedoraResource object =
containerService.findOrCreate(session, pid);
object.updateProperties(
subjects,
"INSERT { <> <http://myurl.org/title> \"5\" . } WHERE { }",
new RdfStream());
}

@Test
public void testValidSparqlUpdateValidation2() throws RepositoryException {
final String pid = UUID.randomUUID().toString();
final FedoraResource object =
containerService.findOrCreate(session, pid);
object.updateProperties(
subjects,
"PREFIX dsc:<http://myurl.org/title> \n" +
"INSERT { <> dsc:p \"ccc\" } WHERE { }",
new RdfStream());
}

@Test
public void testUpdatingRdfType() throws RepositoryException {
final FedoraResource object =
Expand Down

0 comments on commit 50a04b5

Please sign in to comment.