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

验证

相关推荐
老华带你飞1 天前
社团管理|基于Java社团管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端
invicinble1 天前
spring相关系统性理解,企业级应用
java·spring·mybatis
jiayong231 天前
Spring IOC 与 AOP 核心原理深度解析
java·spring·log4j
老华带你飞1 天前
汽车销售|汽车报价|基于Java汽车销售系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端·汽车
TinpeaV1 天前
Elasticsearch8(ES)保姆级菜鸟入门教程
大数据·spring boot·elasticsearch·搜索引擎·全文检索·postman
小马爱打代码1 天前
Spring AI:文生视频 - wanx2.1-i2v-plus
java·人工智能·spring
uzong1 天前
别让认知天花板,变成你的职业终点——技术人如何走出信息茧房
后端
华仔啊1 天前
RebbitMQ 入门教程看这一篇就够了
java·后端·rabbitmq
象象翔1 天前
AI+若依(实战篇)
java·人工智能·spring boot·spring
无限进步_1 天前
C语言实现贪吃蛇游戏详解
c语言·开发语言·数据结构·c++·后端·算法·游戏