Use constructor injection for DaoAuthenticationProvider

Proprietary

Spring Security 7.0 removed the no-arg DaoAuthenticationProvider() constructor and the setUserDetailsService(UserDetailsService) setter; UserDetailsService is now a required constructor argument. This recipe folds setUserDetailsService(x) into the constructor (new DaoAuthenticationProvider(x)) and removes the setter when the provider is created with the no-arg constructor in the same block, for both Java and Kotlin sources. Declarations that the argument needs are moved in front of the provider when nothing else lies in between. In a constructor of a DaoAuthenticationProvider subclass, a leading setUserDetailsService(x) becomes super(x) (Java only). setPasswordEncoder(...) and other configuration are preserved. When the setter cannot be safely folded, a TODO comment with migration guidance is added instead.

io.moderne.java.spring.security7.MigrateDaoAuthenticationProviderConstructor
mod run . --recipe=io.moderne.java.spring.security7.MigrateDaoAuthenticationProviderConstructor

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.