我有一个春季启动应用程序,其中包含添加了formLogin的spring security和自定义loginPage。每当我通过身份验证,它就会将我发送到defaultSuccessUrl,即/ app / dashboard,它会发送模式 http 我整天都在尝试将successUrl架构设为https,只需调整一些更改在application.properties上,有时候还有Bean,但我仍然无法实现它。我的应用程序是在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();
我也曾尝试将绝对网址与<strong> https 一起使用,但效果不佳。
答案 0 :(得分:4)
您是否尝试过requiresChannel()
和requiresSecure()
?要通过https访问特定网址,您可以尝试
.defaultSuccessUrl("/app/dashboard").and().requiresChannel().antMatchers("/app/dashboard").requiresSecure()
对于通过https的所有请求,您可以使用
.and().requiresChannel().anyRequest().requiresSecure()
您可以使用如下所示的端口映射。
http
.portMapper()
.http(8080).mapsTo(443);