端口未在嵌入式tomcat

时间:2016-02-21 17:46:44

标签: java tomcat ssl embedded-tomcat-8 security-constraint

我遇到需要将请求从非SSL端口重定向到SSL端口的情况。我提出了以下代码,但它似乎没有重定向。

baseConnector = tomcat.getConnector();
    if (sslEnabled) {
        sslConnector = new Connector();
        sslConnector.setAttribute("keyAlias", "tomcat");
        sslConnector.setAttribute("keystorePass", "mypassword");
        sslConnector.setAttribute("keystoreFile", "pathtofile");
        sslConnector.setAttribute("clientAuth", "false");
        sslConnector.setAttribute("sslProtocol", "TLS");
        sslConnector.setAttribute("SSLEnabled", true);
        sslConnector.setProtocol("org.apache.coyote.http11.Http11NioProtocol");
        sslConnector.setSecure(true);
        sslConnector.setScheme("https");
        sslConnector.setPort(8443);
        tomcat.getService().addConnector(sslConnector);
        baseConnector.setRedirectPort(8443);
    }

1 个答案:

答案 0 :(得分:1)

似乎我必须向上下文添加安全约束以从非SSL端口重定向到SSL端口