spring-data-rest

Customize endpoints with Spring Data REST

让人想犯罪 __ 提交于 2020-07-19 08:12:06
问题 I've a project with Spring Boot 1.5.7, Spring Data REST, Hibernate, Spring JPA, Swagger2. I've two beans like these: @Entity public class TicketBundle extends AbstractEntity { private static final long serialVersionUID = 404514926837058071L; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List<Note> notes = new ArrayList<>(); ..... } and @Entity public class Note extends AbstractEntity { private static final long serialVersionUID = -5062313842902549565L; @Lob private

Spring Data Rest repositories occasionally not exported

微笑、不失礼 提交于 2020-07-19 07:03:02
问题 I'm having a weird issue in my Spring Boot application ( 2.2.6.RELEASE ) using Spring Data Rest ( 3.2.6.RELEASE ). From time to time my repositories are not exposed via rest. This is happening with the exact same version (same jar) of my application using the exact same configuration. There are 4 @RepositoryRestResource 's and when it's working, the root resource exposes this: { "_links": { "entity-a": { "href": "http://localhost:8080/api/entity-a{?projection}", "templated": true }, "entity-b

Spring Data Rest repositories occasionally not exported

独自空忆成欢 提交于 2020-07-19 07:01:06
问题 I'm having a weird issue in my Spring Boot application ( 2.2.6.RELEASE ) using Spring Data Rest ( 3.2.6.RELEASE ). From time to time my repositories are not exposed via rest. This is happening with the exact same version (same jar) of my application using the exact same configuration. There are 4 @RepositoryRestResource 's and when it's working, the root resource exposes this: { "_links": { "entity-a": { "href": "http://localhost:8080/api/entity-a{?projection}", "templated": true }, "entity-b

Is it problematic that Spring Data REST exposes entities via REST resources without using DTOs?

若如初见. 提交于 2020-07-16 12:59:51
问题 In my limited experience, I've been told repeatedly that you should not pass around entities to the front end or via rest, but instead to use a DTO. Doesn't Spring Data Rest do exactly this? I've looked briefly into projections, but those seem to just limit the data that is being returned, and still expecting an entity as a parameter to a post method to save to the database. Am I missing something here, or am I (and my coworkers) incorrect in that you should never pass around and entity? 回答1:

@PreAuthorize on JpaRepository

拥有回忆 提交于 2020-06-10 05:41:07
问题 I am looking to implement role based security for my REST service. I am using spring-data-rest and have configured a JpaRepository as such: @Repository @RestResource(path = "changesets", rel = "changesets") public interface ChangesetRepository extends JpaRepository<Changeset, Long> { } I would like to attach a @PreAuthorize annotation to the inherited Page<T> findAll(Pageable pageable) method so that a GET requires a specific role. Is there a way to do that? Do I need to provide a custom

@PreAuthorize on JpaRepository

拜拜、爱过 提交于 2020-06-10 05:40:41
问题 I am looking to implement role based security for my REST service. I am using spring-data-rest and have configured a JpaRepository as such: @Repository @RestResource(path = "changesets", rel = "changesets") public interface ChangesetRepository extends JpaRepository<Changeset, Long> { } I would like to attach a @PreAuthorize annotation to the inherited Page<T> findAll(Pageable pageable) method so that a GET requires a specific role. Is there a way to do that? Do I need to provide a custom

Can only create association from one side in Spring Data Rest

僤鯓⒐⒋嵵緔 提交于 2020-06-01 06:49:13
问题 @Entity public class Product { //.. private String name; @OneToMany(mappedBy = "product", orphanRemoval = true) private Set<File> files; //.. } @Entity public class File { //.. @ManyToOne @JoinColumn(name = "product_id", nullable = true) Product product; //.. } I can only create the association from one side so POST /files/{id} { "product" : "http://localhost:8080/api/products/1" } works but POST /products/{id} { "files" : [ "http://localhost:8080/api/files/1" ] } doesn't work. The POST doesn

User Roles Spring Data Rest Spring security

夙愿已清 提交于 2020-05-29 12:29:34
问题 I have an error that I dont really understand. I didn't find any tutorial that explain why it doesn't work. I have this spring boot application using spring security. When I make this POST request : http://localhost:8181/roles body: { "name":"ROLE_USER" } it works fine. When I make this POST request : http://localhost:8181/users body: { "username":"user", "password":"pass", "roles":[ "http://localhost:8181/roles/1" ] } it works fine But when I make this GET request: http://localhost:8181

User Roles Spring Data Rest Spring security

限于喜欢 提交于 2020-05-29 12:26:33
问题 I have an error that I dont really understand. I didn't find any tutorial that explain why it doesn't work. I have this spring boot application using spring security. When I make this POST request : http://localhost:8181/roles body: { "name":"ROLE_USER" } it works fine. When I make this POST request : http://localhost:8181/users body: { "username":"user", "password":"pass", "roles":[ "http://localhost:8181/roles/1" ] } it works fine But when I make this GET request: http://localhost:8181