Redirect HTTP to HTTPS in Undertow

谁都会走 提交于 2019-12-01 13:05:41
siphiuel

This answer pointed in the right direction. Programmatically, one has to add a SecurityConstraint to Builder and set ConfidentialPortManager:

DeploymentInfo servletBuilder = Servlets.deployment();
servletBuilder.addSecurityConstraint(new SecurityConstraint()
  .addWebResourceCollection(new WebResourceCollection()
    .addUrlPattern("/*"))
  .setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
  .setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT))
  .setConfidentialPortManager(new ConfidentialPortManager() {
    @Override
    public int getConfidentialPort(HttpServerExchange exchange) {
      return 443;
    }
  }
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!