色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

spring boot security設置忽略地址不生效的解決

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

最近在試下微服務改造,出現這樣一個問題所有請求都經過spring cloud gateway進行認證授權后再訪問后端數據方服務,但有些需要合作機構回調,由于進行了security認證,最終的方案是對回調地址進行忽略auth認證。

最終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 { /**表示所有的訪問都必須進行認證處理后才可以正常進行*/ http.httpBasic().and().authorizeRequests().anyRequest().fullyAuthenticated(); /**所有的Rest服務一定要設置為無狀態,以提升操作性能*/ http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); http.csrf().disable(); }}這個過程遇到了幾個問題:1、繼承WebSecurityConfigurerAdapter

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

HttpSecurity 及WebSecurity 作用是不一樣的,WebSecurity 主要針對的全局的忽略規則,HttpSecurity主要是權限控制規則。

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

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

WebSecurity

全局請求忽略規則配置(比如說靜態文件,比如說注冊頁面)、全局HttpFirewall配置、是否debug配置、全局SecurityFilterChain配置、privilegeEvaluator、expressionHandler、securityInterceptor、

HttpSecurity

具體的權限控制規則配置。

2、忽略不生效問題

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

如上代碼如果帶上/pr就不會生效,訪問依然會出現401錯誤。/pr是配置的項目路徑。但帶上項目路徑就不生效,這個問題很疑惑。

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注入進來.

導致過濾器全局生效.

正常配置,應該手動new, 而且過濾器類不能加@Component注解

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

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 久久免费播放视频 | 欧美一线高本道高清在线 | 久久精品香蕉视频 | 国产一区二区三区免费视频 | 成人国产精品 | 精品毛片免费看 | 欧美xxxx性xxxxx高清视频 | 一级成人毛片免费观看 | 亚洲天堂免费观看 | 一本色道久久综合亚洲精品高清 | 亚洲欧美日韩国产综合高清 | 久久成人毛片 | 国产在线视频h | 点击进入不卡毛片免费观看 | 韩国日本一级毛片免费视频 | 国产欧美日韩图片一区二区 | 台湾三级香港三级在线中文 | 欧美视频一区在线观看 | 国产精品亚洲精品久久成人 | 欧美精品毛片 | www.av在线.com| 色午夜在线 | 黄色美女免费网站 | xxxxaaa欧美另类 | 免费国产午夜高清在线视频 | 深夜福利成人 | 国产黄色在线播放 | 美国毛片一级视频在线aa | 亚洲欧美成人影院 | 一级片视频在线 | 亚洲日韩精品欧美一区二区 | 草草视频免费在线观看 | 日韩在线成人 | 国产一级在线观看 | 人人爽人人香蕉 | 丝袜足液精子免费视频 | 久久国产免费一区二区三区 | 亚洲成人欧美 | 在线欧美色| 久久精品在线 | 国产精品自拍一区 |