spring-projects / spring-projects/spring-data-rest

access qualifiers to restrict PUT and POST on individual properties [DATAREST-153]

Open
#540 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Thomas Darimont opened DATAREST-153 and commented

Github Author: PantagruelsTeeth
Github Last-Updated: 2012-11-29T17:46:58Z
This issue was automatically imported from github

This is particularly important when using natural keys because changing a primary key is undefined behaviour in JPA (see issue https://github.com/SpringSource/spring-data-rest/pull/44). But, I think this would be useful for other fields. I will describe the general idea although of course there may be a better way.

Each property would have an access qualifier in the schema. The possible qualifiers are "read", "create" and "update". This would be controlled by annotation or the aliasField proposed in issue https://github.com/SpringSource/spring-data-rest/pull/44. Default is complete access, but we should enforce that @Id is "create"-only, even when it is exported. I also think that fields with private or missing setter should be read-only be default, but this is open to discussion.

An example output schema is:

{
"links" : [ {
"rel" : "self",
"href" : "http://server/rest/user/schema"
}, {
"rel" : "user",
"href" : "http://server/rest/user"
} ],
"content" : {
"type" : "object",
"properties" : {
"username" : {
"type" : "string"
"access" : ["read", "create"]
},
"firstname" : {
"type" : "string"
"access" : ["read", "create", "update"]
}
"lastname" : {
"type" : "string"
"access" : ["read", "create", "update"]
}
"reputation" : {
"type" : "integer"
"access" : ["read"]
}
....

We can GET all fields. We can never modify "reputation". Username can be set on create (PUT or POST) but never modified for an existing resource.

Since modifying the schema generated by JSON is probably the most complex part of this task, I think the priority would be to simply support the annotations and check them as appropriate when accessing fields with ReflectionUtils


Reference URL: https://api.github.com/repos/SpringSource/spring-data-rest/issues/52

1 votes, 2 watchers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.