Skip to content

Commit

Permalink
Prevent reference properties pointing at literals
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed May 15, 2014
1 parent ff5a3b7 commit 57490c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Expand Up @@ -22,6 +22,7 @@
import static org.slf4j.LoggerFactory.getLogger;

import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
Expand All @@ -48,6 +49,8 @@ public Response toResponse(final RepositoryException e) {

if ( e.getMessage().matches("Error converting \".+\" from String to a Name")) {
return status(BAD_REQUEST).entity(e.getMessage()).build();
} else if ( e instanceof ValueFormatException ) {
return status(BAD_REQUEST).entity(e.getMessage()).build();
}

return serverError().entity(
Expand Down
Expand Up @@ -19,6 +19,7 @@
import static javax.ws.rs.core.Response.serverError;
import static org.slf4j.LoggerFactory.getLogger;

import javax.jcr.RepositoryException;
import javax.jcr.lock.LockException;
import javax.jcr.security.AccessControlException;
import javax.ws.rs.WebApplicationException;
Expand Down Expand Up @@ -79,6 +80,11 @@ public Response toResponse(final Exception e) {
.toResponse((TransactionMissingException) e.getCause());
}

if ( e.getCause() instanceof RepositoryException) {
return new RepositoryExceptionMapper()
.toResponse((RepositoryException)e.getCause());
}

LOGGER.info("Exception intercepted by WildcardExceptionMapper: \n", e);
return serverError().entity(
showStackTrace ? getStackTraceAsString(e) : null).build();
Expand Down
Expand Up @@ -46,6 +46,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFormatException;
import javax.jcr.ValueFactory;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
Expand Down Expand Up @@ -408,6 +409,8 @@ public Value createValue(final ValueFactory valueFactory, final RDFNode data, fi
final Node nodeFromGraphSubject = session.getNode(graphSubjects.getPathFromSubject(data.asResource()));
return valueFactory.createValue(nodeFromGraphSubject,
type == WEAKREFERENCE);
} else if (!data.isURIResource() && (type == REFERENCE || type == WEAKREFERENCE)) {
throw new ValueFormatException("Reference properties can only refer to URIs, not literals");
} else if (data.isURIResource() || type == URI) {
// some random opaque URI
return valueFactory.createValue(data.toString(), PropertyType.URI);
Expand Down

0 comments on commit 57490c2

Please sign in to comment.