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

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 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败