How to enumerate HTTP listeners from a Java EE web application

I have a web application with a web config interface. If the user is accessing over HTTP, I want to warn the user that they really should be using HTTPS and give them a link to navigate to the HTTPS-prefixed URL.

Now it's pretty easy if we use the default ports, but often we are not - for example, HTTP might be at 8080, from HTTPS to 8181. I might have some heuristics to figure out which port to use, like 80-> 443 , 8080-> 8181, but is there a way to get the list of ports and protocols from the web container? Ideally a Java EE standard, but even container specific, would be the start ...

EDIT - one clarification - this is for a "out-of-the-box" application ( OpenSSO ), so I really like to be able (s) to give the user the option to go ahead and use an insecure port if they really want to (for example, they deploy on their laptop on some container without a secure port) and (b) don't make the user edit the server.xml.

0


source to share


3 answers


You can migrate them automatically to https with just config.

in your web.xml:

<user-data-constraint>
  <transport-guarantee>
    CONFIDENTIAL
  </transport-guarantee>
</user-data-constraint>

      



and in your server.xml in the HTTPConnector:

redirectPort="YOUR_SSL_PORT"

      

+1


source


If you have a load balancer, it can usually be configured to do this kind of automatic redirection.



0


source


If I read your question correctly, you can query the ServletRequest getProtocol to see if the connection is coming in as HTTP or HTTPS and what the version. You can get a port as a bonus.

Inject a solution and redirect (or forward) to the specified application port.

To further clarify the answer; Enabling HTTPS Communication Support

0


source







All Articles