【问题标题】:Redirect to https in Quarkus在 Quarkus 中重定向到 https
【发布时间】:2020-03-24 04:00:59
【问题描述】:

在 Quarkus 中从 HTTP 重定向到 HTTPS 的最简单方法是什么?

我搜索了配置文档https://quarkus.io/guides/all-config,但找不到任何东西。

我尝试添加 undertow 依赖项和 web.xml 以强制建立 https 连接。我添加的 web.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <security-constraint> <web-resource-collection> <web-resource-name>All</web-resource-name> <url-pattern>*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> </web-app>

【问题讨论】:

  • 到目前为止你有什么尝试?
  • 我尝试添加 undertow 依赖项和 web.xml 以强制建立 https 连接。我还尝试查找http.disablehttps.only 等配置参数。
  • 这最好由您的应用服务器完成,而不是您的代码。

标签: java jakarta-ee quarkus


【解决方案1】:

首先如何创建证书并给 quarkus。您可以在此answer 中查看详细信息。

The problemmvn quarkus:dev 不适用于 SSL。我得到了Caused by: java.nio.file.NoSuchFileException: .\keystore.jks,但好消息是正常的 java -jar 运行正常。

Here 是您正在寻找的更准确的配置quarkus.http.insecure-requests=redirect 如果不提​​供证书,它将无法工作。你可以看到我是如何创建证书here

截屏以显示它在 Firefox 中的工作原理,请查看底部的开发控制台。

最后但并非最不重要的是这是一个运行示例https://github.com/ozkanpakdil/quarkus-examples/tree/master/local-ssl-usage

【讨论】:

    猜你喜欢
    • 2019-03-12
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多