java - Spring Boot 登录重定向 302 丢失 HTTPS

标签 java spring-boot authentication https

在使用自定义登录页面尝试登录 SpringBoot 应用程序时,Web 应用程序会自动从 HTTPS 切换到 HTTP。我想同时允许,但如果 HTTPS 已经存在,它不应该自动切换出来。请在此处查看 Chrome 日志:

-- 一般

-- 响应 header :

我正在使用 WebSecurityConfigurerAdapter,我的配置(HttpSecurity http):

http.authorizeRequests().antMatchers("/version*").permitAll().anyRequest().authenticated()
.and().formLogin().loginPage("/login").permitAll().and().logout().permitAll();

我的/login 页面非常简单:

<form method="post" enctype="application/x-www-form-urlencoded">
     <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
     <input type="text" name="username">
     <input type="password" name="password">
     <input id="signInBtn" type="submit" value="Sign In">
</form>

有人知道如何修复配置吗?

最佳答案

我能够使用以下 spring 配置解决此问题:

security.require-ssl=true

尽管 Spring Boot 应用程序在端口 8080 上运行,它仍会强制使用 HTTPS。

关于java - Spring Boot 登录重定向 302 丢失 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48160992/

相关文章:

java - Spring boot 1.5.2.RELEASE 在静态方法中访问 application.yml 属性

java - 错误: Spring 启动数据库错误“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration”

将 EAP 与 PEAP 结合使用时,Android 身份验证会陷入僵局

javascript - 使用 PHP 根据用户名加载不同的 View

java - 将数组从 Java 返回到 Python

java - 启动 java 程序时出现 ArrayIndexOutOfBoundsException

java - Weka工具: how to convert txt files into arff format?

java - 多个 fragment 需要位置更新

spring - 容器化 Spring Boot 应用程序时 "-Djava.security.egd=file:/dev/./urandom"到底做了什么

python - Colaboratory - 记住 Google Drive Auth(Python)