springboot 3.2.5集成spring security 只放行get请求,其他请求403

环境配置

  • jdk 17
xml 复制代码
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-security</artifactId>
     </dependency>

解决办法

java 复制代码
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.csrf(AbstractHttpConfigurer::disable);// 关闭 crsf保护

		// 设置需要进行权限认证的请求
        http.authorizeRequests((authorizeRequests) ->
                        authorizeRequests
                                .requestMatchers("/**").hasRole("USER")
                ).formLogin(withDefaults());
        return http.build();
    }

验证

相关推荐
巫山老妖2 小时前
从零开发一个掘金自动发布 Skill,并上架 Clawhub
后端
颜酱3 小时前
图的数据结构:从「多叉树」到存储与遍历
javascript·后端·算法
雨中飘荡的记忆3 小时前
零拷贝技术深度解析
后端
uzong4 小时前
十年老员工的项目管理实战心得:有道有术
后端
Victor3565 小时前
MongoDB(31)索引对查询性能有何影响?
后端
Victor3565 小时前
MongoDB(30)如何删除索引?
后端
lizhongxuan6 小时前
多 Agent 协同机制对比
后端
IT_陈寒6 小时前
SpringBoot项目启动慢?5个技巧让你的应用秒级响应!
前端·人工智能·后端
树上有只程序猿7 小时前
2026低代码选型指南,主流低代码开发平台排名出炉
前端·后端
高端章鱼哥7 小时前
为什么说用OpenClaw对打工人来说“不划算”
前端·后端