Spring Security跳轉(zhuǎn)頁(yè)面失敗問題解決
這篇文章主要介紹了Spring Security跳轉(zhuǎn)頁(yè)面失敗問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
今天新建SpringBoot項(xiàng)目練手,第一次添加了Spring Security.成功啟動(dòng)項(xiàng)目后發(fā)現(xiàn)與之前新建的項(xiàng)目有點(diǎn)不一樣,無(wú)論我怎么設(shè)置系統(tǒng)首頁(yè),瀏覽器內(nèi)打開的都是登陸界面,如圖:
無(wú)論我怎么設(shè)置controller的跳轉(zhuǎn)路徑都不起作用,氣到撓頭!??!
經(jīng)過查閱各種資料發(fā)現(xiàn)可能是Spring Security權(quán)限控制的原因,于是著手配置控制權(quán)限。
新建SecurityConfig類進(jìn)行權(quán)限配置,代碼如下:
import org.springframework.context.annotation.Bean; 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; import org.springframework.security.crypto.password.NoOpPasswordEncoder; @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { //配置資源文件,其中/css/**、index可以任意訪問 http .authorizeRequests() .antMatchers("/css/**", "/index").permitAll(); } }
一些解釋:
- authorizeRequests: 配置一些資源或者鏈接的權(quán)限認(rèn)證
- antMatchers:配置哪些資源或鏈接需要被認(rèn)證
- permitAll:設(shè)置完全允許訪問的資源或者鏈接
添加上述權(quán)限設(shè)置后index頁(yè)面可以正常訪問
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
@Transactional注解:多個(gè)事務(wù)嵌套時(shí),獨(dú)立事務(wù)處理方式
這篇文章主要介紹了@Transactional注解:多個(gè)事務(wù)嵌套時(shí),獨(dú)立事務(wù)處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01java高并發(fā)下解決AtomicLong性能瓶頸方案LongAdder
這篇文章主要為大家介紹了java高并發(fā)下解決AtomicLong性能瓶頸方案LongAdder,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12

Java語(yǔ)言實(shí)現(xiàn)對(duì)MySql數(shù)據(jù)庫(kù)中數(shù)據(jù)的增刪改查操作的代碼

使用idea+gradle編譯spring5.x.x源碼分析