For my java webapp, I would like a log-in form to appear on each (JSP) page if the user is not yet logged. Pages could be secure (HTTPS) or not (HTTP).
The log-in form must POST on a secured (HTTPS) URL to prevent the username/password to be sent in clear text.
If the user is currently on the page http://localhost:8080/app/home, using jstl [c:url value=”/login”] to compute the log-in form URL will not change the scheme from HTTP to HTTPS
(although /login is marked as CONFIDENTIAL in my web.xml).
Instead, it will give an URL like http://localhost:8080/app/login which will send a redirect to https://localhost:8443/app/login when accessed.
So why is the container redirecting instead of rewriting the URL to use the correct scheme (+ port) in the first place?
I could hardcode the log-in form secured URL but that would be less portable.
Or maybe, there are some considerations about web security I’m not aware of…
When you use “/login” as the URL, the browser will interpret the URL as having the same hostname, port and scheme as the URL of the page containing the URL. If you want to use HTTPS, your server-side has to return HTML that uses URL with (at least) the “https:” scheme. This specified in the HTML spec.
However, you don’t necessarily have to hard-wire the hostname into the JSP. The JSP could pick up the hostname from configuration property, or figure it out from the current request URL.
AFAIK, no. (BTW, if there was Jetty or Tomcat specific way of doing this, it wouldn’t be standard …)
Good question.
As I understand it, the feature that automatically incoming requests to a secure URL is container specific, and needs to be configured at the container level. Specifically, the container (or something) needs to be told what incoming URLs need this treatment. The JSP engine would need similar information to do the same thing when creating URLs for outgoing messages. AFAIK, there is no such facility in Tomcat’s JSP configurations.
You’d need to ask someone on the JSR committee(s) that produced the Java EE specs for an answer as to why there is no standard way to do this.
That is true, but changing a configuration parameter in two places is a minor thing.
And like I said, if you have a beef with the various standards groups for not providing a standard solution for this … or with the Tomcat / Jetty implementors for not providing a non-standard solution … you should take this up with THEM.
FWIW, I use a custom “secureURL” tag to solve this problem, but my use-case is significantly more complicated. I’m implementing components that can be dropped into existing sites and that need to work when https is available or is not available, and when secure cookies are used or not used … for example.