spring security导致登录后从https跳转至http解决方案
生活随笔
收集整理的這篇文章主要介紹了
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-protosecurity代碼中增加以下
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解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机将取代老师吗 英语作文,英语四级作
- 下一篇: OkHttp的详细使用方法