替换spring boot中的websecurityconfigureradapter for ResourceserverConfigurerAdapter

发布于 2025-02-11 08:45:14 字数 1317 浏览 0 评论 0原文

由于Spring Boot 2.7.x版本WebsEcurityConfigurerAdapter class class class necrecectect and a 指南来自Spring.io如何替换这些类并使用基于组件的安全配置。

我的问题是如何处理以下用例:

@Configuration
@EnableResourceServer
public class BearerAuthWebSecurityConfiguration extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .antMatcher("/api/**")
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated();
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources.resourceId(null);
        resources.authenticationManager(new OAuth2AuthenticationManager());
    }
    
}

我找不到有关如何处理@enableReSourceserverResourceerverConfigurerAdapter使用新的基于组件的安全配置的指南。在引擎盖下,这些类还使用websecurityConfigurerAdapter,应移至基于组件的安全配置。

Since Spring Boot 2.7.x version WebSecurityConfigurerAdapter class is deprecated and there is a guide from spring.io on how to replace those classes and use component-based security configuration.

My question is how to handle the following use-case:

@Configuration
@EnableResourceServer
public class BearerAuthWebSecurityConfiguration extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .antMatcher("/api/**")
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated();
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources.resourceId(null);
        resources.authenticationManager(new OAuth2AuthenticationManager());
    }
    
}

I did not find any guide on how to handle @EnableResourceServer and ResourceServerConfigurerAdapter using the new component-based security configuration. And under the hood these classes also use WebSecurityConfigurerAdapter and should be moved to the component-based security configuration.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄖ落Θ余辉 2025-02-18 08:45:14

The ResourceServerSecurityConfigurer is from the

The ResourceServerSecurityConfigurer is from the EOL'd spring-security-oauth project, therefore there is no support for new features/deprecations. I recommend you to use Spring Security's support for OAuth 2.0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文