question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebSecurityConfigurerAdapter migration recipe often not applied

See original GitHub issue

There’s a hint from @BoykoAlex in this https://github.com/openrewrite/rewrite-spring/pull/202#issuecomment-1155782542

I have pushed the revised version of the Recipe to play it safe when non applicable methods are overridden and/or used within the same class declaration.

Tried it on a few projects, but it seems the play-it-safe is quite restrictive. Having any unrelated method in the same class is already enough for the migration to back off. Consider the following sample, where I’ve only added a single line method to the first assertChanged test in WebSecurityConfigurerAdapterTest.kt.

package com.example.websecuritydemo;

import static org.springframework.security.config.Customizer.withDefaults;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests((authz) -> authz
                .anyRequest().authenticated()
            )
            .httpBasic(withDefaults());
    }

    void unrelatedMethod() {} // <-- This is enough for the recipe to back off

}

That leaves a lot of projects which are not migrated, as it’s not uncommon to add additional methods/beans in the same configuration file. For instance a sample project here merely adds a bean and changes the JWT converter, as suggested in the official spring security documentation. Yet the restrictions in the recipe around applicable classes entirely skip this configuration class.

I’m not sure what the exact motivations were to play it safe, but it would seem to me we might want to loosen those restrictions just a bit to be workable for common cases.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pway99commented, Aug 30, 2022

Nothing to tag on thanks Tim!

1reaction
pway99commented, Aug 30, 2022

Thanks Tim! I do agree the recipe should back off if the result would result in a breaking change, and have updated the recipe per your suggestions. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatically migrate WebSecurityConfigurerAdapter
With OpenRewrite you can apply migration recipes to your projects, to manipulate your source code. We've covered migration to JUnit 5 & Spring ......
Read more >
Spring Security without the WebSecurityConfigurerAdapter
In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter , as we encourage users to move towards a component-based ...
Read more >
How to Fix WebSecurityConfigurerAdapter Deprecated
In this short article, I'd like to share how to get rid of the warning saying that “The type WebSecurityConfigurerAdapter is deprecated” in ......
Read more >
Upgrading the deprecated WebSecurityConfigurerAdapter in ...
I have managed to update the methods. This is the WebSecurityConfig class, and the methods are modified in the following way:
Read more >
Spring Security: Upgrading the Deprecated ... - Baeldung
In this tutorial, we'll learn how we can replace this deprecation in a Spring Boot application and run some MVC tests. 2. Spring...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found