Spring Boot中怎么放行Spring Security拦截的静态资源?

新手上路,请多包涵

如下图所示,建立了父子工程,demo是web项目,core是项目中核心的模块,存放jar包和共用的代码,app是应用的jar包,browser是浏览器的jar包,依赖关系是:app依赖core,browser依赖core,demo依赖browser,browser里面有登录页面,还有static等静态资源,现在browser里面的静态资源被拦截,不能放行。

clipboard.png

clipboard.png

clipboard.png
启动类在demo这个子工程里面,不懂怎么引入静态资源?

阅读 10.8k
2 个回答
新手上路,请多包涵

添加了这个设置

clipboard.png

   @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf() //跨站
                .disable() //关闭跨站检测
                .authorizeRequests() //验证策略
                .antMatchers(WHITE_LIST).permitAll()
                .anyRequest().authenticated()    //默认其它的请求都需要认证
                .and()
                .formLogin()
                .loginPage(SecurityConstants.LOGIN_PAGE)
                .failureUrl(SecurityConstants.FAILURE_URL)
                .permitAll()
                .defaultSuccessUrl(SecurityConstants.DEFAULT_SUCCESS_URL, true)
                .permitAll()
                .and()
                .exceptionHandling()
                .accessDeniedPage(SecurityConstants.ACCESS_DENIED_PAGE);
        /*
         * 本次 json web token 权限控制的核心配置部分
         * 在 Spring Security 开始判断本次会话是否有权限时的前一瞬间
         * 通过添加过滤器将 token 解析,将用户所有的权限写入本次 Spring Security 的会话
         */
        http.addFilterBefore(new JwtAuthenticationFilterListener(this.komsProperties),
                UsernamePasswordAuthenticationFilter.class);
        //禁用缓存
        http.headers().cacheControl();

    }

添加白名单

private static String[] WHITE_LIST;
.antMatchers(WHITE_LIST).permitAll()
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题