玖语巴黎 2022-05-06 20:14 采纳率: 75%
浏览 1877
已结题

SpringSecurity permitAll方式放行资源无效

问题遇到的现象和发生背景

在SpringSecurity使用jwt令牌实现认证登录时使用如下方式放行相关静态资源和接口无效,仍然进行了token认证

问题相关代码
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .antMatchers("/login","/doc.html","/swagger-resources/**",
                    "/v2/api-docs/**","/webjars/**","/capture","/test/**","/ws/**","/logOut",
                    "/admins/userFaces","/index.html","/css/**","/js/**","/fonts/**").permitAll()//放行相关请求和资源
            .anyRequest().authenticated()//除了上面的其他都需要认证
            .withObjectPostProcessor(getObjectPostProcessor())//动态权限配置
            .and()
            .addFilterBefore(getJwtAuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class)//添加登陆过滤器
            .exceptionHandling()//添加异常处理过滤器
            .authenticationEntryPoint(restAuthenticationEntryPoint)//未认证异常过滤器
            .accessDeniedHandler(restfulAccessDeniedHandler)//权限拒绝异常过滤器
            .and()
            .csrf().disable()//使用jwt,不需要使用csrf拦截器
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)//不需要使用session
            .and()
            .headers().cacheControl();//禁用缓存
    }
运行结果及报错内容

img

  • 写回答

3条回答 默认 最新

  • a1767028198 2022-05-06 20:33
    关注

    configure(HttpSecurity http)中配置放行,那还是会走spring security拦截链的, configure(WebSecurity web)中去配置放行,那才是真的放行

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

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月9日
  • 已采纳回答 5月9日
  • 创建了问题 5月6日

悬赏问题

  • ¥15 vue中我代理了iframe,iframe却走的是路由,没有显示该显示的网站,这个该如何处理
  • ¥15 操作系统相关算法中while();的含义
  • ¥15 CNVcaller安装后无法找到文件
  • ¥15 visual studio2022中文乱码无法解决
  • ¥15 关于华为5g模块mh5000-31接线问题
  • ¥15 keil L6007U报错
  • ¥15 webapi 发布到iis后无法访问
  • ¥15 初学者如何快速上手学习stm32?
  • ¥15 如何自动更换布娃娃图片上的衣服
  • ¥15 心理学eprime编程