2

我有一个 spring boot 应用程序,其中包含 spring 安全性,其中添加了 formLogin 和自定义 loginPage 。每当我通过身份验证时,它都会将我发送到 defaultSuccessUrl,即 /app/dashboard,它会发送我一整天都在尝试的架构http ,以使 successUrl 架构成为 https,只是调整 application.properties 上的一些更改,有时使用豆,但我仍然无法实现它。我的应用程序在 cloudfoundry 中,我没有 80 端口,但只有 443(https) 。

我在春天的配置是这样的:

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一起使用,但效果不佳。

4

1 回答 1

9

你试过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);

请参阅以获取更多详细信息。

于 2016-12-13T10:17:00.727 回答