spring-boot - Spring Boot Security - 从 http 8080 重定向到 https 433 不能正常工作
问题描述
我需要帮助。我用spring security创建了一个简单的项目。但是从 8080 重定向到 433 并没有达到我的预期。
@Bean
public ServletWebServerFactory servletContainer() {
// Enable SSL Traffic
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
// Add HTTP to HTTPS redirect
tomcat.addAdditionalTomcatConnectors(httpToHttpsRedirectConnector());
return tomcat;
}
private Connector httpToHttpsRedirectConnector() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(443);
return connector;
}
从 localhoste:8080/ 自动重定向后,url 如下所示: https://localhost
服务器没有响应。我必须像这样手动将端口号添加到 url: https://localhost:443/
我的应用程序属性:
server.port=433
server.ssl.enabled=true
server.ssl.key-store=src/main/resources/ssl_security.p12
server.ssl.key-store-password=secret
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=ssl_security
我做错事情了?或者这可能是我的一些网络浏览器配置?
以下链接到github:
解决方案
推荐阅读
- keras - keras中二元分类的类不平衡
- ios - 将新单元格插入表格视图时,在所有可见单元格上调用什么?
- c# - 尝试根据表行的最高 ID 更新特定 SQL Server 表列时出错
- python - 在python中使用liblas和laspy读取las文件的问题
- html - Z-index 没有堆叠
- python - 如何在没有导入库的情况下在 python 文件中获取函数定义?
- java - 从android studio中的按钮单击访问url
- javascript - 如何使用 ArrayBuffer/ArrayBufferView 通过 WebSocket 发送字符串和整数的 Javascript 数组?
- android - 更改 TextInputLayout 提示字体
- regex - 使用正则表达式查找包含在特殊字符中的字符串