av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

spring boot security設(shè)置忽略地址不生效的解決

瀏覽:2日期:2023-07-01 09:53:16
spring boot security設(shè)置忽略地址不生效

最近在試下微服務(wù)改造,出現(xiàn)這樣一個(gè)問題所有請(qǐng)求都經(jīng)過spring cloud gateway進(jìn)行認(rèn)證授權(quán)后再訪問后端數(shù)據(jù)方服務(wù),但有些需要合作機(jī)構(gòu)回調(diào),由于進(jìn)行了security認(rèn)證,最終的方案是對(duì)回調(diào)地址進(jìn)行忽略auth認(rèn)證。

最終security主要代碼如下:

@Configuration@EnableWebSecuritypublic class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers('/v1/prNotifyBack'); } @Override protected void configure(HttpSecurity http) throws Exception { /**表示所有的訪問都必須進(jìn)行認(rèn)證處理后才可以正常進(jìn)行*/ http.httpBasic().and().authorizeRequests().anyRequest().fullyAuthenticated(); /**所有的Rest服務(wù)一定要設(shè)置為無狀態(tài),以提升操作性能*/ http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); http.csrf().disable(); }}這個(gè)過程遇到了幾個(gè)問題:1、繼承WebSecurityConfigurerAdapter

后我們重寫configure方法,這個(gè)方法需要注意:他有兩個(gè)不同的參數(shù)。

HttpSecurity 及WebSecurity 作用是不一樣的,WebSecurity 主要針對(duì)的全局的忽略規(guī)則,HttpSecurity主要是權(quán)限控制規(guī)則。

所以一開始用HttpSecurity是達(dá)不到忽略地址的目的。

protected void configure(HttpSecurity http){.......} public void configure(WebSecurity web) {.........}

WebSecurity

全局請(qǐng)求忽略規(guī)則配置(比如說靜態(tài)文件,比如說注冊(cè)頁面)、全局HttpFirewall配置、是否debug配置、全局SecurityFilterChain配置、privilegeEvaluator、expressionHandler、securityInterceptor、

HttpSecurity

具體的權(quán)限控制規(guī)則配置。

2、忽略不生效問題

web.ignoring().antMatchers('/pr/v1/prNotifyBack');

如上代碼如果帶上/pr就不會(huì)生效,訪問依然會(huì)出現(xiàn)401錯(cuò)誤。/pr是配置的項(xiàng)目路徑。但帶上項(xiàng)目路徑就不生效,這個(gè)問題很疑惑。

server:port: 8089servlet:context-path: /prSpringBoot SpringSecurity, web.ignore失效

@Configuration@EnableGlobalMethodSecurity(prePostEnabled=true)public class CustomSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception {http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().csrf().disable().authorizeRequests().antMatchers('/api/**').authenticated().and().addFilterBefore(new TokenFilter(), UsernamePasswordAuthenticationFilter.class); } @Override public void configure(WebSecurity web) throws Exception {web.ignoring().antMatchers('/').antMatchers('/swagger-ui.html').antMatchers('/swagger-resources/**').antMatchers('/webjars/springfox-swagger-ui/**').antMatchers('/v2/api-docs/**'); }}這是修改后正常工作的配置文件

之前使用@component注解, 然后使用@Resource注入進(jìn)來.

導(dǎo)致過濾器全局生效.

正常配置,應(yīng)該手動(dòng)new, 而且過濾器類不能加@Component注解

具體原因,之后有空研究一下.

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 五月婷婷综合网 | 手机看片福利视频 | 日本一区二区高清 | 天天干天天做 | 久久精品导航 | 久草视| 成人在线国产 | 久久久久久艹 | 一区二区亚洲 | 久久久久国产一区二区三区 | 欧美日韩成人在线观看 | 精品伊人久久 | 三级视频在线观看 | 成年人视频网站 | 欧美在线观看一区二区 | 欧美黄色一级视频 | 免费的黄色小视频 | 大尺度做爰床戏呻吟舒畅 | 国产精品国产三级国产 | 日本国产欧美 | 日日操夜夜骑 | 国产精品久久久久久久久 | 欧美成人三级在线观看 | 五月婷婷综合网 | 青青伊人网 | va视频 | 日韩一二区| 乳色吐息在线观看 | 在线一区视频 | 青青在线视频 | 欧美黄色一区 | 97国产精品人人爽人人做 | 欧美在线网站 | 九久久 | 黄色免费网站 | 欧美成人毛片 | 国产三级免费观看 | 涩涩久久 | 国产一级一片免费播放放a 免费国产视频 | 日韩a在线| 国产精品一区一区三区 |