簡體   English   中英

spring security 登錄成功期間強制Https連接

[英]Forcing Https connection during the spring security login success

我有一個 spring boot 應用程序,其中包含 spring security,添加了 formLogin 和自定義 loginPage 。 每當我通過身份驗證時,它都會將我發送到 /app/dashboard 的 defaultSuccessUrl 並發送模式http我一整天都在嘗試將 successUrl 模式設置為 https 只是調整 application.properties 上的一些更改,有時使用Bean,但我仍然無法實現它。 我的應用程序在 cloudfoundry 中,我沒有 80 端口,但只有 443(https) 。

我在spring的配置是這樣的:

http
    .authorizeRequests()
    .antMatchers("/", "/forbidden", "/index.html", "/webjars/*", "/app.js", "/access/*", "/signup", "/l10n/*.js", "/", "/tpl/**/*.html", "/fonts/**/*.woff").permitAll()
    .anyRequest().authenticated()

    .and().addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class).
    csrf().csrfTokenRepository(repo)

    .and() .httpBasic().disable()
    .formLogin()
    .loginPage("/access/signin").permitAll()
    .failureUrl("/error")
    .defaultSuccessUrl("/app/dashboard")
    .and().logout()
    .logoutRequestMatcher(new AntPathRequestMatcher("access/logout"))
    .logoutSuccessUrl("/access/signin").permitAll();

我也嘗試過將絕對 url 與https一起使用,但效果不佳。

您是否嘗試過requiresChannel()requiresSecure() 對於可以通過 https 訪問的特定 url,您可以嘗試

.defaultSuccessUrl("/app/dashboard").and().requiresChannel().antMatchers("/app/dashboard").requiresSecure() 

對於通過 https 的所有請求,您可以使用 like

.and().requiresChannel().anyRequest().requiresSecure()

您可以使用如下所示的端口映射。

 http
     .portMapper()              
        .http(8080).mapsTo(443);

請參閱thisthis了解更多詳情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM