VCDI 2022-01-10 15:52 采纳率: 90.9%
浏览 62
已结题

spring security permit无效


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .cors().and()
                .csrf().disable()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                .authorizeRequests()
                    .antMatchers("/home/**")
                    .permitAll()
                    .and()
                .authorizeRequests()
                    .anyRequest()
                    .authenticated()
                    .and()
                .addFilterBefore(new JwtAuthenticationFilter(this.jwtProperties, authenticationManagerBean(), jwtTokenUtil), RequestCacheAwareFilter.class)
                .addFilterBefore(new ExceptionHandlerFilter(), JwtAuthenticationFilter.class)
                .authenticationProvider(jwtAuthenticationProvider())
                .authenticationProvider(loginAuthenticationProvider());
    }

使用了 permitAll 允许路径,但是/home/test请求仍然被拦截了

  • 写回答

3条回答 默认 最新

  • 羽浩chris 2022-01-10 16:28
    关注

    这个代码是按照循序执行的,你换成这样看看呢

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .cors().and()
            .csrf().disable()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
    
            .authorizeRequests()
            .anyRequest()
            .authenticated()
            .and()
            .authorizeRequests()
            .antMatchers("/home/**")
            .permitAll()
            .and()
            .addFilterBefore(new JwtAuthenticationFilter(this.jwtProperties, authenticationManagerBean(), jwtTokenUtil), RequestCacheAwareFilter.class)
            .addFilterBefore(new ExceptionHandlerFilter(), JwtAuthenticationFilter.class)
            .authenticationProvider(jwtAuthenticationProvider())
            .authenticationProvider(loginAuthenticationProvider());
    }
    

    将anyRequest【任何请求】authenticated【通过身份验证】放在前面,将匹配home/**放在后面

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 1月22日
  • 已采纳回答 1月14日
  • 创建了问题 1月10日

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据