gpt4 book ai didi

java - Quarkus HTTPS Restful 服务

转载 作者:行者123 更新时间:2023-12-02 16:52:13 26 4
gpt4 key购买 nike

是否有使用 quarkus.io 构建和配置 TLS 安全的 Restful 服务的示例/教程?

不幸的是,我在 quarkus 文档中都找不到,这里也没有。

最佳答案

谢谢先生。纪尧姆·斯梅特,我找到了解决方案。这里是《Quarkus 和 SSL 5 分钟从零到你好指南》。这是由 quarkus undertow 插件完成的。此外,您还需要安装文本编辑器、jdk 1.8+ 和 maven。

首先,创建项目。

mkdir restls
cd restls
mvn io.quarkus:quarkus-maven-plugin:create -DprojectGroupId=org.acme -DprojectArtifactId=restls -DclassName="org.acme.HelloResource" -Dpath="/hello" -Dextensions="undertow"

使用任何编辑器打开应用程序配置文件src/main/resources/application.properties并添加行:

quarkus.http.port=80
quarkus.http.ssl-port=443
quarkus.http.ssl.certificate.key-store-file=keystore.jks

创建包含自签名证书的 keystore (回答所有问题并指定密码,即“password”):

keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 365 -keysize 2048

文件 keystore.jks 必须位于 src/main/resources/ 文件夹中。

构建项目:

mvnw clean package quarkus:build

现在尝试一下:

java -jar target/restls-1.0-SNAPSHOT-runner.jar

导航到 https://localhost/hello 并允许您的浏览器信任证书。仅此而已。

您可以像这样覆盖调用时的选项:

java -Dquarkus.http.ssl.certificate.key-store-file=/path-to-keystore/keystore-name.jks -jar target/restls-1.0-SNAPSHOT-runner.jar

最后,这是相关的选项列表:

quarkus.http.ssl.certificate.file -- The file path to a server certificate or certificate chain in PEM format.

quarkus.http.ssl.certificate.key-file -- The file path to the corresponding certificate private key file in PEM format.

quarkus.http.ssl.certificate.key-store-file -- An optional key store which holds the certificate information instead of specifying separate files.

quarkus.http.ssl.certificate.key-store-file-type -- An optional parameter to specify type of the key store file. If not given, the type is automatically detected based on the file name.

您可以指定 PEM 格式的证书 + key 文件或 keystore 。

关于java - Quarkus HTTPS Restful 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55588382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com