-
Notifications
You must be signed in to change notification settings - Fork 168
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
fix: remove Lazy annotation from Flow security beans #18463
fix: remove Lazy annotation from Flow security beans #18463
Conversation
For parameters with Lazy annotation, Spring generates a not-serializable proxy. Since some security beans are used inside Flow listeners, they should be fully serializable (or defined transient, if possible). This change removes the unnecessary Lazy annotaions, moving the lazy evaluation to VaadinWebSecurity. Fixes #18458
@@ -119,7 +119,7 @@ NavigationAccessControlConfigurer navigationAccessControlConfigurerCustomizer() | |||
*/ | |||
@Bean | |||
public AnnotatedViewAccessChecker annotatedViewAccessChecker( | |||
@Lazy AccessAnnotationChecker accessAnnotationChecker) { | |||
AccessAnnotationChecker accessAnnotationChecker) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it also make sense to add proxyBeanMethods=false
to the @Configuration
so that all beans in that class aren't proxied? This would also ensure this isn't reintroduced by accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, proxyBeanMethods=false
prevents the configuration class to be proxied, not the exposed beans.
Anyway, it makes sense to set that flag, since we have no direct method calls in SpringSecurityAutoConfiguration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same assumption in the past :) until I've read the javadocs of the flag:
Specify whether @bean methods should get proxied in order to enforce bean lifecycle behavior, e.g. to return shared singleton bean instances even in case of direct @bean method calls in user code. This feature requires method interception, implemented through a runtime-generated CGLIB subclass which comes with limitations such as the configuration class and its methods not being allowed to declare final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read it as "configuration class is proxied so that bean methods will always return the same instance when called by other methods of the class". My understanding is that when, for example, you call annotatedViewAccessChecker()
from another method inside the SpringSecurityAutoConfiguration
class, it creates the instance at the first call, and subsequent invocation will return that one instead of a new instance how it would happen if the configuration class is not proxied.
So, SpringSecurityAutoConfiguration
methods are proxied, but not their return value.
But I may be wrong. I'll double-check it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thing to double check! I only remember an old issue where boot also switched all their configuration to false by default, also to increase performance: spring-projects/spring-boot#9068
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this is blocked: don't worry about it and do it later :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the flag anyway, since it completely makes sense to avoid proxying in this case.
Thanks for pointing out 👍
vaadin-spring/src/test/java/com/vaadin/flow/spring/SpringSecurityAutoConfigurationTest.java
Outdated
Show resolved
Hide resolved
private <T> void assertObjectIsSerializable(T instance) { | ||
Object deserialized = Assertions.assertDoesNotThrow(() -> { | ||
ByteArrayOutputStream bs = new ByteArrayOutputStream(); | ||
ObjectOutputStream out = new ObjectOutputStream(bs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intellij like this version better:
ObjectOutputStream out = new ObjectOutputStream(bs); | |
try (ObjectOutputStream out = new ObjectOutputStream(bs)) { | |
out.writeObject(instance); | |
} |
Maybe we could use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Marco!
Co-authored-by: Peter Czuczor <61667986+czp13@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes! 🙇 I believe most issues have been addressed, with only a minor code modification suggested. It's a very small change, so I am marking this as approved.
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
* fix: remove Lazy annotation from Flow security beans For parameters with Lazy annotation, Spring generates a not-serializable proxy. Since some security beans are used inside Flow listeners, they should be fully serializable (or defined transient, if possible). This change removes the unnecessary Lazy annotaions, moving the lazy evaluation to VaadinWebSecurity. Fixes #18458 * Apply suggestions from code review Co-authored-by: Peter Czuczor <61667986+czp13@users.noreply.github.com> * set proxyBeanMethods to false * use try-with-resource for serialization/deserialization --------- Co-authored-by: Peter Czuczor <61667986+czp13@users.noreply.github.com>
* fix: remove Lazy annotation from Flow security beans For parameters with Lazy annotation, Spring generates a not-serializable proxy. Since some security beans are used inside Flow listeners, they should be fully serializable (or defined transient, if possible). This change removes the unnecessary Lazy annotaions, moving the lazy evaluation to VaadinWebSecurity. Fixes #18458 * Apply suggestions from code review * set proxyBeanMethods to false * use try-with-resource for serialization/deserialization --------- Co-authored-by: Marco Collovati <marco@vaadin.com> Co-authored-by: Peter Czuczor <61667986+czp13@users.noreply.github.com>
Description
For parameters with Lazy annotation, Spring generates a not-serializable proxy. Since some security beans are used inside Flow listeners, they should be fully serializable (or defined transient, if possible).
This change removes the unnecessary Lazy annotaions, moving the lazy evaluation to VaadinWebSecurity.
Fixes #18458
Type of change
Checklist
Additional for
Feature
type of change