spring-data-rest

Spring Data REST How to add embedded resources inline

我与影子孤独终老i 提交于 2019-12-18 12:01:05
问题 I'm using Spring Data REST and Hateoas in combination with HAL browser. This works perfectly, but now I would like to make a JSON dump of a specific entity with (a set of) its associated objects. I used @Projection but then I got stuck again. FYI: The normal behaviour (with embedded and links etc) should remain besides the new endpoint (without embedded and links). To further illustrate my problem/question: class Person { String name; List<Company> companies; } class Company { String name;

Repository access control in Spring Data Rest based off user princpal

跟風遠走 提交于 2019-12-18 10:46:16
问题 I'm attempting to implement fine grain access control while still taking advantage of Spring data rest. I'm working on securing a CrudRepository so users can only modify or insert data that belongs to them. I'm making use of @PreAuthorize / @PostAuthorize and @PreFilter / @PostFilter to lock access down to the current principal. So far my repository looks like this. public interface MyRepository extends CrudRepository<MyObject, Integer> { @PreAuthorize("#entity.userId == principal.id")

How to prevent some HTTP methods from being exported from my MongoRepository?

感情迁移 提交于 2019-12-18 10:34:39
问题 I'm using spring-data-rest and I have a MongoRepository like this: @RepositoryRestResource interface MyEntityRepository extends MongoRepository<MyEntity, String> { } I would like to allow the GET methods but disable PUT, POST, PATCH and DELETE (read only web service). According to http://docs.spring.io/spring-data/rest/docs/2.2.2.RELEASE/reference/html/#repository-resources.collection-resource I should be able to do that like this: @RepositoryRestResource interface MyEntityRepository extends

Creating new entity plus association not working

99封情书 提交于 2019-12-18 09:24:11
问题 I am having two entities AppUser and UserGroup . They have a @ManyToMany relationship. I am currently trying to create and associate a new group for an existing user like this: POST http://localhost:8080/groups { "name": "Group 1", "users": ["http://localhost:8080/users/1"] } The problem is that only the group gets created - but no association with the listed users - and still the server responds with 201 Created ?! These are the two repositories: @RepositoryRestResource(collectionResourceRel

Spring Data Rest @EmbeddedId cannot be constructed from Post Request

做~自己de王妃 提交于 2019-12-18 08:55:01
问题 I have a JPA entity Person and an entity Team . Both are joined by an entity PersonToTeam . This joining entity holds a many-to-one relation to Person and one to Team . It has a multi-column key consisting of the ids of the Person and the Team , which is represented by an @EmbeddedId. To convert the embedded id back and forth to the request id I have a converter. All this follows the suggestion on Spring Data REST @Idclass not recognized The code looks like this: @Entity public class

Paginate sub-resources in Spring Data Rest 2.1

大兔子大兔子 提交于 2019-12-18 04:19:51
问题 I use Spring Data Rest 2.1.1 Release with the default configuration. Considering the following resource: GET /communities/MyCommunity { "creationDate": "2014-07-16T06:22:37.153+0000", "name": "GroupeSEB", "_links": { "self": { "href": "http://localhost:8080/api/communities/GroupeSEB" }, "posts": { "href": "http://localhost:8080/api/communities/GroupeSEB/posts" } } } When I get the "posts" sub-resource : GET /communities/MyCommunity/posts { "_embedded": { "posts": [ { "creationDate": "2014-07

Spring Data REST - PUT request does not work properly since v.2.5.7

给你一囗甜甜゛ 提交于 2019-12-18 03:58:13
问题 Since version 2.5.7 Spring Data REST does not properly perform a PUT request to update resource which has associated resources . Unlike PATCH request that works as expected! For example, Person has a many-to-one association with Addres . If we perform a PUT request with SDR v.2.5.6 (Spring Boot v.1.4.3) then all works OK. But if we switch to version 2.5.7 (i.e. to Spring Boot v.1.4.4) then we get an error: Can not construct instance of Address: no String-argument constructor/factory method to

Spring data rest - Is there a way to restrict the supported operations?

和自甴很熟 提交于 2019-12-18 03:57:16
问题 I want to expose data from a database as Restful APIs in a Spring(SpringBoot) application. Spring Data Rest appears to be an exact fit for purpose for this activity. This database is read-only for my application needs. The default provides all the HTTP methods. Is there a configuration that I can use to restrict (in fact prevent) the other methods from being exposed? 回答1: From the Spring docs on Hiding repository CRUD methods: 16.2.3. Hiding repository CRUD methods If you don’t want to expose

Spring Boot integration test ignoring secure=false in AutoConfigureMockMvc annotation, get 401

时光总嘲笑我的痴心妄想 提交于 2019-12-17 20:13:39
问题 Can't make my @SpringBootTest work. It says authentication is on, which I do not want. I've set it up with @AutoConfigureMockMvc(secure = false) I submit a mock request with some JSON and my integration test should test the whole stack, taking it through the web layer with SDR to JPA and then into the in-memory database, so I can test for it using JdbcTemplate . But the response is 401 , requires authentication. Why isn't the @AutoConfigureMockMvc(secure = false) enough? What's missing?

spring data rest with composite primary key

十年热恋 提交于 2019-12-17 19:49:46
问题 I use spring data rest for crud. But when the entity has composite primary keys, I dont know how to to get an entity by giving the primary key. River class: @Entity public class River { private RiverPK id; private Double length; private Timestamp date; private String comment; @Basic @Column(name = "length") public Double getLength() { return length; } public void setLength(Double length) { this.length = length; } @Basic @Column(name = "date") public Timestamp getDate() { return date; } public