Auto-configure a SecurityContextHolderStrategy bean #22745
Draft
+24
−110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



This is the first step towards #21401 and completes the migration from
VaadinWebSecurity(now removed) to the recently introducedVaadinSecurityConfigurerin #21373.It avoids the need to manually import
VaadinAwareSecurityContextHolderStrategyConfigurationby removing the class and include the strategy bean definition inSpringSecurityAutoConfigurationwith an additionalSmartInitializingSingletonthat sets the provided strategy bean statically inSecurityContextHolder.Removing
VaadinAwareSecurityContextHolderStrategyConfigurationis a minor breaking change since applications that currently import that configuration manually withmust remove the explicit import. Runtime functionality is not affected since applications providing their own custom strategy bean will override the auto-configured bean and the custom strategy will be picked up by the
SmartInitializingSingletonto be set statically.Note: a deprecation cycle of
VaadinAwareSecurityContextHolderStrategyConfigurationis not feasible since it's not allowed to keep two configurations providing the same conditional bean. An option could to deprecate and make it no-op to avoid compiler errors when importing the configuration (but this might just create some confusion).