spring-projects / spring-projects/spring-security
Improve Integration between Authorized Objects and Spring Data
@jzheaux is already working on this.
Since Sep 5, 2024.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
If an authorized object is sent to Spring Data, for example using CrudRepository#save, the call fails since it tries to look up model metadata by the class name, a CGLIB name in this case.
Moreover, if an authorized object is sent to CrudRepository#save (and the call succeeded), then the associated masks and other authorization handling would apply if its methods are called.
Consider the following sample controller method:
@PutMapping("/{id}")
public Message update(@PathVariable("id") Long id, @RequestBody String body) {
Message message = this.messageRepository.findById(id); // authorized, if using `@AuthorizeReturnObject`
// ...
// only authorized operations on the object
// ...
return this.messageRepository.save(message); // if still wrapped, then unwanted masking or other error handling could ensue when persisting
}
Because a proxied object could be used as a method parameter anywhere in the application, Security can't know on its own any circumstances where it should unwrap the object.
One way to address this could be for Spring Data to detect AuthorizationProxy-implementing domain objects and unwrap them. The following sample illustrates the issue in its updateMessage method.
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.
Assessment
This issue has not been assessed yet.