I have a situation where i need to redirect requests from a non SSL
port to an SSL
port. I came up with the following code but it doesn't seem to redirect.
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);
}
Seems like i had to add a security constraint to the context to redirect from a non-SSL port to a SSL port