首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防机器配置在弹簧6不起作用。

防机器配置在弹簧6不起作用。
EN

Stack Overflow用户
提问于 2022-11-27 08:44:12
回答 2查看 65关注 0票数 -1

我开始在没有WebSecurityConfigurerAdapter的情况下在我的应用程序中编写web安全性,我在内部使用了使用spring 6的springboot3,在这个设置下,我从下面的代码中得到了一些错误,比如无法解析'ExpressionInterceptUrlRegistry‘中的'antMatchers’方法。

代码语言:javascript
复制
.authorizeRequests()
                    .antMatchers("/register").permitAll()
                    .anyRequest().authenticated()
                    .and()
                    .httpBasic()

完全方法

代码语言:javascript
复制
 @Bean
    protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .cors()
                .and()
                .csrf()
                .disable()

                .authorizeRequests()
                .antMatchers("/register").permitAll()
                .anyRequest().authenticated()
                .and()
                .httpBasic()

                .exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
                .and()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        return http.build();
    }
EN

回答 2

Stack Overflow用户

发布于 2022-11-29 17:38:05

在spring框架6中,.antMatchers不再可用。相反,根据春季安全文件,您应该执行以下操作:

代码语言:javascript
复制
@Bean
protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    http
            .cors()
            .and()
            .csrf()
            .disable()

            .authorizeHttpRequests( (auth) -> auth
                    .requestMatchers("/register").permitAll()
                    .anyRequest().authenticated()
            )
            .httpBasic().and()
            .exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
            .and()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

    return http.build();
}
票数 1
EN

Stack Overflow用户

发布于 2022-11-29 08:04:49

由于SpringBoot3.0.0(或SpringFramework6),.antMatchers for AuthorizationManagerRequestMatcherRegistry不再可用。

相反,使用.requestMatchers("/register")

示例:

代码语言:javascript
复制
http.authorizeHttpRequests( auth ->
    auth
        .requestMatchers(.....)
        .anyRequest().authenticated()
    )

参见关于“授权HttpServletRequests with AuthorizationFilter”的Spring安全文档

https://docs.spring.io/spring-security

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74588632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档