disappearing post parameters

Thu, May 18, 2006

There was an issue with the Guanxi Guard where it was losing POST parameters, i.e.if you submitted a form who’s action was protected by a Guard, the form fields would never reach the protected application.

The reason was that the Pod was storing a reference to the original Map containing the request parameters. According to the servlet spec, the servlet container is free to do what it wants when the request is finished, so those references aren’t guaranteed to point to anything useful once the request has completed.

Simply storing the reference in the Pod wasn’t enough. When the GuardRequest was created after the SAML workflow was finished, the original parameters in the Pod were gone.

The solution was to force a copy and not reference in the Pod. Storing the parameters as a completely new HashMap using HashMap.putAll(Map) to copy the params into the Pod.

HashMap requestParameters = new HashMap(); requestParameters.putAll(request.getParameterMap);

That was ok but then it left me needing to implement the parameter methods of HttpServletRequestWrapper, one of which returns an Enumeration. What a drag. In the end it was easy enough using an iterator over the key Set of the HashMap.

public Enumeration getParameterNames() { return new Enumeration() { Iterator names = requestPod.getRequestParameters().keySet().iterator(); public boolean hasMoreElements() { return names.hasNext(); } public Object nextElement() { return names.next(); } }; }

An interesting side effect of implementing HttpServletRequestWrapper.getParameter() was discovering that the servlet container stores each parameter as a String[], even if it only has one value. So, doing this:


to get the value of a parameter from the original set, returns a String[].

So that’s that wee problem sorted. Must get on and finish the Guard registration module as it’s experimental at the moment.

comments powered by Disqus