-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Integration between Authorized Objects and Spring Data #15746
Comments
Calling a Spring Data repository with an authorized return object requires unwrapping. Spring Data repositories are proxies already hence the advisor would be a good place to unwrap the target object. You can identify Spring Data repositories as these implement |
@mp911de I think this is a good point. Truly, it's better for Spring Security to unproxy its own proxies. I'm not certain yet how generally applicable such a heuristic would be (outside of repositories), but I reason it's likely every proxied method parameter in a A more general-purposes way we could do it is add a companion annotation like @Repository
public class MessageRepository ... {
@AuthorizeReturnObject
Optional<Message> findById(Long id);
void save(@PermitParameter Message message);
} Ostensibly, it could be added at the method or class level to reduce duplication. Down the road, an application could more generally apply this to repositories though its proposed mixin support. |
If anyone interested, here is my solution to unwrap a proxy under Spring 6.3:
|
@jzheaux I ran into another problem. When I try to fetch an pageable search results of authorized entities I get:
|
Thanks, @noshua, can you please open a separate ticket with a reproducer, and we can link that ticket to this one? |
@jzheaux dunno if you have already thought about that so I wanted to mention. If you have 2 entities
So a solution like you supposed would also need to unwrap relations recursively even if |
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:
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 itsupdateMessage
method.The text was updated successfully, but these errors were encountered: