title: http to https redirect (tomcat/jboss)
body: <p>We want to redirect all traffic that comes to the http url of our application to https, in order to do that we set the following values in the web.xml in the deploy/jboss-web.deployer/conf directory.</p>
  
  <pre><code>&lt;security-constraint&gt;
      &lt;web-resource-collection&gt;
          &lt;web-resource-name&gt;securedapp&lt;/web-resource-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/web-resource-collection&gt;
      &lt;user-data-constraint&gt;
          &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
      &lt;/user-data-constraint&gt;
  &lt;/security-constraint&gt;  
  </code></pre>
  
  <p>This does successfully redirect the user to the https location HOWEVER they use a different port as to what was configured in the server.xml in the deploy/jboss-web.deployer path</p>
  
  <pre><code>&lt;Connector port="8381" address="${jboss.bind.address}"    
           maxThreads="350" maxHttpHeaderSize="8192"
           emptySessionPath="true" protocol="HTTP/1.1"
           enableLookups="false" redirectPort="8543" acceptCount="100"
           connectionTimeout="20000" disableUploadTimeout="true" compression="on" /&gt;
  
      &lt;!-- Define a SSL HTTP/1.1 Connector on port 8643
           This connector uses the JSSE configuration, when using APR, the 
           connector should be using the OpenSSL style configuration
           described in the APR documentation --&gt;
      &lt;!----&gt;
      &lt;Connector port="8543" protocol="HTTP/1.1" SSLEnabled="true"
              maxThreads="150" scheme="https" secure="true"
              clientAuth="false" sslProtocol="TLS"
              keystoreFile="${jboss.server.home.dir}/conf/localhost.keystore"
          keystorePass="changeit"
      /&gt;    
  
      &lt;!-- Define an AJP 1.3 Connector on port 8009 --&gt;
      &lt;Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
           emptySessionPath="true" enableLookups="false" redirectPort="8543" /&gt;
  
        &lt;Engine name="jboss.web" defaultHost="localhost" jvmRoute="data1"&gt;
  </code></pre>
  
  <p>We had the https port set to 8543 which did then work however the https port that did redirect the user to when the user went to the http url was 8744 (when we set 8744 in the server.xml it worked successfully), however we could not find where the 8744 port was taken, does anyone know how to configure which port the first mentioned code placed in the web.xml redirects to</p>
  
  <p>Another query is that when we put this configuration in to production the https port will be "443", we need to know where to set 443 for the "security-constraint" entry to redirect to. Accessing <a href="http://www.data.com" rel="nofollow">http://www.data.com</a> will have to redirect to <a href="https://www.data.com" rel="nofollow">https://www.data.com</a> then</p>
  
  <p>Regards,
  Milinda</p>