spring-projects / spring-projects/spring-data-rest
access qualifiers to restrict PUT and POST on individual properties
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the proposed annotations and the field-access checks performed through ReflectionUtils. Define how read, create, and update qualifiers should apply to PUT and POST, including the stated @Id and setter cases. Done means annotated property access is enforced; schema JSON support is identified as a separate, more complex part of the work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100