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();
    }

验证

相关推荐
老华带你飞12 分钟前
宠物商城销售|基于Java+ vue宠物商城销售管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·宠物
计算机学姐19 分钟前
基于Python的在线考试系统【2026最新】
开发语言·vue.js·后端·python·mysql·django·flask
朝阳58129 分钟前
Rust 并行压缩如何改变我的工作流程
后端·rust
程序员爱钓鱼31 分钟前
Node.js 编程实战:深入掌握异步性能优化
后端·node.js·trae
SadSunset34 分钟前
(9)基于xml的自动装配
java·笔记·spring
疯狂的程序猴36 分钟前
从需求到上架,现代 iOS 开发流程的工程化方法论
后端
程序员爱钓鱼38 分钟前
Node.js 编程实战:创建 HTTP/HTTPS 服务器全解析
后端·node.js·trae
hunter1990101 小时前
Spring线程池ThreadPoolTaskExecutor配置与实践
java·后端·spring
梦子yumeko1 小时前
Spring Ai Alibaba-1.1.0.0-RC1-LlmRoutingAgent
人工智能·spring·r语言
用户8356290780511 小时前
C# 实现 XML 转 Excel:从解析到生成 XLSX 的详细步骤
后端·c#