From 4d8f009679fc517bc716291b279a28fab967ac95 Mon Sep 17 00:00:00 2001 From: Jon Brisbin Date: Wed, 6 Mar 2013 08:42:20 -0600 Subject: [PATCH] Fix for DATAREST-72. `ResourceMapping.isExported()` is now considered for displaying the link to the repository or when building the metadata for the request. Now sends back a 404 when a repository is not exported and an attempt to access it is made. --- .../data/rest/example/mongodb/ProfileRepository.java | 2 ++ .../data/rest/webmvc/RepositoryController.java | 7 ++++++- .../data/rest/webmvc/RepositoryRestRequest.java | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-data-rest-example/src/main/java/org/springframework/data/rest/example/mongodb/ProfileRepository.java b/spring-data-rest-example/src/main/java/org/springframework/data/rest/example/mongodb/ProfileRepository.java index a0fc07a61..7b22a230f 100644 --- a/spring-data-rest-example/src/main/java/org/springframework/data/rest/example/mongodb/ProfileRepository.java +++ b/spring-data-rest-example/src/main/java/org/springframework/data/rest/example/mongodb/ProfileRepository.java @@ -1,9 +1,11 @@ package org.springframework.data.rest.example.mongodb; import org.springframework.data.repository.CrudRepository; +import org.springframework.data.rest.repository.annotation.RestResource; /** * @author Jon Brisbin */ +@RestResource(exported = false) public interface ProfileRepository extends CrudRepository { } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java index 2b9f7b9d9..877226c27 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryController.java @@ -1,12 +1,14 @@ package org.springframework.data.rest.webmvc; import static java.util.Collections.*; +import static org.springframework.data.rest.repository.support.ResourceMappingUtils.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.convert.ConversionService; import org.springframework.data.repository.support.DomainClassConverter; import org.springframework.data.repository.support.Repositories; import org.springframework.data.rest.config.RepositoryRestConfiguration; +import org.springframework.data.rest.config.ResourceMapping; import org.springframework.hateoas.EntityLinks; import org.springframework.hateoas.Resource; import org.springframework.stereotype.Controller; @@ -46,7 +48,10 @@ public class RepositoryController extends AbstractRepositoryRestController { throws ResourceNotFoundException { Resource links = new Resource(emptyList()); for(Class domainType : repositories) { - links.add(entityLinks.linkToCollectionResource(domainType)); + ResourceMapping repoMapping = getResourceMapping(config, repositories.getRepositoryInformationFor(domainType)); + if(repoMapping.isExported()) { + links.add(entityLinks.linkToCollectionResource(domainType)); + } } return links; } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestRequest.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestRequest.java index 10bb300fa..fb5430790 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestRequest.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestRequest.java @@ -48,7 +48,7 @@ class RepositoryRestRequest { this.baseUri = baseUri; this.repoInfo = repoInfo; this.repoMapping = getResourceMapping(config, repoInfo); - if(null == repoMapping) { + if(null == repoMapping || !repoMapping.isExported()) { this.repoLink = null; this.repository = null; this.repoMethodInvoker = null;