1. 程式人生 > 其它 >springSecurity+vue前後分離放行所有請求

springSecurity+vue前後分離放行所有請求

技術標籤:許可權框架springbootspring bootvue

問題:vue前端請求SpringSecuriry許可權框架資源返回403沒有許可權

解決:springSecurity配置類配置所有的資源都可以放行。

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      // auth.inMemoryAuthentication().withUser("admin").password("123456").authorities("PRODUCT_ADD");
    }

    /**
     * 自定義配置
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/**").permitAll()// 所有請求都可以訪問
        .and().csrf().disable() // 跨域請求關閉
        .headers().frameOptions().disable(); // 資源下載許可權關閉
    }

}

發現只能訪問最開始的請求,需要把跨站檢查關閉。發現可以請求了。