日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring security导致登录后从https跳转至http解决方案

發布時間:2024/1/18 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring security导致登录后从https跳转至http解决方案 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 項目為spring boot項目,由原來的http連接更換為https連接,因項目中配置的了spring security,登錄被spring security攔截重定向后會跳轉到http

解決辦法:

nginx中增加

proxy_set_header ? X-Forwarded-Proto 'https';

yml文件中增加

server:use-forward-headers: truetomcat:remote-ip-header: x-forwarded-forprotocol-header: x-forwarded-proto

security代碼中增加以下

protected void configure(HttpSecurity http) throws Exception { http.requiresChannel().anyRequest().requiresSecure();

2.因項目內部使用fegin調用仍采用了http方式,即項目中https針對前端,http針對后端fegin需要做https通道排除

RequestMatcher requestMatcher = new NegatedRequestMatcher(new AntPathRequestMatcher("fegin接口調用")); http.requiresChannel().requestMatchers(requestMatcher).requiresSecure();

? 遇到的坑;requestMatchers不能傳入多個new NegatedRequestMatcher,需要使用 AndRequestMatcher進行合并才可以,如

RequestMatcher a = new NegatedRequestMatcher(new AntPathRequestMatcher("/a")); RequestMatcher b= new NegatedRequestMatcher(new AntPathRequestMatcher("b")); RequestMatcher c = new NegatedRequestMatcher(new AntPathRequestMatcher("/c")); AndRequestMatcher andRequestMatcher = new AndRequestMatcher(a,b,c); http.requiresChannel().requestMatchers(andRequestMatcher).requiresSecure();

?

總結

以上是生活随笔為你收集整理的spring security导致登录后从https跳转至http解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。