springboot+spring security給web應用增加權限驗證的若干難題

1. Refused to execute script from '....js' because its MIME type ('text/html') is not executable...

引用博客:https://blog.csdn.net/c4jem/article/details/77131422

該問題是因爲加了權限驗證導致默認不需要權限驗證的靜態文件例如css js等也被攔截導致http 302了,解決辦法,在安全配置類的方法中增加過濾:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        // http.authorizeRequests()每個匹配器按照它們被聲明的順序被考慮。
        http
            .authorizeRequests()
                // 所有用戶均可訪問的資源
                .antMatchers("/css/**", "/js/**","/images/**", "/webjars/**", "**/favicon.ico", "/index").permitAll()
                // ROLE_USER的權限才能訪問的資源
                .antMatchers("/user/**").hasRole("USER")
                // 任何尚未匹配的URL只需要驗證用戶即可訪問
                .anyRequest().authenticated()
                .and()
            .formLogin()
                // 指定登錄頁面,授予所有用戶訪問登錄頁面
                .loginPage("/login
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章