views:

52

answers:

1

Like many websites, I have a login popup on every webpage of my site. Most of these pages are http (non-secure). But the login mechanism has to post to a secure url. All this works great. The problem is the secure url changes in the various dev environments, staging and different production environments.

So not too big of a deal, I just have a properties file for each environment with the secure host and port. Now is there a way to encode the url with the right context and jsession id (if needed) and other things c:url normally does?

for example:

<form method="post" action="${rootHttpsUrl}/login">

I might think this would work to modify the url to add the right context, session info if needed, etc:

<form method="post" action="<c:url value='${rootHttpsUrl}/login'/>">

But that doesn't work because c:url sees https://some-url.com and thinks it's an external link. So I could just modify the url myself:

<form method="post"
action="<%=response.encodeURL(${rootHttpsUrl}${pageContext.request.contextPath}/login)%>">

But escaping to java code like that doesn't let java see the rootHttpsUrl jsp variable (how do I expose this to java?). Is there a way to call encodeURL from within JSP?

So what's the best solution here? I'm using Spring, Spring webmvc and Spring Security v3.0. Ideally there's something like

<c:url value='/login' secure='true'/>

UPDATE: The best I've come up with is to have a properties file for each environment with a property for the https host and port. Then I add that to the model and reference any secure URL like this:

https://${httpsHostAndPort}&lt;c:url value='/login'/>
A: 

Hard-encode it yourself.

action="${rootHttpsUrl}/login;jsessionid=${pageContext.session.id}"
BalusC
Yes, well we also need the context, but easy enough to add. However, I don't want the session id exposed unless necessary (cookies not enabled). I guess I'm at least looking for a standard way to add the session id only when necessary...
at
You can use under each [`HttpServletRequest#isRequestedSessionIdFromURL()`](http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html#isRequestedSessionIdFromURL%28%29) to determine whether the client is passing the session ID around by URL (and thus likely doesn't support cookies).
BalusC
That's the same problem with HttpServletRequest#encodeURL, which does all the work for us. How do I use it inside a JSP page? I can do a <%= %>, but then I can't access the JSP variable... or can I?
at
You can obtain `${rootHttpsUrl}` in scriptlet using `pageContext.findAttribute("rootHttpsUrl")`. I am although not a fan of scriptlets, but I don't see other ways. Spring guys may know cleaner ways with help of servlet or filter like preprocessing functionality.
BalusC
I updated the question with what I think is the best way to implement this
at