以编程方式为 Jetty 9 嵌入式配置 SSL

2024-02-18

我正在使用 jetty 版本 9.0.0.M4 并尝试将其配置为接受 SSL 连接。 按照以下说明进行操作:http://www.eclipse.org/jetty/documentation/current/configuring-connectors.html http://www.eclipse.org/jetty/documentation/current/configuring-connectors.html

我设法写了一些有用的东西。 然而,我写的代码看起来很丑陋而且不必要的复杂。 知道如何正确执行此操作吗?

final Server server = new Server(Config.Server.PORT);

SslContextFactory contextFactory = new SslContextFactory();
contextFactory.setKeyStorePath(Config.Location.KEYSTORE_LOCATION);
contextFactory.setKeyStorePassword("******");
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(contextFactory, org.eclipse.jetty.http.HttpVersion.HTTP_1_1.toString());

HttpConfiguration config = new HttpConfiguration();
config.setSecureScheme("https");
config.setSecurePort(Config.Server.SSL_PORT);
config.setOutputBufferSize(32786);
config.setRequestHeaderSize(8192);
config.setResponseHeaderSize(8192);
HttpConfiguration sslConfiguration = new HttpConfiguration(config);
sslConfiguration.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(sslConfiguration);

ServerConnector connector = new ServerConnector(server, sslConnectionFactory, httpConnectionFactory);
connector.setPort(Config.Server.SSL_PORT);
server.addConnector(connector);

server.start();
server.join();

The ServerConnector http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/ServerConnector.html应该设置一个SslContextFactory http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/util/ssl/SslContextFactory.html.

您正在做的其余工作Http配置 http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/HttpConfiguration.html与设置 SSL 无关。

在嵌入模式下设置 SSL 的一个很好的示例位于嵌入式码头示例 http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/src/main/java/org/eclipse/jetty/embedded/项目。http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java

编辑:更清楚(感谢埃里克)

更新日期:2016 年 6 月

Eclipse Jetty 项目已将其规范存储库移至 github。

以上LikeJettyXml.java现在可以在以下位置找到

https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

以编程方式为 Jetty 9 嵌入式配置 SSL 的相关文章

  • Jetty 提供静态内容所需的最少文件集?

    背景 免责声明 I have veryJava 经验很少 我们之前在 Ant 构建期间使用了 Jetty 6 的包装版本来处理按需静态内容 JS CSS 图像 HTML 因此我们可以使用 PhantomJS 针对 HTTP 托管环境运行单元
  • 由于握手问题,PerL SSL 连接尝试失败

    我希望有人可以提供帮助 我正在使用 nagios 插件 check ilo2 health 该插件在我们的 OpenSuSE 系统上运行良好 但新的 Ubuntu 14 04 系统有问题 删除 nagios 的东西并运行 perl 基本上是
  • 如何将证书从 PEM 转换为 JKS?

    我必须将 PEM 格式的证书转换为 Java 密钥存储 在 Windows 服务器上将其与 tomcat 一起使用 我有这些文件 cert request csr BEGIN CERTIFICATE REQUEST END CERTIFIC
  • gRPC + SSL = 未满足的链接错误

    我一直在尝试对我的 gRPC 服务进行 SSL 化 在纯文本模式下工作正常 注意 这是在商业环境中 这限制了我的一些选择 例如开发环境和部署平台 我跟着安全 md https github com grpc grpc java blob m
  • nginx 的“ssl”指令已弃用,请使用“listen ... ssl”

    NGINX 升级后v1 15 2开始收到警告 nginx warn the ssl directive is deprecated use the listen ssl directive instead in usr local etc
  • 无法删除 Google 管理的 SSL 证书

    我无法删除 Google 管理的 SSL 证书 当我删除它时 它又会回来 该证书不被任何其他服务使用 我可以删除其他证书 但它们不会再回来 我也有这个问题 我在文档中发现只有在以下情况下才能删除证书 仅当没有其他资源 例如目标 HTTPS
  • 添加自签名证书而不提示用户是/否

    使用一些批处理文件 我想在 Java 密钥库中添加不受信任的自签名证书 命令是 JAVA HOME bin keytool import v trustcacerts alias server alias file server cer k
  • java安全套接字无需身份验证?

    我有一个简单的安全套接字服务器 客户端程序 对于服务器证书 我使用 keytool 创建了一个密钥库 当我尝试通过客户端连接到服务器时 出现以下异常 在服务器中 Exception in thread main javax net ssl
  • .htaccess HTTPS 主域和通配符 HTTP 子域 + 所有非 WWW

    Stack Overflow 上有很多类似的解决方案 例如htaccess http 到 https 带 www 不重定向子域 https stackoverflow com questions 30242495 htaccess http
  • 我们可以向 ServicePointManager.SecurityProtocol 添加四个协议吗?

    我想支持从 ssl3 到 tls 1 2 的所有安全协议 但是在网上搜索时我发现代码为 ServicePointManager SecurityProtocol SecurityProtocolType Ssl3 SecurityProto
  • 签署 apple-app-site-association

    我尝试实施iOS9 Universal Links 我正在使用这个教程 http blog hokolinks com how to implement apple universal links on ios 9 http blog ho
  • Python 使用 ssl.getpeercert() 从 URL 获取通用名称

    我正在尝试获取证书颁发者信息 通用名称 但链接中的代码不适用于某些 URL 如何在 python 中获取证书颁发者信息 https stackoverflow com questions 30862099 how can i get cer
  • SBT、Jetty 和 Servlet 3.0

    我有一个非常小的问题 我有以下 build sbt 文件 name Tueet libraryDependencies org eclipse jetty jetty webapp 8 1 2 v20120308 调用 sbt update
  • 如何通过 jnlp 为 jetty 提供许多 Web 应用程序?

    我有一个网络应用程序 http sourceforge net projects sf mvn plugins files m2 repo net sf maven plugins example captaincasa jnlp 0 1
  • 使用 VirtualDocumentRoot 的 SSL 虚拟主机

    我在 ubuntu 16 04 VM 上进行开发工作 当我处理多个项目时 为了让我的生活更轻松 我使用 VirtualDocumentRoot 和主机文件使用 dev 域从我的主文件夹中服务器站点 在 000 default conf 我有
  • 将 http 和 https 请求重定向到新主机

    在 Apache 2 4 6 中 我想重定向来自http A org foo and https A org foo to https B org foo 我正在使用以下指令
  • 在 Tomcat 8 上配置 SSL 并连接超时

    我设置了一个密钥库并从 openssl com 获得了 SSL 证书 我遵循的具体步骤在这里 https drive google com file d 0B6PUGo7cBLcDTzdkc0pzT2pTMk0 view usp shari
  • 使用 openssl 检查服务器安全协议

    我有一个框架应用程序 它根据使用方式连接到不同的服务器 对于 https 连接 使用 openssl 我的问题是 我需要知道我连接的服务器是否使用 SSL 还是 TLS 以便我可以创建正确的 SSL 上下文 目前 如果我使用错误的上下文尝试
  • 从 WildFly 安全地调用 EJB

    我正在尝试以企业 业务 方式重写我的旧应用程序 因此 我有一个带有登录模块的 Swing 客户端和从头开始创建的我自己的服务器 客户端使用ssl证书加密与服务器的TCP连接 我检查服务器上的客户端证书和客户端上的服务器证书 然后服务器使用数
  • 使用 luasocket smtp 和 ssl 发送电子邮件

    我一直在尝试使用帖子中描述的代码发送电子邮件 lua使用gmail账户发送邮件 https stackoverflow com questions 11070623 lua send mail with gmail account 代码由米

随机推荐